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,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 | if (this.caulculateLegendData) { | 1229 | if (this.caulculateLegendData) { |
1233 | this.data.forEach((dataSetHolder, keyIndex) => { | 1230 | this.data.forEach((dataSetHolder, keyIndex) => { |
1234 | this.updateLegend(keyIndex, dataSetHolder.data, false); | 1231 | this.updateLegend(keyIndex, dataSetHolder.data, false); |
@@ -38,6 +38,9 @@ | @@ -38,6 +38,9 @@ | ||
38 | </mat-option> | 38 | </mat-option> |
39 | </mat-select> | 39 | </mat-select> |
40 | </mat-form-field> | 40 | </mat-form-field> |
41 | + <mat-checkbox formControlName="sortDataKeys"> | ||
42 | + {{ 'legend.sort-legend' | translate }} | ||
43 | + </mat-checkbox> | ||
41 | <mat-checkbox formControlName="showMin"> | 44 | <mat-checkbox formControlName="showMin"> |
42 | {{ 'legend.show-min' | translate }} | 45 | {{ 'legend.show-min' | translate }} |
43 | </mat-checkbox> | 46 | </mat-checkbox> |
@@ -68,6 +68,7 @@ export class LegendConfigPanelComponent extends PageComponent implements OnInit | @@ -68,6 +68,7 @@ export class LegendConfigPanelComponent extends PageComponent implements OnInit | ||
68 | this.legendConfigForm = this.fb.group({ | 68 | this.legendConfigForm = this.fb.group({ |
69 | direction: [this.data.legendConfig.direction, []], | 69 | direction: [this.data.legendConfig.direction, []], |
70 | position: [this.data.legendConfig.position, []], | 70 | position: [this.data.legendConfig.position, []], |
71 | + sortDataKeys: [this.data.legendConfig.sortDataKeys, []], | ||
71 | showMin: [this.data.legendConfig.showMin, []], | 72 | showMin: [this.data.legendConfig.showMin, []], |
72 | showMax: [this.data.legendConfig.showMax, []], | 73 | showMax: [this.data.legendConfig.showMax, []], |
73 | showAvg: [this.data.legendConfig.showAvg, []], | 74 | showAvg: [this.data.legendConfig.showAvg, []], |
@@ -60,8 +60,11 @@ export class LegendComponent implements OnInit { | @@ -60,8 +60,11 @@ export class LegendComponent implements OnInit { | ||
60 | } | 60 | } |
61 | 61 | ||
62 | legendKeys(): LegendKey[] { | 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,6 +203,7 @@ export const legendPositionTranslationMap = new Map<LegendPosition, string>( | ||
203 | export interface LegendConfig { | 203 | export interface LegendConfig { |
204 | position: LegendPosition; | 204 | position: LegendPosition; |
205 | direction?: LegendDirection; | 205 | direction?: LegendDirection; |
206 | + sortDataKeys: boolean; | ||
206 | showMin: boolean; | 207 | showMin: boolean; |
207 | showMax: boolean; | 208 | showMax: boolean; |
208 | showAvg: boolean; | 209 | showAvg: boolean; |
@@ -213,6 +214,7 @@ export function defaultLegendConfig(wType: widgetType): LegendConfig { | @@ -213,6 +214,7 @@ export function defaultLegendConfig(wType: widgetType): LegendConfig { | ||
213 | return { | 214 | return { |
214 | direction: LegendDirection.column, | 215 | direction: LegendDirection.column, |
215 | position: LegendPosition.bottom, | 216 | position: LegendPosition.bottom, |
217 | + sortDataKeys: false, | ||
216 | showMin: false, | 218 | showMin: false, |
217 | showMax: false, | 219 | showMax: false, |
218 | showAvg: wType === widgetType.timeseries, | 220 | showAvg: wType === widgetType.timeseries, |
@@ -1664,6 +1664,7 @@ | @@ -1664,6 +1664,7 @@ | ||
1664 | "legend": { | 1664 | "legend": { |
1665 | "direction": "Legend direction", | 1665 | "direction": "Legend direction", |
1666 | "position": "Legend position", | 1666 | "position": "Legend position", |
1667 | + "sort-legend": "Sort datakeys in legend", | ||
1667 | "show-max": "Show max value", | 1668 | "show-max": "Show max value", |
1668 | "show-min": "Show min value", | 1669 | "show-min": "Show min value", |
1669 | "show-avg": "Show average value", | 1670 | "show-avg": "Show average value", |