@@ -36,50 +36,17 @@ type path = {
36
36
y : number ;
37
37
} ;
38
38
39
- // 处理用户自行配置 min max的情况
40
- function adjustScale ( viewScale : Scale , pathData : path [ ] , dim : string , config : renderOptions ) {
41
- const { min, max } = viewScale ;
42
- const {
43
- options : { data, xField, yField } ,
44
- } = config ;
45
- const field = dim === 'x' ? xField : yField ;
46
- const dataMin = minBy ( data , field ) [ field ] ;
47
- const dataMax = maxBy ( data , field ) [ field ] ;
48
- const minRatio = ( min - dataMin ) / ( dataMax - dataMin ) ;
49
- const maxRatio = ( max - dataMax ) / ( dataMax - dataMin ) ;
50
- const trendMin = minBy ( pathData , dim ) [ dim ] ;
51
- const trendMax = maxBy ( pathData , dim ) [ dim ] ;
52
- return {
53
- min : trendMin + minRatio * ( trendMax - trendMin ) ,
54
- max : trendMax + maxRatio * ( trendMax - trendMin ) ,
55
- } ;
56
- }
57
-
58
39
function getPath ( data : number [ ] [ ] , config : renderOptions ) {
59
40
const {
60
41
view,
61
42
options : { xField, yField } ,
62
43
} = config ;
63
- const pathData = data . map ( ( d : [ number , number ] ) => ( { x : d [ 0 ] , y : d [ 1 ] } ) ) ;
64
44
const xScaleView = view . getScaleByField ( xField ) ;
65
45
const yScaleView = view . getScaleByField ( yField ) ;
66
- const coordinate = view . getCoordinate ( ) ;
67
- const linearScale = getScale ( 'linear' ) ;
68
- const xRange = adjustScale ( xScaleView , pathData , 'x' , config ) ;
69
- const xScale = new linearScale ( {
70
- min : xRange . min ,
71
- max : xRange . max ,
72
- } ) ;
73
- const yRange = adjustScale ( yScaleView , pathData , 'y' , config ) ;
74
- const yScale = new linearScale ( {
75
- min : yRange . min ,
76
- max : yRange . max ,
77
- } ) ;
78
- const points = pathData . map ( ( d ) => ( {
79
- x : coordinate . start . x + coordinate [ 'width' ] * xScale . scale ( d . x ) ,
80
- y : coordinate . start . y - coordinate [ 'height' ] * yScale . scale ( d . y ) ,
81
- } ) ) ;
82
- return getSplinePath ( points , false ) ;
46
+ const pathData = data . map ( ( d : [ number , number ] ) =>
47
+ view . getCoordinate ( ) . convert ( { x : xScaleView . scale ( d [ 0 ] ) , y : yScaleView . scale ( d [ 1 ] ) } )
48
+ ) ;
49
+ return getSplinePath ( pathData , false ) ;
83
50
}
84
51
85
52
function renderPath ( config : renderOptions ) {
0 commit comments