Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
D3.js 如何修复d3js中突破图表的文本?_D3.js - Fatal编程技术网

D3.js 如何修复d3js中突破图表的文本?

D3.js 如何修复d3js中突破图表的文本?,d3.js,D3.js,导出默认函数定义(运行时、观察者){ const main=runtime.module(); 主变量(观察者(“图表”))。定义(“图表”、“分区”、“数据”、“d3”、“宽度”、“颜色”、“弧”、“格式”、“半径”)、函数(分区、数据、d3、宽度、颜色、弧、格式、半径) { 常量根=分区(数据); 根。每个(d=>d.current=d); const svg=d3.create(“svg”) .attr(“视图框”[0,0,宽度,宽度]) .style(“字体”,“10px无衬线”); 常

导出默认函数定义(运行时、观察者){
const main=runtime.module();
主变量(观察者(“图表”))。定义(“图表”、“分区”、“数据”、“d3”、“宽度”、“颜色”、“弧”、“格式”、“半径”)、函数(分区、数据、d3、宽度、颜色、弧、格式、半径)
{
常量根=分区(数据);
根。每个(d=>d.current=d);
const svg=d3.create(“svg”)
.attr(“视图框”[0,0,宽度,宽度])
.style(“字体”,“10px无衬线”);
常量g=svg.append(“g”)
.attr(“transform”,`translate(${width/2},${width/2})`);
常量路径=g.append(“g”)
.selectAll(“路径”)
.data(root.subjects().slice(1))
.join(“路径”)
.attr(“fill”,d=>{while(d.depth>1)d=d.parent;返回颜色(d.data.name);})
.attr(“填充不透明度”,d=>arcVisible(d.current)?(d.children?0.6:0.4):0)
.attr(“d”,d=>弧(d.电流));
path.filter(d=>d.children)
.style(“光标”、“指针”)
。开启(“点击”,点击);
路径追加(“标题”)
.text(d=>`${d.祖先().map(d=>d.data.name).reverse().join(“/”)}\n${format(d.value)}`);
常量标签=g.append(“g”)
.attr(“指针事件”、“无”)
.attr(“文本锚定”、“中间”)
.style(“用户选择”、“无”)
.selectAll(“文本”)
.data(root.subjects().slice(1))
.join(“文本”)
.attr(“dy”,“0.35em”)
.attr(“填充不透明度”,d=>+labelVisible(d.current))
.attr(“转换”,d=>标签转换(d.current))
.text(d=>d.data.name);
const parent=g.append(“圆”)
.基准面(根)
.attr(“r”,半径)
.attr(“填充”、“无”)
.attr(“指针事件”、“全部”)
。开启(“点击”,点击);
单击函数(事件,p){
父数据(p.parent | | root);
root.each(d=>d.target={
x0:Math.max(0,Math.min(1,(d.x0-p.x0)/(p.x1-p.x0))*2*Math.PI,
x1:Math.max(0,Math.min(1,(d.x1-p.x0)/(p.x1-p.x0))*2*Math.PI,
y0:数学最大值(0,d.y0-p.depth),
y1:数学最大值(0,d.y1-p.depth)
});
const t=g.transition().持续时间(750);
//转换所有圆弧上的数据,即使是不可见的圆弧,
//因此,如果此过渡被中断,将开始输入圆弧
//从所需位置的下一个过渡。
路径转换(t)
.tween(“数据”,d=>{
常数i=d3.插值(d.电流,d.目标);
返回t=>d.current=i(t);
})
.过滤器(功能(d){
return+this.getAttribute(“填充不透明度”)| | arcVisible(d.target);
})
.attr(“填充不透明度”,d=>arcVisible(d.target)?(d.children?0.6:0.4):0)
.attrween(“d”,d=>()=>弧(d.电流));
标签.过滤器(功能(d){
return+this.getAttribute(“填充不透明度”)| | labelVisible(d.target);
}).过渡(t)
.attr(“填充不透明度”,d=>+labelVisible(d.target))
.attrTween(“变换”,d=>()=>标签变换(d.current));
}
功能arcVisible(d){
返回d.y1=1&&d.x1>d.x0;
}
功能标签可视(d){
返回d.y1=1&(d.y1-d.y0)*(d.x1-d.x0)>0.03;
}
功能标签转换(d){
常数x=(d.x0+d.x1)/2*180/Math.PI;
常数y=(d.y0+d.y1)/2*半径;
返回`rotate(${x-90})translate(${y},0)rotate(${x<180?0:180})`;
}
返回svg.node();
});
main.variable().define(“数据”,[“d3”],函数(d3){return(
d3.json(“https://gist.githubusercontent.com/KyungJinDo/31a920e4d768380540d6af903ee3ed67/raw/2b746256945d14888c69ae3fbf77ff6d29285021/data_ganghwa.json")
)});
main.variable().define(“分区”,[“d3”],函数(d3){return(
数据=>{
const root=d3.层次结构(数据)
.sum(d=>d.value*2)
.sort((a,b)=>b.value-a.value);
返回d3.partition()
.size([2*Math.PI,root.height+1])
(根);
}
)});
main.variable().define(“color”,[“d3”,“data”],函数(d3,data){return(
d3.scaleOrdinal(d3.quantize(d3.interpolaterInbow,data.children.length+1))
)});
main.variable().define(“format”,[“d3”],函数(d3){return(
d3.格式(“,”)
)});
main.variable().define(“宽度”,函数(){return(
932
)});
main.variable().define(“半径”、[“宽度”],函数(宽度){return(
宽度/6
)});
main.variable().define(“弧”、[“d3”、“半径”],函数(d3,半径){return(
d3.arc()
.startAngle(d=>d.x0)
.端角(d=>d.x1)
.焊盘角度(d=>数学最小值((d.x1-d.x0)/2,0.005))
.焊盘半径(半径*1.5)
.内半径(d=>d.y0*半径)
.outerRadius(d=>数学最大值(d.y0*半径,d.y1*半径-1))
)});
main.variable().define(“d3”、[“require”]、函数(require){return(
要求(”d3@6")
)});
回水总管;
}