Skip to content

Commit 3c4b910

Browse files
alison985jezdez
authored andcommittedMar 5, 2018
change pie chart colors (re getredash#240)
Incorporates: fix pie chart multiple colors changed (re getredash#242)
1 parent ea7bcd0 commit 3c4b910

File tree

3 files changed

+90
-16
lines changed

3 files changed

+90
-16
lines changed
 

‎client/app/visualizations/chart/chart-editor.html

+37-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@
99
<li ng-class="{active: currentTab == 'yAxis'}" ng-if="options.globalSeriesType != 'custom'">
1010
<a ng-click="changeTab('yAxis')">Y Axis</a>
1111
</li>
12-
<li ng-class="{active: currentTab == 'series'}" ng-if="options.globalSeriesType != 'custom'">
12+
<li ng-class="{active: currentTab == 'series'}" ng-if="options.globalSeriesType != 'custom' && options.globalSeriesType != 'pie'">
1313
<a ng-click="changeTab('series')">Series</a>
1414
</li>
15+
<li ng-class="{active: currentTab == 'colors'}"
16+
ng-if="options.globalSeriesType == 'pie'">
17+
<a ng-click="changeTab('colors')">Colors</a>
18+
</li>
1519
</ul>
1620
<div ng-if="currentTab == 'general'" class="m-t-10 m-b-10">
1721
<div class="form-group">
@@ -267,4 +271,36 @@ <h4>{{$index == 0 ? 'Left' : 'Right'}} Y Axis</h4>
267271
</tbody>
268272
</table>
269273
</div>
274+
275+
<div ng-show="currentTab == 'colors'">
276+
<table class="table table-condensed col-table">
277+
<thead>
278+
<th>zIndex</th>
279+
<th>Label</th>
280+
<th>Color</th>
281+
</thead>
282+
<tbody ui-sortable ng-model="form.colorsList">
283+
<tr ng-repeat="name in form.colorsList track by name">
284+
<td style="cursor: move;"><i class="fa fa-arrows-v"></i> <span
285+
ng-bind="options.seriesOptions[name].zIndex + 1"></span>
286+
</td>
287+
<td style="padding: 3px; width: 300px;">
288+
{{name}}
289+
</td>
290+
<td style="padding: 3px; width: 35px;">
291+
<ui-select ng-model="options.seriesOptions[name].color">
292+
<ui-select-match>
293+
<color-box color="$select.selected.value"></color-box>
294+
</ui-select-match>
295+
<ui-select-choices repeat="color.value as (key, color) in colors">
296+
<color-box color="color.value"></color-box>
297+
<span ng-bind-html="color.key | capitalize | highlight: $select.search"></span>
298+
</ui-select-choices>
299+
</ui-select>
300+
</td>
301+
</tr>
302+
</tbody>
303+
</table>
304+
</div>
270305
</div>
306+

‎client/app/visualizations/chart/index.js

+44-14
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,48 @@ function ChartEditor(ColorPalette, clientConfig) {
123123
}
124124

125125
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+
}
139168
}
140169

141170
function setColumnRole(role, column) {
@@ -167,6 +196,8 @@ function ChartEditor(ColorPalette, clientConfig) {
167196
yAxisColumns: [],
168197
seriesList: sortBy(keys(scope.options.seriesOptions), name =>
169198
scope.options.seriesOptions[name].zIndex),
199+
colorsList: sortBy(keys(scope.options.colorOptions), name =>
200+
scope.options.colorOptions[name].zIndex),
170201
};
171202

172203
scope.$watchCollection('form.seriesList', (value) => {
@@ -176,7 +207,6 @@ function ChartEditor(ColorPalette, clientConfig) {
176207
});
177208
});
178209

179-
180210
scope.$watchCollection('form.yAxisColumns', (value, old) => {
181211
each(old, unsetColumn);
182212
each(value, partial(setColumnRole, 'y'));

‎client/app/visualizations/chart/plotly/utils.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,17 @@ function preparePieData(seriesList, options) {
183183
return map(seriesList, (serie, index) => {
184184
const xPosition = (index % cellsInRow) * cellWidth;
185185
const yPosition = Math.floor(index / cellsInRow) * cellHeight;
186+
const labels = map(serie.data, (row, rowIdx) => {
187+
const rowX = hasX ? row.x : `Slice ${index}`;
188+
const rowOpts = options.seriesOptions[rowX];
189+
if (rowOpts) {
190+
colorPalette[rowIdx] = rowOpts.color;
191+
}
192+
return rowX;
193+
});
186194
return {
187195
values: pluck(serie.data, 'y'),
188-
labels: map(serie.data, row => (hasX ? row.x : `Slice ${index}`)),
196+
labels: labels,
189197
type: 'pie',
190198
hole: 0.4,
191199
marker: { colors: ColorPaletteArray },

0 commit comments

Comments
 (0)
Please sign in to comment.