MCPcopy
hub / github.com/timqian/chart.xkcd / render

Method render

src/Pie.js:63–146  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

61 }
62
63 render() {
64 if (this.title) {
65 addLabels.title(this.svgEl, this.title, this.options.strokeColor);
66 }
67
68 const tooltip = new Tooltip({
69 parent: this.svgEl,
70 title: 'tooltip',
71 items: [{ color: 'red', text: 'weweyang: 12' }, { color: 'blue', text: 'timqian: 13' }],
72 position: { x: 30, y: 30, type: config.positionType.upRight },
73 unxkcdify: this.options.unxkcdify,
74 strokeColor: this.options.strokeColor,
75 backgroundColor: this.options.backgroundColor,
76 });
77
78 const radius = Math.min(this.width, this.height) / 2 - margin;
79
80 const thePie = pie();
81
82 const dataReady = thePie(this.data.datasets[0].data);
83
84 const theArc = arc()
85 .innerRadius(radius
86 * (this.options.innerRadius === undefined ? 0.5 : this.options.innerRadius))
87 .outerRadius(radius);
88
89 this.chart.selectAll('.xkcd-chart-arc')
90 .data(dataReady)
91 .enter()
92 .append('path')
93 .attr('class', '.xkcd-chart-arc')
94 .attr('d', theArc)
95 .attr('fill', 'none')
96 .attr('stroke', this.options.strokeColor)
97 .attr('stroke-width', 2)
98 .attr('fill', (d, i) => this.options.dataColors[i])
99 .attr('filter', this.filter)
100 // .attr("fill-opacity", 0.6)
101 .on('mouseover', (d, i, nodes) => {
102 select(nodes[i]).attr('fill-opacity', 0.6);
103 tooltip.show();
104 })
105 .on('mouseout', (d, i, nodes) => {
106 select(nodes[i]).attr('fill-opacity', 1);
107 tooltip.hide();
108 })
109 .on('mousemove', (d, i, nodes) => {
110 const tipX = mouse(nodes[i])[0] + (this.width / 2) + 10;
111 const tipY = mouse(nodes[i])[1] + (this.height / 2) + 10;
112
113 tooltip.update({
114 title: this.data.labels[i],
115 items: [{
116 color: this.options.dataColors[i],
117 text: `${this.data.datasets[0].label || ''}: ${d.data}`,
118 }],
119 position: {
120 x: tipX,

Callers 1

constructorMethod · 0.95

Calls 4

showMethod · 0.95
hideMethod · 0.95
updateMethod · 0.95
addLegendFunction · 0.85

Tested by

no test coverage detected