22
33import defaults from '../core/core.defaults' ;
44import Element from '../core/core.element' ;
5+ import helpers from '../helpers' ;
56
67const defaultColor = defaults . global . defaultColor ;
78
@@ -48,78 +49,14 @@ function startAtGap(line, options) {
4849 }
4950}
5051
51- const methods = {
52- line : ( ctx , previous , target ) => {
53- ctx . lineTo ( target . x , target . y ) ;
54- } ,
55- stepMiddle : ( ctx , previous , target ) => {
56- const midpoint = ( previous . x + target . x ) / 2.0 ;
57- ctx . lineTo ( midpoint , previous . y ) ;
58- ctx . lineTo ( midpoint , target . y ) ;
59- ctx . lineTo ( target . x , target . y ) ;
60- } ,
61- stepMiddleR : ( ctx , previous , target ) => {
62- const midpoint = ( previous . x + target . x ) / 2.0 ;
63- ctx . lineTo ( midpoint , target . y ) ;
64- ctx . lineTo ( midpoint , previous . y ) ;
65- ctx . lineTo ( target . x , target . y ) ;
66- } ,
67- stepAfter : ( ctx , previous , target ) => {
68- ctx . lineTo ( previous . x , target . y ) ;
69- ctx . lineTo ( target . x , target . y ) ;
70- } ,
71- stepAfterR : ( ctx , previous , target ) => {
72- ctx . lineTo ( target . x , previous . y ) ;
73- ctx . lineTo ( target . x , target . y ) ;
74- } ,
75- stepBefore : ( ctx , previous , target ) => {
76- ctx . lineTo ( target . x , previous . y ) ;
77- ctx . lineTo ( target . x , target . y ) ;
78- } ,
79- stepBeforeR : ( ctx , previous , target ) => {
80- ctx . lineTo ( previous . x , target . y ) ;
81- ctx . lineTo ( target . x , target . y ) ;
82- } ,
83- bezier : ( ctx , previous , target ) => {
84- ctx . bezierCurveTo (
85- previous . controlPointNextX ,
86- previous . controlPointNextY ,
87- target . controlPointPreviousX ,
88- target . controlPointPreviousY ,
89- target . x ,
90- target . y ) ;
91- } ,
92- bezierR : ( ctx , previous , target ) => {
93- ctx . bezierCurveTo (
94- previous . controlPointPreviousX ,
95- previous . controlPointPreviousY ,
96- target . controlPointNextX ,
97- target . controlPointNextY ,
98- target . x ,
99- target . y ) ;
100- }
101- } ;
102-
103- function getLineMethod ( line , reverse ) {
104- let name = 'bezier' ;
105- if ( line . steppedLine ) {
106- const mode = line . steppedLine ;
107- if ( mode === 'middle' ) {
108- name = 'stepMiddle' ;
109- } else if ( mode === 'after' ) {
110- name = 'stepAfter' ;
111- } else {
112- name = 'stepBefore' ;
113- }
114- } else if ( ! line . tension ) {
115- name = 'line' ;
116- reverse = false ;
117- }
52+ function lineTo ( ctx , previous , target ) {
53+ ctx . lineTo ( target . x , target . y ) ;
54+ }
11855
119- if ( reverse ) {
120- name += 'R' ;
121- }
122- return methods [ name ] ;
56+ function getLineMethod ( line ) {
57+ return line . steppedLine ? helpers . canvas . _steppedLineTo
58+ : ! line . tension ? lineTo
59+ : helpers . canvas . _bezierCurveTo ;
12360}
12461
12562function pointInLine ( p1 , p2 , t ) {
@@ -247,7 +184,7 @@ function loopPath(ctx, line, options) {
247184 const points = line . _children ;
248185 const vm = line . _view ;
249186 const spanGaps = vm . spanGaps ;
250- const lineMethod = getLineMethod ( vm , reverse ) ;
187+ const lineMethod = getLineMethod ( vm ) ;
251188 const count = points . length ;
252189 const dir = reverse ? - 1 : 1 ;
253190 let closed = ! bound ;
@@ -274,7 +211,7 @@ function loopPath(ctx, line, options) {
274211 ctx . moveTo ( point . x , point . y ) ;
275212 move = false ;
276213 } else {
277- lineMethod ( ctx , prev || point , point , vm . steppedLine ) ;
214+ lineMethod ( ctx , prev || point , point , reverse , vm . steppedLine ) ;
278215 }
279216 prev = point ;
280217 }
@@ -288,7 +225,7 @@ function normalPath(ctx, line, options) {
288225 const points = line . _children ;
289226 const vm = line . _view ;
290227 const spanGaps = vm . spanGaps ;
291- const lineMethod = getLineMethod ( vm , reverse ) ;
228+ const lineMethod = getLineMethod ( vm ) ;
292229 const startIndex = bound ? lineStart ( points , bounds , reverse ) : 0 ;
293230 const count = points . length ;
294231 const num = count - startIndex ;
@@ -315,7 +252,7 @@ function normalPath(ctx, line, options) {
315252 ctx . moveTo ( point . x , point . y ) ;
316253 move = false ;
317254 } else {
318- lineMethod ( ctx , prev || point , point , vm . steppedLine ) ;
255+ lineMethod ( ctx , prev || point , point , reverse , vm . steppedLine ) ;
319256 }
320257 prev = point ;
321258 }
0 commit comments