Skip to content

Commit 193cc6d

Browse files
committed
feat:(Chart) add chartHelper types
1 parent 3cc8160 commit 193cc6d

File tree

5 files changed

+47
-26
lines changed

5 files changed

+47
-26
lines changed

frontend/src/app/components/ChartGraph/BasicBarChart/BasicBarChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ class BasicBarChart extends Chart {
270270
),
271271
name: k,
272272
data: xAxisColumns?.[0]?.data?.map(d => {
273-
const row = dataSet.find(r => r.getCell(xAxisConfig) === d);
273+
const row = dataSet.find(r => r.getCell(xAxisConfig) === d)!;
274274
return {
275275
...getExtraSeriesRowData(row),
276276
...getExtraSeriesDataFormat(aggConfig?.format),

frontend/src/app/components/ChartGraph/BasicLineChart/BasicLineChart.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ class BasicLineChart extends Chart {
239239
normal: { color: itemStyleColor?.value },
240240
},
241241
data: xAxisColumns[0].data.map(d => {
242-
const row = dataSet.find(r => r.getCell(xAxisConfig) === d);
242+
const row = dataSet.find(r => r.getCell(xAxisConfig) === d)!;
243243
return {
244244
...getExtraSeriesRowData(row),
245245
...getExtraSeriesDataFormat(aggConfig?.format),

frontend/src/app/components/ChartGraph/BasicLineChart/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import {
77
export type Series = {
88
data: Array<{
99
rowData: { [key: string]: any };
10-
value: number | string;
11-
name?: string;
10+
value: number | string | undefined;
11+
name?: string | undefined;
1212
format: IFieldFormatConfig | undefined;
1313
}>;
1414
smooth?: boolean;

frontend/src/app/utils/__tests__/chartHelper.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,20 @@ describe('Chart Helper ', () => {
715715
},
716716
'13',
717717
],
718+
[
719+
0,
720+
{
721+
type: 'numeric',
722+
numeric: {
723+
decimalPlaces: 0,
724+
unitKey: 'none',
725+
useThousandSeparator: false,
726+
prefix: '',
727+
suffix: '',
728+
},
729+
},
730+
'0',
731+
],
718732
[
719733
NaN,
720734
{

frontend/src/app/utils/chartHelper.ts

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
FontStyle,
3131
GridStyle,
3232
IFieldFormatConfig,
33+
LineStyle,
3334
MarkArea,
3435
MarkDataConfig,
3536
MarkLine,
@@ -297,9 +298,9 @@ function dateFormater(
297298
* console.log(colorList); // ["#298ffe","#dae9ff","#fe705a","#ffdcdc","#751adb","#8663d7","#15AD31","#FAD414","#E62412"]
298299
*
299300
* @export
300-
* @return {*} default color array
301+
* @return {string[]} default color array
301302
*/
302-
export function getDefaultThemeColor() {
303+
export function getDefaultThemeColor(): string[] {
303304
return echartsDefaultTheme.color;
304305
}
305306

@@ -936,11 +937,11 @@ export function getAxisLine(show: boolean, lineStyle?): AxisLineStyle {
936937
}
937938

938939
export function getAxisLabel(
939-
show,
940+
show: boolean,
940941
font: FontStyle,
941-
interval = null,
942-
rotate = null,
943-
overflow = null,
942+
interval: string | null = null,
943+
rotate: number | null = null,
944+
overflow: string | null = null,
944945
): AxisLabel {
945946
return {
946947
show,
@@ -951,24 +952,30 @@ export function getAxisLabel(
951952
};
952953
}
953954

954-
export function getSplitLine(show, lineStyle): AxisLineStyle {
955+
export function getSplitLine(
956+
show: boolean,
957+
lineStyle: LineStyle,
958+
): AxisLineStyle {
955959
return {
956960
show,
957961
lineStyle,
958962
};
959963
}
960964

961-
export function getAxisTick(show, lineStyle): AxisLineStyle {
965+
export function getAxisTick(
966+
show: boolean,
967+
lineStyle: LineStyle,
968+
): AxisLineStyle {
962969
return {
963970
show,
964971
lineStyle,
965972
};
966973
}
967974

968975
export function getNameTextStyle(
969-
fontFamily,
970-
fontSize,
971-
color,
976+
fontFamily: string,
977+
fontSize: number,
978+
color: string,
972979
): { fontFamily: string; fontSize: number; color: string } {
973980
return {
974981
fontFamily,
@@ -1126,7 +1133,7 @@ export function getDataColumnMaxAndMin(
11261133
export function getDataColumnMaxAndMin2(
11271134
chartDataSetRows: IChartDataSetRow<string>[],
11281135
config?: ChartDataSectionField,
1129-
) {
1136+
): { min: number; max: number } {
11301137
if (!config || !chartDataSetRows?.length) {
11311138
return { min: 0, max: 100 };
11321139
}
@@ -1139,10 +1146,10 @@ export function getDataColumnMaxAndMin2(
11391146
}
11401147

11411148
export function getSeriesTooltips4Scatter(
1142-
params,
1143-
tooltipItemConfigs,
1149+
params: Array<{ value: string | number }>,
1150+
tooltipItemConfigs: ChartDataSectionField[],
11441151
start?: number,
1145-
) {
1152+
): string[] {
11461153
const dataValues = params?.[0]?.value;
11471154
return tooltipItemConfigs.map((config, index) =>
11481155
valueFormatter(config, dataValues?.[!!start ? start + index : index]),
@@ -1269,10 +1276,10 @@ export function valueFormatter(
12691276

12701277
export function getScatterSymbolSizeFn(
12711278
valueIndex: number,
1272-
max,
1273-
min,
1279+
max: number,
1280+
min: number,
12741281
cycleRatio?: number,
1275-
) {
1282+
): (val) => number {
12761283
min = Math.min(0, min);
12771284
const scaleRatio = cycleRatio || 1;
12781285
const defaultScatterPointPixelSize = 10;
@@ -1324,7 +1331,7 @@ export function getExtraSeriesDataFormat(format?: IFieldFormatConfig): {
13241331
export function getColorizeGroupSeriesColumns(
13251332
chartDataSet: IChartDataSet<string>,
13261333
groupConfig: ChartDataSectionField,
1327-
) {
1334+
): { [x: string]: IChartDataSet<string> }[] {
13281335
return Object.entries(chartDataSet.groupBy(groupConfig)).map(([k, v]) => {
13291336
let a = {};
13301337
a[k] = v;
@@ -1400,14 +1407,14 @@ export function isMatchRequirement(
14001407
}
14011408

14021409
// 获取是否展示刻度
1403-
export const getIntervalShow = interval =>
1410+
export const getIntervalShow = (interval): boolean =>
14041411
interval !== 'auto' && interval !== null;
14051412

14061413
// 判断overflow 条件是否已生效
14071414
export function hadAxisLabelOverflowConfig(
14081415
options?: ECBasicOption,
14091416
horizon: boolean = false,
1410-
) {
1417+
): boolean {
14111418
if (!options) return false;
14121419
const axisName = !horizon ? 'xAxis' : 'yAxis';
14131420

@@ -1416,7 +1423,7 @@ export function hadAxisLabelOverflowConfig(
14161423

14171424
const { overflow, interval, show } = axisLabelOpts;
14181425

1419-
return show && overflow && getIntervalShow(interval);
1426+
return !!(show && overflow && getIntervalShow(interval));
14201427
}
14211428

14221429
// 处理溢出情况

0 commit comments

Comments
 (0)