@@ -123,19 +123,48 @@ function ChartEditor(ColorPalette, clientConfig) {
123
123
}
124
124
125
125
function refreshSeries ( ) {
126
- const seriesNames = pluck ( scope . queryResult . getChartData ( scope . options . columnMapping ) , 'name' ) ;
127
- const existing = keys ( scope . options . seriesOptions ) ;
128
- each ( difference ( seriesNames , existing ) , ( name ) => {
129
- scope . options . seriesOptions [ name ] = {
130
- type : scope . options . globalSeriesType ,
131
- yAxis : 0 ,
132
- } ;
133
- scope . form . seriesList . push ( name ) ;
134
- } ) ;
135
- each ( difference ( existing , seriesNames ) , ( name ) => {
136
- scope . form . seriesList = without ( scope . form . seriesList , name ) ;
137
- delete scope . options . seriesOptions [ name ] ;
138
- } ) ;
126
+ // for pie charts only get color list (x row) instead of series list (y column)
127
+ if ( scope . options . globalSeriesType === 'pie' ) {
128
+ const seriesData = scope . queryResult . getData ( ) ;
129
+ scope . form . colorsList = [ ] ;
130
+ const xColumnName = scope . form . xAxisColumn ;
131
+ seriesData . forEach ( ( rowOfData ) => {
132
+ scope . form . colorsList . push ( rowOfData [ xColumnName ] ) ;
133
+ } ) ;
134
+
135
+ const colorNames = scope . form . colorsList ;
136
+ let existing = [ ] ;
137
+ if ( scope . options . colorOptions === undefined ) {
138
+ existing = colorNames ;
139
+ } else {
140
+ existing = keys ( scope . options . colorOptions ) ;
141
+ }
142
+ each ( difference ( colorNames , existing ) , ( name ) => {
143
+ scope . options . colorOptions [ name ] = {
144
+ type : scope . options . globalSeriesType ,
145
+ yAxis : 0 ,
146
+ } ;
147
+ scope . form . colorsList . push ( name ) ;
148
+ } ) ;
149
+ each ( difference ( existing , colorNames ) , ( name ) => {
150
+ scope . form . colorsList = without ( scope . form . colorsList , name ) ;
151
+ delete scope . options . colorOptions [ name ] ;
152
+ } ) ;
153
+ } else {
154
+ const seriesNames = pluck ( scope . queryResult . getChartData ( scope . options . columnMapping ) , 'name' ) ;
155
+ const existing = keys ( scope . options . seriesOptions ) ;
156
+ each ( difference ( seriesNames , existing ) , ( name ) => {
157
+ scope . options . seriesOptions [ name ] = {
158
+ type : scope . options . globalSeriesType ,
159
+ yAxis : 0 ,
160
+ } ;
161
+ scope . form . seriesList . push ( name ) ;
162
+ } ) ;
163
+ each ( difference ( existing , seriesNames ) , ( name ) => {
164
+ scope . form . seriesList = without ( scope . form . seriesList , name ) ;
165
+ delete scope . options . seriesOptions [ name ] ;
166
+ } ) ;
167
+ }
139
168
}
140
169
141
170
function setColumnRole ( role , column ) {
@@ -167,6 +196,8 @@ function ChartEditor(ColorPalette, clientConfig) {
167
196
yAxisColumns : [ ] ,
168
197
seriesList : sortBy ( keys ( scope . options . seriesOptions ) , name =>
169
198
scope . options . seriesOptions [ name ] . zIndex ) ,
199
+ colorsList : sortBy ( keys ( scope . options . colorOptions ) , name =>
200
+ scope . options . colorOptions [ name ] . zIndex ) ,
170
201
} ;
171
202
172
203
scope . $watchCollection ( 'form.seriesList' , ( value ) => {
@@ -176,7 +207,6 @@ function ChartEditor(ColorPalette, clientConfig) {
176
207
} ) ;
177
208
} ) ;
178
209
179
-
180
210
scope . $watchCollection ( 'form.yAxisColumns' , ( value , old ) => {
181
211
each ( old , unsetColumn ) ;
182
212
each ( value , partial ( setColumnRole , 'y' ) ) ;
0 commit comments