我有代碼滑塊:移動滑塊D3對象具體位置
var slider = d3.select('body').append('p').text('Title: ');
slider.append('label')
.attr('for', 'threshold')
.text('');
slider.append('input')
.attr('type', 'range')
.attr('min', d3.min(graph.links, function(d) {return d.value; }))
.attr('max', d3.max(graph.links, function(d) {return d.value; }))
.attr('value', d3.min(graph.links, function(d) {return d.value; }))
.attr('id', 'threshold')
.style('width', '50%')
.style('display', 'block')
.on('input', function() {
var threshold = this.value;
d3.select('label').text(threshold);
var newData = [];
graph.links.forEach(function (d) {
if (d.value >= threshold) {newData.push(d); };
});
color.domain([d3.min(newData, function(d) {return d.value; }), d3.max(newData, function(d) {return d.value; })]).interpolator(d3.interpolateBlues);
link = link.data(newData, function(d){ return d.value});
link.exit().remove();
var linkEnter = link.enter().append("path")
.style("stroke", function(d) { return color(d.value); })
.style("fill", "none")
.style("stroke-width", "3px");
link = linkEnter.merge(link).style("stroke", function(d) { return color(d.value); });
node = node.data(graph.nodes);
simulation.nodes(graph.nodes)
.on('tick', tick)
simulation.force("link")
.links(newData);
simulation.alphaTarget(0.1).restart();
我會在哪裏把.attr("transform", "translate(10,10)")
定位滑塊?我似乎無處不在。示例(https://bl.ocks.org/mbostock/6452972)首先使用svg.append(「g」)進行分組,但我無法將其與當前代碼進行集成。