File tree 7 files changed +127
-1
lines changed
__tests__/unit/plots/area
7 files changed +127
-1
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,40 @@ describe('area', () => {
18
18
expect ( area . chart . geometries [ 0 ] . elements . length ) . toBe ( 1 ) ;
19
19
} ) ;
20
20
21
+ it ( 'x cat scale' , ( ) => {
22
+ const data = [
23
+ { x : 1 , y : 1 } ,
24
+ { x : 2 , y : 4 } ,
25
+ { x : 3 , y : 5 } ,
26
+ { x : 4 , y : 2 } ,
27
+ ] ;
28
+ const area = new Area ( createDiv ( ) , {
29
+ width : 400 ,
30
+ height : 300 ,
31
+ appendPadding : 10 ,
32
+ data : data ,
33
+ xField : 'x' ,
34
+ yField : 'y' ,
35
+ } ) ;
36
+
37
+ area . render ( ) ;
38
+
39
+ expect ( area . options . meta . x . type ) . toBe ( 'cat' ) ;
40
+ expect ( area . chart . getScaleByField ( 'x' ) . range ) . toEqual ( [ 0 , 1 ] ) ;
41
+ area . update ( {
42
+ ...area . options ,
43
+ meta : {
44
+ x : {
45
+ type : 'linear' ,
46
+ range : [ 0.1 , 0.9 ] ,
47
+ } ,
48
+ } ,
49
+ } ) ;
50
+
51
+ expect ( area . options . meta . x . type ) . toBe ( 'linear' ) ;
52
+ expect ( area . chart . getScaleByField ( 'x' ) . range ) . toEqual ( [ 0.1 , 0.9 ] ) ;
53
+ } ) ;
54
+
21
55
it ( 'x*y with color' , ( ) => {
22
56
const area = new Area ( createDiv ( ) , {
23
57
width : 400 ,
Original file line number Diff line number Diff line change
1
+ import { Area } from '@antv/g2plot' ;
2
+
3
+ fetch ( 'https://gw.alipayobjects.com/os/bmw-prod/1d565782-dde4-4bb6-8946-ea6a38ccf184.json' )
4
+ . then ( ( res ) => res . json ( ) )
5
+ . then ( ( data ) => {
6
+ const area = new Area ( 'container' , {
7
+ data,
8
+ xField : 'Date' ,
9
+ yField : 'scales' ,
10
+ xAxis : {
11
+ type : 'dateTime' ,
12
+ tickCount : 5 ,
13
+ } ,
14
+ areaStyle : ( ) => {
15
+ return {
16
+ fill : 'l(270) 0:#ffffff 0.5:#7ec2f3 1:#1890ff' ,
17
+ } ;
18
+ } ,
19
+ } ) ;
20
+ area . render ( ) ;
21
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { Area } from '@antv/g2plot' ;
2
+
3
+ fetch ( 'https://gw.alipayobjects.com/os/bmw-prod/1d565782-dde4-4bb6-8946-ea6a38ccf184.json' )
4
+ . then ( ( res ) => res . json ( ) )
5
+ . then ( ( data ) => {
6
+ const area = new Area ( 'container' , {
7
+ data,
8
+ xField : 'Date' ,
9
+ yField : 'scales' ,
10
+ xAxis : {
11
+ type : 'dateTime' ,
12
+ tickCount : 5 ,
13
+ } ,
14
+ slider : {
15
+ min : 0.1 ,
16
+ max : 0.9 ,
17
+ trendCfg : {
18
+ isArea : true ,
19
+ } ,
20
+ } ,
21
+ } ) ;
22
+ area . render ( ) ;
23
+ } ) ;
Original file line number Diff line number Diff line change 11
11
"en" : " basic Area chart"
12
12
},
13
13
"screenshot" : " https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*aARCQbtAl4AAAAAAAAAAAABkARQnAQ"
14
+ },
15
+ {
16
+ "filename" : " basic-gradients.ts" ,
17
+ "title" : {
18
+ "zh" : " 渐变色面积图" ,
19
+ "en" : " gradients Area chart"
20
+ },
21
+ "screenshot" : " https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*aARCQbtAl4AAAAAAAAAAAABkARQnAQ"
22
+ },
23
+ {
24
+ "filename" : " basic-slider.ts" ,
25
+ "title" : {
26
+ "zh" : " 缩略轴面积图" ,
27
+ "en" : " slider Area chart"
28
+ },
29
+ "screenshot" : " https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*aARCQbtAl4AAAAAAAAAAAABkARQnAQ"
14
30
}
15
31
]
16
32
}
Original file line number Diff line number Diff line change
1
+ import { Area } from '@antv/g2plot' ;
2
+
3
+ fetch ( 'https://gw.alipayobjects.com/os/bmw-prod/b21e7336-0b3e-486c-9070-612ede49284e.json' )
4
+ . then ( ( res ) => res . json ( ) )
5
+ . then ( ( data ) => {
6
+ const area = new Area ( 'container' , {
7
+ data,
8
+ xField : 'date' ,
9
+ yField : 'value' ,
10
+ seriesField : 'country' ,
11
+ slider : {
12
+ min : 0.1 ,
13
+ max : 0.9 ,
14
+ } ,
15
+ } ) ;
16
+ area . render ( ) ;
17
+ } ) ;
Original file line number Diff line number Diff line change 19
19
"en" : " The causes of CO2 emissions"
20
20
},
21
21
"screenshot" : " https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*u6u1RqMG9coAAAAAAAAAAABkARQnAQ"
22
+ },
23
+ {
24
+ "filename" : " basic-slider.ts" ,
25
+ "title" : {
26
+ "zh" : " 带缩略轴堆叠面积图" ,
27
+ "en" : " StackedArea with slider"
28
+ },
29
+ "screenshot" : " https://gw.alipayobjects.com/mdn/rms_d314dd/afts/img/A*u6u1RqMG9coAAAAAAAAAAABkARQnAQ"
22
30
}
23
31
]
24
32
}
Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ export class Area extends Plot<AreaOptions> {
13
13
/**
14
14
* 获取 折线图 默认配置
15
15
*/
16
- protected getDefaultOptions ( ) {
16
+ protected getDefaultOptions ( options : AreaOptions ) {
17
+ const { xField } = options ;
17
18
return deepMix ( { } , super . getDefaultOptions ( ) , {
18
19
tooltip : {
19
20
showMarkers : true ,
@@ -22,6 +23,12 @@ export class Area extends Plot<AreaOptions> {
22
23
type : 'x' ,
23
24
} ,
24
25
} ,
26
+ meta : {
27
+ [ xField ] : {
28
+ type : 'cat' ,
29
+ range : [ 0 , 1 ] ,
30
+ } ,
31
+ } ,
25
32
} ) ;
26
33
}
27
34
You can’t perform that action at this time.
0 commit comments