Commit c40f6bf47c58cfc26d6d04729093da50e0a3b054
1 parent
f73b05a8
UI: Added new options for legend config (sort datakeys in legend)
Showing
6 changed files
with
12 additions
and
5 deletions
... | ... | @@ -1226,9 +1226,6 @@ export class WidgetSubscription implements IWidgetSubscription { |
1226 | 1226 | }); |
1227 | 1227 | }); |
1228 | 1228 | } |
1229 | - if (this.displayLegend) { | |
1230 | - this.legendData.keys = this.legendData.keys.sort((key1, key2) => key1.dataKey.label.localeCompare(key2.dataKey.label)); | |
1231 | - } | |
1232 | 1229 | if (this.caulculateLegendData) { |
1233 | 1230 | this.data.forEach((dataSetHolder, keyIndex) => { |
1234 | 1231 | this.updateLegend(keyIndex, dataSetHolder.data, false); | ... | ... |
... | ... | @@ -38,6 +38,9 @@ |
38 | 38 | </mat-option> |
39 | 39 | </mat-select> |
40 | 40 | </mat-form-field> |
41 | + <mat-checkbox formControlName="sortDataKeys"> | |
42 | + {{ 'legend.sort-legend' | translate }} | |
43 | + </mat-checkbox> | |
41 | 44 | <mat-checkbox formControlName="showMin"> |
42 | 45 | {{ 'legend.show-min' | translate }} |
43 | 46 | </mat-checkbox> | ... | ... |
... | ... | @@ -68,6 +68,7 @@ export class LegendConfigPanelComponent extends PageComponent implements OnInit |
68 | 68 | this.legendConfigForm = this.fb.group({ |
69 | 69 | direction: [this.data.legendConfig.direction, []], |
70 | 70 | position: [this.data.legendConfig.position, []], |
71 | + sortDataKeys: [this.data.legendConfig.sortDataKeys, []], | |
71 | 72 | showMin: [this.data.legendConfig.showMin, []], |
72 | 73 | showMax: [this.data.legendConfig.showMax, []], |
73 | 74 | showAvg: [this.data.legendConfig.showAvg, []], | ... | ... |
... | ... | @@ -60,8 +60,11 @@ export class LegendComponent implements OnInit { |
60 | 60 | } |
61 | 61 | |
62 | 62 | legendKeys(): LegendKey[] { |
63 | - return this.legendData.keys | |
64 | - .filter(legendKey => this.legendData.keys[legendKey.dataIndex].dataKey.inLegend); | |
63 | + let keys = this.legendData.keys; | |
64 | + if (this.legendConfig.sortDataKeys) { | |
65 | + keys = this.legendData.keys.sort((key1, key2) => key1.dataKey.label.localeCompare(key2.dataKey.label)); | |
66 | + } | |
67 | + return keys.filter(legendKey => this.legendData.keys[legendKey.dataIndex].dataKey.inLegend); | |
65 | 68 | } |
66 | 69 | |
67 | 70 | } | ... | ... |
... | ... | @@ -203,6 +203,7 @@ export const legendPositionTranslationMap = new Map<LegendPosition, string>( |
203 | 203 | export interface LegendConfig { |
204 | 204 | position: LegendPosition; |
205 | 205 | direction?: LegendDirection; |
206 | + sortDataKeys: boolean; | |
206 | 207 | showMin: boolean; |
207 | 208 | showMax: boolean; |
208 | 209 | showAvg: boolean; |
... | ... | @@ -213,6 +214,7 @@ export function defaultLegendConfig(wType: widgetType): LegendConfig { |
213 | 214 | return { |
214 | 215 | direction: LegendDirection.column, |
215 | 216 | position: LegendPosition.bottom, |
217 | + sortDataKeys: false, | |
216 | 218 | showMin: false, |
217 | 219 | showMax: false, |
218 | 220 | showAvg: wType === widgetType.timeseries, | ... | ... |
... | ... | @@ -1664,6 +1664,7 @@ |
1664 | 1664 | "legend": { |
1665 | 1665 | "direction": "Legend direction", |
1666 | 1666 | "position": "Legend position", |
1667 | + "sort-legend": "Sort datakeys in legend", | |
1667 | 1668 | "show-max": "Show max value", |
1668 | 1669 | "show-min": "Show min value", |
1669 | 1670 | "show-avg": "Show average value", | ... | ... |