@@ -41,8 +41,12 @@ callWithJQuery ($, Plotly) ->
41
41
labels .push (datumKey .join (' -' ) || ' ' )
42
42
43
43
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
46
50
return $ .extend (trace, traceOptions)
47
51
48
52
if transpose
@@ -55,18 +59,32 @@ callWithJQuery ($, Plotly) ->
55
59
titleText += " #{ opts .localeStrings .vs } #{ hAxisTitle} " if hAxisTitle != " "
56
60
titleText += " #{ opts .localeStrings .by } #{ groupByTitle} " if groupByTitle != " "
57
61
58
- layout = {
62
+ layout =
59
63
title : titleText
60
64
hovermode : ' closest'
61
65
width : window .innerWidth / 1.4
62
66
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 =
64
82
title : if transpose then fullAggName else null
65
83
automargin : true
66
- yaxis :
84
+ layout . yaxis =
67
85
title : if transpose then null else fullAggName
68
86
automargin : true
69
- }
87
+
70
88
71
89
result = $ (" <div>" ).appendTo $ (" body" )
72
90
Plotly .newPlot (result[0 ], data, $ .extend (layout, layoutOptions, opts .plotly ), opts .plotlyConfig )
@@ -121,3 +139,6 @@ callWithJQuery ($, Plotly) ->
121
139
" Line Chart" : makePlotlyChart ()
122
140
" Area Chart" : makePlotlyChart ({stackgroup : 1 })
123
141
" Scatter Chart" : makePlotlyScatterChart ()
142
+ ' Multiple Pie Chart' : makePlotlyChart (
143
+ {type : ' pie' , scalegroup : 1 , hoverinfo : ' label+value' , textinfo : ' none' },
144
+ {}, true )
0 commit comments