【发布时间】:2019-09-29 02:25:43
【问题描述】:
我正在尝试反转这个旭日形可视化的色带。它使用带有标签等的旭日形可缩放图表。通常,您只需反转它们正在使用的范围内的值,但我不太明白它是如何获取设置值的。
这是我正在使用的配色方案 https://github.com/d3/d3-scale-chromatic
d3.interpolateViridis
目前它从深紫色变为亮黄色,我需要反转颜色以从亮黄色变为深紫色。所以我需要改变范围值的起点。但我不明白他在下面是如何做到的。
建议的方法是更改范围并首先从范围的最大值开始。但这似乎不起作用。
require()('@observablehq/flare').then(data => {
const root = partition(data);
const color =
d3.scaleOrdinal().range(d3.quantize(d3.interpolateViridis,
data.children.length +1));
console.log(data.children.length)
root.each(d => d.current = d);
const svg = d3.select('#partitionSVG')
.style("width", "50%")
.style("height", "80%")
.style("font", "10px sans-serif")
const g = svg.append("g")
.attr('transform', 'translate(' + width/2 + ',' + height/2 +')');
const path = g.append("g")
.selectAll("path")
.data(root.descendants().slice(1))
.join("path")
.attr("fill", d => {
while (d.depth > 1)
d = d.parent;
return color(d.data.name);
})
.attr("fill-opacity", d => arcVisible(d.current) ? (d.children ? 0.6 : 0.4) : 0)
.attr("d", d => arc(d.current));
【问题讨论】:
标签: javascript d3.js data-visualization