- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 d3 焦点/上下文图表,我希望能够在刷亮上下文后平移焦点部分,并且我希望上下文区域的刷过部分与焦点的平移同步移动区域。但是,当我在上下文图表中选择一个区域后单击焦点部分时,焦点比例发生变化,并且点不再显示在正确的坐标处。以下代码可在 jsfiddle 上找到还有:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> - jsFiddle demo</title>
<script type="text/javascript" src="http://d3js.org/d3.v3.min.js"></script>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<style type="text/css">
circle {
-webkit-transition: fill-opacity 250ms linear;
}
.selecting circle {
fill-opacity: .5;
}
.selecting circle.selected {
stroke: #f00;
}
.brush .extent {
stroke: #B8C6D0;
fill-opacity: .125;
shape-rendering: crispEdges;
}
#context .axis path.domain {
stroke: lightsteelblue;
stroke-width: 5px;
}
#context .tick {
stroke:black;
stroke-width: 1px;
}
#context .x .tick {
stroke:black;
stroke-width: 2px;
}
.axis path, .axis line {
fill: none;
stroke: #ddd;
stroke-width: 1px;
shape-rendering: crispEdges;
}
.axis path {
stroke: #999;
stroke-width: 2px;
}
</style>
<script type="text/javascript">//<![CDATA[
var data = [{
Id: "1",
Year: 1950,
Relevance: 55,
Category: "Cat1",
SpecFreq: 5,
GenFreq: 10
}, {
Id: "2",
Year: 1975,
Relevance: 25,
Category: "Cat1",
SpecFreq: 2,
GenFreq: 31
}, {
Id: "3",
Year: 1990,
Relevance: 75,
Category: "Cat1",
SpecFreq: 8,
GenFreq: 23
}, {
Id: "4",
Year: 1970,
Relevance: 45,
Category: "Cat1",
SpecFreq: 17,
GenFreq: 60
}, {
Id: "5",
Year: 1985,
Relevance: 90,
Category: "Cat1",
SpecFreq: 17,
GenFreq: 25
}];
$(function () {
//dimensions
var margin = {
top: 5.5,
right: 19.5,
bottom: 39.5,
left: 39.5
};
//data domain extents
var extentX = d3.extent(data, function (d) {
return d.Year;
});
var extentY = d3.extent(data, function (d) {
return d.Relevance;
});
var focusAxisOptions = {
x: {
ticks: {
format: d3.format("d"),
size: -1* (500 - margin.top - margin.bottom),
ticks: 10
},
showLabel: true
},
y: {
ticks: {
format: d3.format(""),
size: -1 * (800 - margin.left - margin.right),
ticks: 10
},
showLabel: true
}
};
var contextAxisOptions = {
x: {
ticks: {
format: d3.format("d"),
size: -1 * (100 - margin.top - margin.bottom),
ticks: 10
},
showLabel: true
},
y: {
ticks: {
format: "",
size: 0,
ticks: 0
},
showLabel: false
}
};
var focus = DrawChart(data, margin, 800 - margin.left - margin.right, 500 - margin.top - margin.bottom, extentX, extentY, focusAxisOptions);
var context = DrawChart(data, margin, 800 - margin.left - margin.right, 100 - margin.top - margin.bottom, extentX, extentY, contextAxisOptions);
MakeContextBrushable(context, focus);
MakeFocusZoomable(focus);
});
function DrawChart(data, margin, width, height, extentX, extentY, axisOptions) {
//pad extents to provide some extra "blank" areas around edge of graph
var paddedExtentX = [extentX[0] - 5, extentX[1] +5];
var paddedExtentY = [extentY[0] - 5, extentY[1] +5];
//scales
var x = d3.scale.linear().domain(paddedExtentX).range([0, width]);
var y = d3.scale.linear().domain(paddedExtentY).range([height, 0]);
var radiusMax = .025 * width;
var radius = d3.scale.sqrt().domain([0, 100]).range([0, radiusMax]);
var color = d3.scale.ordinal().domain(["Cat1", "Cat2", "Cat3"]).range(["#b7b8a0", "#898a72", "#878772"]);
//axes
var xAxis = d3.svg.axis().scale(x).orient("bottom").tickFormat(axisOptions.x.ticks.format).tickSize(axisOptions.x.ticks.size).ticks(axisOptions.x.ticks.ticks);
var yAxis = d3.svg.axis().scale(y).orient("left").tickFormat(axisOptions.y.ticks.format).tickSize(axisOptions.y.ticks.size).ticks(axisOptions.y.ticks.ticks);
//create and size svg element
var svg = d3.select("#chart").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.style("float", "left")
.style("clear", "left");
var g = svg
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")"); ;
// Add the x-axis.
g.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis)
.selectAll("text")
.style("font-size", "10px")
.attr("dy", "1.5em");
// Add the y-axis.
g.append("g")
.attr("class", "y axis")
.call(yAxis)
.selectAll("text")
.style("font-size", "10px")
.attr("dx", "-1em");
// Add the x-axis label.
if (axisOptions.x.showLabel) {
g.append("text")
.attr("class", "x label")
.attr("text-anchor", "end")
.attr("x", width / 2)
.attr("y", height + 35)
.text(" Year");
}
// Add the y-axis label.
if (axisOptions.y.showLabel) {
g.append("text")
.attr("class", "y label")
.attr("text-anchor", "end")
.attr("x", -1 * height / 2)
.attr("y", -40)
.attr("dy", ".75em")
.attr("transform", "rotate(-90)")
.text("Relevance");
}
//plot genFreq
var gGenerally = g.append("g").selectAll("circle")
.data(data)
.enter().append("circle")
.style("fill", function (d) {
return color(d.Category);
})
.attr("cx", function (d) {
return x(d.Year);
})
.attr("cy", function (d) {
return y(d.Relevance);
})
.attr("r", function (d) {
return radius(d.GenFreq);
})
.append("title")
.text(function (d) {
return "(" + d.Year + ", " + d.Relevance + ", " + d.GenFreq + ", " + d.SpecFreq + ")";
});
//plot specFreq
var gWithin = g.append("g").selectAll("circle")
.data(data)
.enter().append("circle")
.style("fill", function (d) {
return "#d6d487";
})
.attr("cx", function (d) {
return x(d.Year);
})
.attr("cy", function (d) {
return y(d.Relevance);
})
.attr("r", function (d) {
return radius(d.SpecFreq);
})
.append("title")
.text(function (d) {
return "(" + d.Year + ", " + d.Relevance + ", " + d.GenFreq + ", " + d.SpecFreq + ")";
});
var chart = {
svg: svg,
g: g,
x: x,
y: y,
xAxis: xAxis,
yAxis: yAxis
}
return chart;
}
function MakeContextBrushable(context, focus) {
var brush = d3.svg.brush().x(context.x).y(context.y)
.on("brushstart", brushstart)
.on("brush", brushmove)
.on("brushend", brushend);
context.g.append("g")
.attr("class", "brush")
.call(brush);
function brushstart() {
context.svg.classed("selecting", true);
}
function brushmove() {
var e = d3.event.target.extent();
var circle = context.svg.selectAll("circle");
circle.classed("selected", function (d) {
return e[0][0] <= d["DecisionYear"] && d["DecisionYear"] <= e[1][0]
&& e[0][1] <= d["Relevance"] && d["Relevance"] <= e[1][1];
});
}
function brushend() {
context.svg.classed("selecting", !d3.event.target.empty());
if (!d3.event.target.empty()) {
var e = d3.event.target.extent();
focus.x.domain([e[0][0], e[1][0]]);
focus.y.domain([e[0][1], e[1][1]]);
focus.g.select(".x.axis").call(focus.xAxis)
.selectAll("text")
.style("font-size", "10px")
.attr("dx", "-1em");
focus.g.select(".y.axis").call(focus.yAxis)
.selectAll("text")
.style("font-size", "10px")
.attr("dx", "-1em");
var circle = focus.svg.selectAll("circle").attr("cx", function (d) { return focus.x(d.Year); })
.attr("cy", function (d) { return focus.y(d.Relevance); })
console.log("BrushEnd Domain: [" + focus.x.domain()[0] + ", " + focus.x.domain()[1] + "]");
}
else {
focus.x.domain(context.x.domain());
focus.y.domain(context.y.domain());
focus.g.select(".x.axis").call(focus.xAxis)
.selectAll("text")
.style("font-size", "10px")
.attr("dx", "-1em");
focus.g.select(".y.axis").call(focus.yAxis)
.selectAll("text")
.style("font-size", "10px")
.attr("dx", "-1em");
var circle = focus.g.selectAll("circle").attr("cx", function (d) { return focus.x(d.Year); })
.attr("cy", function (d) { return focus.y(d.Relevance); })
}
}
}
function MakeFocusZoomable(focus) {
focus.svg.call(d3.behavior.zoom().x(focus.x).y(focus.y).on("zoom", Zoom));
function Zoom() {
focus.svg.select(".x.axis").call(focus.xAxis).selectAll("text")
.style("font-size", "10px")
.attr("dy", "1.5em");
focus.svg.select(".y.axis").call(focus.yAxis).selectAll("text")
.style("font-size", "10px")
.attr("dx", "-1em");
focus.svg.selectAll("circle").attr("transform", "translate(" + d3.event.translate + ")" + " scale(" + d3.event.scale + ")");
}
}
</script>
</head>
<body>
<div id="chart">
</div>
</body>
</html>
最佳答案
要在平移后重置刷亮,您需要重置并再次调用 brush.extent:
//Find extent of zoomed area, for example the edges of graphed region
var brushExtent = [x.invert(0), x.invert(width)];
context.select(".brush").call(brush.extent(brushExtent));
以下是折线图上焦点/上下文刷平移同步的示例: http://jsfiddle.net/MtXvx/8/
希望对您有所帮助!
关于d3.js - D3 焦点/上下文图表 : synchronization of brushing and panning,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15818217/
我需要一些帮助。这都是关于选项卡索引的。我有一个使用 document.getElementById("name").focus(); 的 JavaScript,其中 id="name"的 textb
这是我的第一篇文章,如果您想了解更多信息,请告诉我! 我正在使用选择列表和 jQuery Accordion 。当用户从列表中选择一个值时,它会使用 activate 方法打开折叠面板的相关部分。 除
JQM 1.3.2/ASP.NET MVC 4 当选择一个值时,焦点没有正确设置到输入字段,我错过了什么? 周围的典型 jqm-shadow 没有从选择中移除,输入得到阴影效果,但光标没有设置到输入字
我正在为 Android 开发一个播放列表应用程序,它有一个包含歌曲名称 (TextView) 作为其列表项的 ListView。 随着歌曲的播放,我想突出显示 ListView 中的项目,直到歌曲结
我在这里不知所措,以前从来没有遇到过这个问题。 我无法让 focus() 在任何浏览器中工作。我正在使用 jquery,甚至不能让它与标准的 javascript 一起工作。我也尝试添加超时但仍然没有
登录后我有一个文本字段。登录后光标将自动聚焦在该文本字段上。如何验证该文本字段上是否存在光标/焦点? 文本框的HTML代码如下: 最佳答案 您也可以尝试直接的 webdriver 方法: drive
我有一个框架和一个面板。我永久删除面板并添加另一个面板。添加新面板后,我需要 JTextField 来获得焦点。我该怎么做? 我尝试了 panel.requestFocus() 方法,但没有成功。 示
这个问题在这里已经有了答案: 关闭 13 年前。 Possible Duplicate: Trouble with jquery lavalamp 出于某种原因,无论我点击哪个链接,我的背景颜色都会
在我的表单验证中,在提交时,我正在验证表单,并找到未填充的元素并使用此函数进行聚焦:工作正常 switch (tagName) { case 'TEXT': if (!actualVa
我最近构建了一个 JS/CSS 模态系统。该元素使用的是 Bootstrap 模式,但通过在其中放置无法滚动或无法正确聚焦在移动设备上的表单和大量内容,将其推向了极限。 可以触发模态系统here单击大
我正在建立一个网站,但我想将图片放在背景中,但我无法将其放在我想要的位置。 我希望网页上图像的“焦点”位于图像中心几像素处。宽度我都能看出来,但是高度没有。 图像分辨率为“5760x3840px”。
这个问题在这里已经有了答案: using :focus pseudo class on li or other element else than a,input,button, etc (2 个
每当我创建编辑器的另一个实例(在我的例子中,通过 onkeypress 事件),我就会失去对创建新编辑器时正在输入的编辑器的关注。我怎样才能防止所有编辑都失去对任何事件的关注? 最佳答案 为此,Qui
我试图将焦点放在一个字段上,更改文本的颜色,但无论我尝试什么:它都不起作用。以下是 HTML: .register-section input:focus + .register-section la
我已经为微调器选择的变化设置了一个监听器。在监听器中,我想关注一个 EditText 字段。我使用了以下代码: text_other_msg.setFocusable(true); 它不起作用。我还尝
我在表单屏幕上有几个 UITextField 输入,其中一些有一个数字键盘显示,通过自定义弹出窗口显示。当用户在字段中前进时,我们会根据需要关闭或打开弹出窗口。在 iOS 11 中,似乎“第一响应者”
我在 jQueryUI 中输入焦点时遇到问题。我在按钮上使用了 hover() 方法并且它正在工作,但是输入上的 focus() 不起作用。我不知道为什么。这是代码和 fiddle $(documen
有没有办法在自动对焦完成后随时获取对焦点? 在 Apple 的示例代码中,他们使用: - (void)subjectAreaDidChange:(NSNotification *)notifi
如果我的焦点不在 textField 上,如何移除 NSTextField 上的焦点? 我有一个 NSTextField,我设置了操作:编辑结束时发送。单击 textField 后,当我单击 View
如何通过 jQuery 实现这一点? 当用户单击表单中的任何输入时,它就会获得焦点。当用户从任何输入中单击表单外时,它会变得模糊,但是,在表单本身的输入之间进行 Tab 键切换之间不会触发模糊。 对于
我是一名优秀的程序员,十分优秀!