File tree 3 files changed +81
-6
lines changed
3 files changed +81
-6
lines changed Original file line number Diff line number Diff line change @@ -13,18 +13,30 @@ it.only('initialize & destory', () => {
13
13
width : 200 ,
14
14
height : 100 ,
15
15
percent : 0.1 ,
16
- animation : {
16
+ /* animation: {
17
17
update: {
18
18
duration: 1000,
19
19
},
20
- } ,
20
+ },*/
21
+ marker : [
22
+ {
23
+ value : 0.3 ,
24
+ /*style:{
25
+ stroke:'red',
26
+ lineWidth: 2
27
+ }*/
28
+ } ,
29
+ {
30
+ value : 0.5 ,
31
+ } ,
32
+ ] ,
21
33
} ) ;
22
34
progress . render ( ) ;
23
- window . setTimeout ( ( ) => {
35
+
36
+ /*window.setTimeout(() => {
24
37
progress.update(0.6, [{ fill: 'red' }, { fill: 'green' }]);
25
38
}, 2000);
26
-
27
- /* expect(progress).toBeInstanceOf(Progress);
39
+ expect(progress).toBeInstanceOf(Progress);
28
40
const canvas = progress.plot.get('canvas');
29
41
expect(canvas.get('width')).toBe(200);
30
42
expect(canvas.get('height')).toBe(100);
Original file line number Diff line number Diff line change
1
+ import * as _ from '@antv/util' ;
2
+ import { View , Coord } from '@antv/g2' ;
3
+ import { Group , Shape , Canvas } from '@antv/g' ;
4
+
5
+ export interface IMarker {
6
+ value : number ;
7
+ style ?: any ;
8
+ }
9
+
10
+ export default class Marker {
11
+ protected canvas : Canvas ;
12
+ protected view : View ;
13
+ protected coord : Coord ;
14
+ protected container : Group ;
15
+ protected shape : Shape ;
16
+ protected progressSize : number ;
17
+
18
+ constructor ( cfg ) {
19
+ _ . assign ( this , cfg ) ;
20
+ this . init ( ) ;
21
+ }
22
+
23
+ public clear ( ) { }
24
+
25
+ public destory ( ) { }
26
+
27
+ protected init ( ) {
28
+ this . coord = this . view . get ( 'coord' ) ;
29
+ this . container = this . view . get ( 'container' ) ;
30
+ const x = this . coord . convert ( { x : 0 , y : this . value } ) . x ; // progress坐标系是转置坐标系
31
+ const y0 = this . coord . center . y - this . progressSize / 2 - 2 ;
32
+ const y1 = this . coord . center . y + this . progressSize / 2 + 2 ;
33
+ const style = _ . deepMix ( { } , { stroke : 'grey' , lineWidth : 1 } , this . style ) ;
34
+ this . shape = this . container . addShape ( 'path' , {
35
+ attrs : {
36
+ path : [
37
+ [ 'M' , x , y0 ] ,
38
+ [ 'L' , x , y1 ] ,
39
+ ] ,
40
+ ...style ,
41
+ } ,
42
+ name : 'progress-marker' ,
43
+ } ) ;
44
+ this . canvas . draw ( ) ;
45
+ }
46
+ }
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { registerPlotType } from '../../base/global';
3
3
import { LayerConfig } from '../../base/layer' ;
4
4
import { getGeom } from '../../geoms/factory' ;
5
5
import TinyLayer , { TinyViewConfig } from '../tiny-layer' ;
6
+ import Marker from './component/marker' ;
6
7
import * as EventParser from './event' ;
7
8
8
9
export interface ProgressViewConfig extends TinyViewConfig {
@@ -31,7 +32,6 @@ export default class ProgressLayer<T extends ProgressLayerConfig = ProgressLayer
31
32
32
33
public type : string = 'progress' ;
33
34
public processProps ( ) {
34
- this . getSize ( ) ;
35
35
let props = this . options ;
36
36
props . data = this . processData ( ) ;
37
37
const cfg = {
@@ -60,6 +60,23 @@ export default class ProgressLayer<T extends ProgressLayerConfig = ProgressLayer
60
60
}
61
61
}
62
62
63
+ public afterRender ( ) {
64
+ if ( this . options . marker ) {
65
+ _ . each ( this . options . marker , ( cfg ) => {
66
+ const marker = new Marker (
67
+ _ . mix (
68
+ {
69
+ canvas : this . canvas ,
70
+ view : this . view ,
71
+ progressSize : this . options . barSize ,
72
+ } ,
73
+ cfg
74
+ )
75
+ ) ;
76
+ } ) ;
77
+ }
78
+ }
79
+
63
80
protected geometryParser ( dim : string , type : string ) : string {
64
81
if ( dim === 'g2' ) {
65
82
return G2_GEOM_MAP [ type ] ;
You can’t perform that action at this time.
0 commit comments