@@ -10,6 +10,7 @@ import defaults from '../core/core.defaults';
1010import Line , { _boundSegment , _boundSegments } from '../elements/element.line' ;
1111import { clipArea , unclipArea } from '../helpers/helpers.canvas' ;
1212import { valueOrDefault , isFinite , isArray , extend } from '../helpers/helpers.core' ;
13+ import { _normalizeAngle } from '../helpers/helpers.math' ;
1314
1415
1516defaults . _set ( 'global' , {
@@ -239,7 +240,6 @@ function _clip(ctx, target, clipY) {
239240 ctx . clip ( ) ;
240241}
241242
242- const TAU = Math . PI * 2 ;
243243function getBounds ( property , first , last , loop ) {
244244 if ( loop ) {
245245 return ;
@@ -248,12 +248,19 @@ function getBounds(property, first, last, loop) {
248248 let end = last [ property ] ;
249249
250250 if ( property === 'angle' ) {
251- start = ( start + TAU ) % TAU ;
252- end = ( end + TAU ) % TAU ;
251+ start = _normalizeAngle ( start ) ;
252+ end = _normalizeAngle ( end ) ;
253253 }
254254 return { property, start, end} ;
255255}
256256
257+ function _getEdge ( a , b , prop , fn ) {
258+ if ( a && b ) {
259+ return fn ( a [ prop ] , b [ prop ] ) ;
260+ }
261+ return a ? a [ prop ] : b ? b [ prop ] : 0 ;
262+ }
263+
257264function _segments ( line , target , property ) {
258265 const points = line . points ;
259266 const tpoints = target . points ;
@@ -265,18 +272,34 @@ function _segments(line, target, property) {
265272 if ( ! target . segments ) {
266273 // Special case for boundary not supporting `segments` (simpleArc)
267274 // Bounds are provided as `target` for partial circle, or undefined for full circle
268- parts . push ( { source : segment , target : bounds } ) ;
275+ parts . push ( {
276+ source : segment ,
277+ target : bounds ,
278+ start : points [ segment . start ] ,
279+ end : points [ segment . end ]
280+ } ) ;
269281 continue ;
270282 }
271283
272284 // Get all segments from `target` that intersect the bounds of current segment of `line`
273285 const subs = _boundSegments ( target , bounds ) ;
274286
275287 for ( let sub of subs ) {
276- const fillSources = _boundSegment ( segment , points , getBounds ( property , tpoints [ sub . start ] , tpoints [ sub . end ] , sub . loop ) ) ;
288+ const subBounds = getBounds ( property , tpoints [ sub . start ] , tpoints [ sub . end ] , sub . loop ) ;
289+ const fillSources = _boundSegment ( segment , points , subBounds ) ;
277290
278291 for ( let source of fillSources ) {
279- parts . push ( { source, target : sub } ) ;
292+ parts . push ( {
293+ source,
294+ target : sub ,
295+ start : {
296+ [ property ] : _getEdge ( bounds , subBounds , 'start' , Math . max )
297+ } ,
298+ end : {
299+ [ property ] : _getEdge ( bounds , subBounds , 'end' , Math . min )
300+ }
301+
302+ } ) ;
280303 }
281304 }
282305 }
@@ -303,30 +326,27 @@ function interpolatedLineTo(ctx, target, point, property) {
303326function _fill ( ctx , cfg ) {
304327 const { line, target, property, color, scale} = cfg ;
305328 const segments = _segments ( cfg . line , cfg . target , property ) ;
306- const points = line . points ;
307329
308330 ctx . fillStyle = color ;
309331 for ( let i = 0 , ilen = segments . length ; i < ilen ; ++ i ) {
310- const { source : src , target : tgt } = segments [ i ] ;
311- const first = points [ src . start ] ;
312- const last = points [ src . end ] ;
332+ const { source : src , target : tgt , start, end} = segments [ i ] ;
313333
314334 ctx . save ( ) ;
315335
316- clipBounds ( ctx , scale , getBounds ( property , first , last ) ) ;
336+ clipBounds ( ctx , scale , getBounds ( property , start , end ) ) ;
317337
318338 ctx . beginPath ( ) ;
319339
320340 let loop = ! ! line . pathSegment ( ctx , src ) ;
321341 if ( loop ) {
322342 ctx . closePath ( ) ;
323343 } else {
324- interpolatedLineTo ( ctx , target , last , property ) ;
344+ interpolatedLineTo ( ctx , target , end , property ) ;
325345 }
326346
327347 loop &= target . pathSegment ( ctx , tgt , { move : loop , reverse : true } ) ;
328348 if ( ! loop ) {
329- interpolatedLineTo ( ctx , target , first , property ) ;
349+ interpolatedLineTo ( ctx , target , start , property ) ;
330350 }
331351
332352 ctx . closePath ( ) ;
0 commit comments