52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# File 'lib/spoom/coverage/d3/pie.rb', line 52
def script
" \#{tooltip}\n\n var json_\#{id} = \#{@data.to_json};\n var pie_\#{id} = d3.pie().value((d) => d.value);\n var data_\#{id} = pie_\#{id}(d3.entries(json_\#{id}));\n var sum_\#{id} = d3.sum(data_\#{id}, (d) => d.data.value);\n var title_\#{id} = \#{@title.to_json};\n\n function draw_\#{id}() {\n var pieSize_\#{id} = document.getElementById(\"\#{id}\").clientWidth - 10;\n\n var arcGenerator_\#{id} = d3.arc()\n .innerRadius(pieSize_\#{id} / 4)\n .outerRadius(pieSize_\#{id} / 2);\n\n d3.select(\"#\#{id}\").selectAll(\"*\").remove()\n\n var svg_\#{id} = d3.select(\"#\#{id}\")\n .attr(\"width\", pieSize_\#{id})\n .attr(\"height\", pieSize_\#{id})\n .attr(\"class\", \"pie\")\n .append(\"g\")\n .attr(\"transform\", \"translate(\" + pieSize_\#{id} / 2 + \",\" + pieSize_\#{id} / 2 + \")\");\n\n svg_\#{id}.selectAll(\"arcs\")\n .data(data_\#{id})\n .enter()\n .append('path')\n .attr(\"class\", \"arc\")\n .attr('fill', (d) => strictnessColor(d.data.key))\n .attr('d', arcGenerator_\#{id})\n .on(\"mouseover\", (d) => tooltip.style(\"opacity\", 1))\n .on(\"mousemove\", tooltip_\#{id})\n .on(\"mouseleave\", (d) => tooltip.style(\"opacity\", 0));\n\n svg_\#{id}.selectAll(\"labels\")\n .data(data_\#{id})\n .enter()\n .append('text')\n .attr(\"class\", \"label\")\n .attr(\"transform\", (d) => \"translate(\" + arcGenerator_\#{id}.centroid(d) + \")\")\n .filter(d => (d.endAngle - d.startAngle) > 0.25)\n .append(\"tspan\")\n .attr(\"x\", 0)\n .attr(\"y\", -3)\n .text((d) => d.data.value)\n .append(\"tspan\")\n .attr(\"class\", \"small\")\n .attr(\"x\", 0)\n .attr(\"y\", 13)\n .text((d) => toPercent(d.data.value, sum_\#{id}) + \"%\");\n\n svg_\#{id}\n .append(\"text\")\n .attr(\"class\", \"title\")\n .append(\"tspan\")\n .attr(\"y\", 7)\n .text(title_\#{id});\n }\n\n draw_\#{id}();\n window.addEventListener(\"resize\", draw_\#{id});\n JS\nend\n"
|