Skip to content

Commit 6fd464a

Browse files
committed
feat(dashboard): auto borderWidth of heatmap by width & height
1 parent e632af1 commit 6fd464a

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

dashboard/src/components/plugins/viz-components/heatmap/option/index.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,23 @@ const defaultOption = {
1717
},
1818
};
1919

20-
export function getOption(conf: IHeatmapConf, data: TPanelData, variables: ITemplateVariable[]) {
20+
function calcBorderWidth(xlen: number, ylen: number, width: number, height: number) {
21+
if (width < xlen * 10 || height < ylen * 10) {
22+
return 0;
23+
}
24+
if (width < xlen * 20 || height < ylen * 20) {
25+
return 1;
26+
}
27+
return 2;
28+
}
29+
30+
export function getOption(
31+
conf: IHeatmapConf,
32+
data: TPanelData,
33+
variables: ITemplateVariable[],
34+
width: number,
35+
height: number,
36+
) {
2137
if (!conf.x_axis.data_key || !conf.y_axis.data_key || !conf.heat_block.data_key) {
2238
return {};
2339
}
@@ -36,7 +52,7 @@ export function getOption(conf: IHeatmapConf, data: TPanelData, variables: ITemp
3652
const xData = _.uniq(data[x.queryID].map((d) => d[x.columnKey]));
3753
const yData = _.uniq(data[x.queryID].map((d) => d[y.columnKey]));
3854
const seriesData = data[x.queryID].map((d) => [_.get(d, x.columnKey), _.get(d, y.columnKey), _.get(d, h.columnKey)]);
39-
const borderWidth = 2;
55+
const borderWidth = calcBorderWidth(xData.length, yData.length, width, height);
4056

4157
const customOptions = {
4258
xAxis: getXAxis(conf, xData, labelFormatters.x_axis),

dashboard/src/components/plugins/viz-components/heatmap/viz-heatmap.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ function Chart({
8383
}, [handleHeatBlockClick]);
8484

8585
const option = React.useMemo(() => {
86-
return getOption(conf, data, variables);
87-
}, [conf, data]);
86+
return getOption(conf, data, variables, width, height);
87+
}, [conf, data, width, height]);
8888

8989
if (!width || !height) {
9090
return null;

0 commit comments

Comments
 (0)