Skip to content

Commit 6bc05be

Browse files
multipies
1 parent 5c64ce0 commit 6bc05be

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

src/plotly_renderers.coffee

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,12 @@ callWithJQuery ($, Plotly) ->
4141
labels.push(datumKey.join('-') || ' ')
4242

4343
trace = {name: traceKey.join('-') || fullAggName}
44-
trace.x = if transpose then values else labels
45-
trace.y = if transpose then labels else values
44+
if traceOptions.type == "pie"
45+
trace.values = values
46+
trace.labels = if labels.length > 1 then labels else [fullAggName]
47+
else
48+
trace.x = if transpose then values else labels
49+
trace.y = if transpose then labels else values
4650
return $.extend(trace, traceOptions)
4751

4852
if transpose
@@ -55,18 +59,32 @@ callWithJQuery ($, Plotly) ->
5559
titleText += " #{opts.localeStrings.vs} #{hAxisTitle}" if hAxisTitle != ""
5660
titleText += " #{opts.localeStrings.by} #{groupByTitle}" if groupByTitle != ""
5761

58-
layout = {
62+
layout =
5963
title: titleText
6064
hovermode: 'closest'
6165
width: window.innerWidth / 1.4
6266
height: window.innerHeight / 1.4 - 50
63-
xaxis:
67+
68+
if traceOptions.type == 'pie'
69+
columns = Math.ceil(Math.sqrt(data.length))
70+
rows = Math.ceil(data.length / columns)
71+
layout.grid = {columns, rows}
72+
for i, d of data
73+
d.domain = {
74+
row: Math.floor(i / columns),
75+
column: i - columns * Math.floor(i / columns),
76+
}
77+
if data.length > 1
78+
d.title = d.name
79+
layout.showlegend = false if data[0].labels.length == 1
80+
else
81+
layout.xaxis =
6482
title: if transpose then fullAggName else null
6583
automargin: true
66-
yaxis:
84+
layout.yaxis =
6785
title: if transpose then null else fullAggName
6886
automargin: true
69-
}
87+
7088

7189
result = $("<div>").appendTo $("body")
7290
Plotly.newPlot(result[0], data, $.extend(layout, layoutOptions, opts.plotly), opts.plotlyConfig)
@@ -121,3 +139,6 @@ callWithJQuery ($, Plotly) ->
121139
"Line Chart": makePlotlyChart()
122140
"Area Chart": makePlotlyChart({stackgroup: 1})
123141
"Scatter Chart": makePlotlyScatterChart()
142+
'Multiple Pie Chart': makePlotlyChart(
143+
{type: 'pie', scalegroup: 1, hoverinfo: 'label+value', textinfo: 'none'},
144+
{}, true)

0 commit comments

Comments
 (0)