Skip to content

Commit 0d745e1

Browse files
committed
feat(chart): all row data used outside of chart should be case sensitive values
1 parent c4d428e commit 0d745e1

File tree

4 files changed

+37
-18
lines changed

4 files changed

+37
-18
lines changed

frontend/src/app/components/ChartGraph/models/ChartDataSet.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,40 +61,47 @@ class ChartDataSetBase extends Array {
6161
protected toCaseInsensitive(key) {
6262
return String(key).toUpperCase();
6363
}
64+
65+
public getFieldOriginKey(field: ChartDataSectionField) {
66+
return this.toOriginKey(field);
67+
}
6468
}
6569

6670
export class ChartDataSet<T>
6771
extends ChartDataSetBase
6872
implements IChartDataSet<T>
6973
{
7074
private columnIndexTable: ColumnIndexTable = {};
75+
private originalFields?: ChartDataSectionField[];
7176

72-
constructor(columns: T[][], metas?: ChartDatasetMeta[]) {
77+
constructor(
78+
columns: T[][],
79+
metas?: ChartDatasetMeta[],
80+
fields?: ChartDataSectionField[],
81+
) {
7382
super(
7483
...(Array.prototype.map.call(columns, c => {
7584
if (c?.length === 1) {
7685
const row = new ChartDataSetRow(metas, []);
7786
row.push(c[0]);
7887
return row;
7988
}
80-
return new ChartDataSetRow(metas, c);
89+
return new ChartDataSetRow(metas, c, fields);
8190
}) as any),
8291
);
92+
this.originalFields = fields;
8393
this.columnIndexTable = super.createColumnIndexTable(metas);
8494
}
8595

8696
public getFieldKey(field: ChartDataSectionField) {
8797
return this.toKey(field);
8898
}
8999

90-
public getFieldOriginKey(field: ChartDataSectionField) {
91-
return this.toOriginKey(field);
92-
}
93-
94100
public getFieldIndex(field: ChartDataSectionField) {
95101
return this.toIndexBy(this.columnIndexTable, field);
96102
}
97103

104+
// TODO(Stephen): should be passed by sorted fields not data configs
98105
public sortBy(dataConfigs: ChartDataConfig[]): void {
99106
const orderConfigs = dataConfigs
100107
.filter(
@@ -129,9 +136,13 @@ export class ChartDataSetRow<T>
129136
implements IChartDataSetRow<T>
130137
{
131138
private columnIndexTable: ColumnIndexTable = {};
139+
private metas: Array<{ name: string }> = [];
140+
private originalFields?: ChartDataSectionField[];
132141

133-
constructor(metas, items: T[]) {
142+
constructor(metas, items: T[], fields?: ChartDataSectionField[]) {
134143
super(...(items as any));
144+
this.metas = metas;
145+
this.originalFields = fields;
135146
this.columnIndexTable = this.createColumnIndexTable(metas);
136147
}
137148

@@ -157,4 +168,11 @@ export class ChartDataSetRow<T>
157168
return acc;
158169
}, {});
159170
}
171+
172+
public convertToCaseSensitiveObject(): object {
173+
return (this.originalFields || []).reduce((acc, cur) => {
174+
acc[this.getFieldOriginKey(cur)] = this[this.getFieldIndex(cur)];
175+
return acc;
176+
}, {});
177+
}
160178
}

frontend/src/app/pages/DashBoardPage/components/WidgetCore/DataChartWidget/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export const DataChartWidget: React.FC<{}> = memo(() => {
5555
if (!params) {
5656
return;
5757
}
58+
console.log(`params ---> `, params);
5859
widgetChartClick(widgetRef.current, params);
5960
},
6061
[widgetChartClick],

frontend/src/app/types/ChartDataSet.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export interface IChartDataSetRow<T> extends Array<T> {
2929
getFieldIndex(field: ChartDataSectionField): number;
3030

3131
convertToObject(): object;
32+
33+
convertToCaseSensitiveObject(): object;
3234
}
3335

3436
export interface IChartDataSet<T> extends Array<IChartDataSetRow<T>> {

frontend/src/app/utils/chartHelper.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ import ChartMetadata from 'app/types/ChartMetadata';
4141
import { NumberUnitKey, NumericUnitDescriptions } from 'globalConstants';
4242
import moment from 'moment';
4343
import { Debugger } from 'utils/debugger';
44-
import { isEmpty,
45-
isEmptyArray,
46-
isUndefined,
47-
meanValue,
48-
pipe,} from 'utils/object';
44+
import { isEmpty, isEmptyArray, meanValue, pipe } from 'utils/object';
4945
import {
5046
flattenHeaderRowsWithoutGroupRow,
5147
getColumnRenderOriginName,
@@ -73,7 +69,7 @@ import {
7369
* @param {IFieldFormatConfig} [format]
7470
* @return {*}
7571
*/
76-
export function toFormattedValue(
72+
export function toFormattedValue(
7773
value?: number | string,
7874
format?: IFieldFormatConfig,
7975
) {
@@ -910,16 +906,17 @@ export function getNameTextStyle(fontFamily, fontSize, color) {
910906
* @template T
911907
* @param {T[][]} [datas]
912908
* @param {ChartDatasetMeta[]} [metas]
913-
* @param {ChartDataConfig[]} [sortedConfigs]
909+
* @param {ChartDataConfig[]} [dataConfigs]
914910
* @return {*} {IChartDataSet<T>}
915911
*/
916912
export function transformToDataSet<T>(
917913
datas?: T[][],
918914
metas?: ChartDatasetMeta[],
919-
sortedConfigs?: ChartDataConfig[],
915+
dataConfigs?: ChartDataConfig[],
920916
): IChartDataSet<T> {
921-
const ds = new ChartDataSet(datas || [], metas || []);
922-
ds.sortBy(sortedConfigs || []);
917+
const fields = (dataConfigs || []).flatMap(config => config.rows || []);
918+
const ds = new ChartDataSet(datas || [], metas || [], fields || []);
919+
ds.sortBy(dataConfigs || []);
923920
return ds;
924921
}
925922

@@ -1220,7 +1217,8 @@ export function getGridStyle(styles) {
12201217
export function getExtraSeriesRowData(data) {
12211218
if (data instanceof ChartDataSetRow) {
12221219
return {
1223-
rowData: data?.convertToObject(),
1220+
// NOTE: row data should be case sensitive except for data chart
1221+
rowData: data?.convertToCaseSensitiveObject(),
12241222
};
12251223
}
12261224

0 commit comments

Comments
 (0)