@@ -8,14 +8,32 @@ import { getTooltip } from './tooltip';
8
8
import { getVisualMap } from './visual-map' ;
9
9
import { getXAxis } from './x-axis' ;
10
10
import { getYAxis } from './y-axis' ;
11
+ import _ from 'lodash' ;
12
+ import { parseDataKey } from '~/utils/data' ;
11
13
12
14
const defaultOption = {
13
15
tooltip : {
14
16
confine : true ,
15
17
} ,
16
18
} ;
17
19
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
+ ) {
19
37
if ( ! conf . x_axis . data_key || ! conf . y_axis . data_key || ! conf . heat_block . data_key ) {
20
38
return { } ;
21
39
}
@@ -28,10 +46,18 @@ export function getOption(conf: IHeatmapConf, data: TPanelData, variables: ITemp
28
46
const labelFormatters = getLabelFormatters ( conf ) ;
29
47
const valueFormatters = getValueFormatters ( conf ) ;
30
48
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
+
31
57
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 ) ,
35
61
tooltip : getTooltip ( conf , data , labelFormatters , valueFormatters ) ,
36
62
grid : getGrid ( conf ) ,
37
63
visualMap : getVisualMap ( conf , variableValueMap ) ,
0 commit comments