Skip to content

Commit 8052bab

Browse files
authored
Merge pull request #1164 from merico-dev/1150-automatically-decrease-heat-blocks-border-in-heatmap
1150 automatically decrease heat blocks border in heatmap
2 parents afb3baa + e99b165 commit 8052bab

File tree

10 files changed

+42
-36
lines changed

10 files changed

+42
-36
lines changed

api/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtable/api",
3-
"version": "10.29.0",
3+
"version": "10.30.0",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

dashboard/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtable/dashboard",
3-
"version": "10.29.0",
3+
"version": "10.30.0",
44
"license": "Apache-2.0",
55
"publishConfig": {
66
"access": "public",

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

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,32 @@ import { getTooltip } from './tooltip';
88
import { getVisualMap } from './visual-map';
99
import { getXAxis } from './x-axis';
1010
import { getYAxis } from './y-axis';
11+
import _ from 'lodash';
12+
import { parseDataKey } from '~/utils/data';
1113

1214
const defaultOption = {
1315
tooltip: {
1416
confine: true,
1517
},
1618
};
1719

18-
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+
) {
1937
if (!conf.x_axis.data_key || !conf.y_axis.data_key || !conf.heat_block.data_key) {
2038
return {};
2139
}
@@ -28,10 +46,18 @@ export function getOption(conf: IHeatmapConf, data: TPanelData, variables: ITemp
2846
const labelFormatters = getLabelFormatters(conf);
2947
const valueFormatters = getValueFormatters(conf);
3048

49+
const x = parseDataKey(conf.x_axis.data_key);
50+
const y = parseDataKey(conf.y_axis.data_key);
51+
const h = parseDataKey(conf.heat_block.data_key);
52+
const xData = _.uniq(data[x.queryID].map((d) => d[x.columnKey]));
53+
const yData = _.uniq(data[x.queryID].map((d) => d[y.columnKey]));
54+
const seriesData = data[x.queryID].map((d) => [_.get(d, x.columnKey), _.get(d, y.columnKey), _.get(d, h.columnKey)]);
55+
const borderWidth = calcBorderWidth(xData.length, yData.length, width, height);
56+
3157
const customOptions = {
32-
xAxis: getXAxis(conf, data, labelFormatters.x_axis),
33-
yAxis: getYAxis(conf, data, labelFormatters.y_axis),
34-
series: getSeries(conf, data),
58+
xAxis: getXAxis(conf, xData, labelFormatters.x_axis),
59+
yAxis: getYAxis(conf, yData, labelFormatters.y_axis),
60+
series: getSeries(conf, seriesData, borderWidth),
3561
tooltip: getTooltip(conf, data, labelFormatters, valueFormatters),
3662
grid: getGrid(conf),
3763
visualMap: getVisualMap(conf, variableValueMap),

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1-
import _ from 'lodash';
2-
import { parseDataKey } from '~/utils/data';
31
import { IHeatmapConf } from '../type';
42

5-
export function getSeries(conf: IHeatmapConf, data: TPanelData) {
6-
const { x_axis, y_axis, heat_block } = conf;
7-
const x = parseDataKey(x_axis.data_key);
8-
const y = parseDataKey(y_axis.data_key);
9-
const h = parseDataKey(heat_block.data_key);
10-
11-
const seriesData = data[x.queryID].map((d) => {
12-
return [_.get(d, x.columnKey), _.get(d, y.columnKey), _.get(d, h.columnKey)];
13-
});
3+
export function getSeries(conf: IHeatmapConf, seriesData: any[], borderWidth: number) {
4+
const { heat_block } = conf;
145

156
return {
167
type: 'heatmap',
@@ -20,7 +11,7 @@ export function getSeries(conf: IHeatmapConf, data: TPanelData) {
2011
datasetIndex: 0,
2112
itemStyle: {
2213
borderColor: 'white',
23-
borderWidth: 2,
14+
borderWidth,
2415
},
2516
data: seriesData,
2617
label: heat_block.label,

dashboard/src/components/plugins/viz-components/heatmap/option/x-axis.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
import _ from 'lodash';
2-
import { parseDataKey } from '~/utils/data';
31
import { getLabelOverflowOptionOnAxis } from '../../../common-echarts-fields/axis-label-overflow';
42
import { FormatterFuncType } from '../editors/x-axis/x-axis-label-formatter/get-echarts-x-axis-tick-label';
53
import { IHeatmapConf } from '../type';
64

7-
export function getXAxis(conf: IHeatmapConf, data: TPanelData, formatterFunc: FormatterFuncType) {
8-
const x = parseDataKey(conf.x_axis.data_key);
9-
const xData = _.uniq(data[x.queryID].map((d) => d[x.columnKey]));
10-
5+
export function getXAxis(conf: IHeatmapConf, xData: any[], formatterFunc: FormatterFuncType) {
116
const { overflow, rotate } = conf.x_axis.axisLabel;
127
const overflowOption = getLabelOverflowOptionOnAxis(overflow.on_axis);
138
return {

dashboard/src/components/plugins/viz-components/heatmap/option/y-axis.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
import _ from 'lodash';
2-
import { parseDataKey } from '~/utils/data';
31
import { getLabelOverflowOptionOnAxis } from '../../../common-echarts-fields/axis-label-overflow';
42
import { FormatterFuncType } from '../editors/x-axis/x-axis-label-formatter/get-echarts-x-axis-tick-label';
53
import { IHeatmapConf } from '../type';
64

7-
export function getYAxis(conf: IHeatmapConf, data: TPanelData, formatterFunc: FormatterFuncType) {
8-
const x = parseDataKey(conf.x_axis.data_key);
9-
const y = parseDataKey(conf.y_axis.data_key);
10-
5+
export function getYAxis(conf: IHeatmapConf, yData: any[], formatterFunc: FormatterFuncType) {
116
const { nameAlignment, data_key, ...rest } = conf.y_axis;
12-
const yData = _.uniq(data[x.queryID].map((d) => d[y.columnKey]));
137

148
const { overflow, rotate } = conf.y_axis.axisLabel;
159
const overflowOption = getLabelOverflowOptionOnAxis(overflow.on_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;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtable/root",
3-
"version": "10.29.0",
3+
"version": "10.30.0",
44
"private": true,
55
"workspaces": [
66
"api",

settings-form/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtable/settings-form",
3-
"version": "10.29.0",
3+
"version": "10.30.0",
44
"license": "Apache-2.0",
55
"publishConfig": {
66
"access": "public",

website/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@devtable/website",
33
"private": true,
44
"license": "Apache-2.0",
5-
"version": "10.29.0",
5+
"version": "10.30.0",
66
"scripts": {
77
"dev": "vite",
88
"preview": "vite preview"

0 commit comments

Comments
 (0)