@@ -170,11 +170,11 @@ function pointsFromSegments(boundary, line) {
170
170
const first = linePoints [ segment . start ] ;
171
171
const last = linePoints [ segment . end ] ;
172
172
if ( y !== null ) {
173
- points . push ( { x : first . x , y, _prop : 'x' , _ref : first } ) ;
174
- points . push ( { x : last . x , y, _prop : 'x' , _ref : last } ) ;
173
+ points . push ( { x : first . x , y} ) ;
174
+ points . push ( { x : last . x , y} ) ;
175
175
} else if ( x !== null ) {
176
- points . push ( { x, y : first . y , _prop : 'y' , _ref : first } ) ;
177
- points . push ( { x, y : last . y , _prop : 'y' , _ref : last } ) ;
176
+ points . push ( { x, y : first . y } ) ;
177
+ points . push ( { x, y : last . y } ) ;
178
178
}
179
179
} ) ;
180
180
return points ;
@@ -186,23 +186,23 @@ function pointsFromSegments(boundary, line) {
186
186
*/
187
187
function buildStackLine ( source ) {
188
188
const { chart, scale, index, line} = source ;
189
- const linesBelow = getLinesBelow ( chart , index ) ;
190
189
const points = [ ] ;
191
190
const segments = line . segments ;
192
191
const sourcePoints = line . points ;
193
- const startPoints = [ ] ;
194
- sourcePoints . forEach ( point => startPoints . push ( { x : point . x , y : scale . bottom , _prop : 'x' , _ref : point } ) ) ;
195
- linesBelow . push ( new Line ( { points : startPoints , options : { } } ) ) ;
192
+ const linesBelow = getLinesBelow ( chart , index ) ;
193
+ linesBelow . push ( createBoundaryLine ( { x : null , y : scale . bottom } , line ) ) ;
196
194
197
195
for ( let i = 0 ; i < segments . length ; i ++ ) {
198
196
const segment = segments [ i ] ;
199
197
for ( let j = segment . start ; j <= segment . end ; j ++ ) {
200
198
addPointsBelow ( points , sourcePoints [ j ] , linesBelow ) ;
201
199
}
202
200
}
203
- return new Line ( { points, options : { } , _refPoints : true } ) ;
201
+ return new Line ( { points, options : { } } ) ;
204
202
}
205
203
204
+ const isLineAndNotInHideAnimation = ( meta ) => meta . type === 'line' && ! meta . hidden ;
205
+
206
206
/**
207
207
* @param {Chart } chart
208
208
* @param {number } index
@@ -211,12 +211,13 @@ function buildStackLine(source) {
211
211
function getLinesBelow ( chart , index ) {
212
212
const below = [ ] ;
213
213
const metas = chart . getSortedVisibleDatasetMetas ( ) ;
214
+
214
215
for ( let i = 0 ; i < metas . length ; i ++ ) {
215
216
const meta = metas [ i ] ;
216
217
if ( meta . index === index ) {
217
218
break ;
218
219
}
219
- if ( meta . type === 'line' ) {
220
+ if ( isLineAndNotInHideAnimation ( meta ) ) {
220
221
below . unshift ( meta . dataset ) ;
221
222
}
222
223
}
@@ -259,22 +260,27 @@ function addPointsBelow(points, sourcePoint, linesBelow) {
259
260
* @returns {{point?: Point, first?: boolean, last?: boolean} }
260
261
*/
261
262
function findPoint ( line , sourcePoint , property ) {
263
+ const point = line . interpolate ( sourcePoint , property ) ;
264
+ if ( ! point ) {
265
+ return { } ;
266
+ }
267
+
268
+ const pointValue = point [ property ] ;
262
269
const segments = line . segments ;
263
270
const linePoints = line . points ;
271
+ let first = false ;
272
+ let last = false ;
264
273
for ( let i = 0 ; i < segments . length ; i ++ ) {
265
274
const segment = segments [ i ] ;
266
- for ( let j = segment . start ; j <= segment . end ; j ++ ) {
267
- const point = linePoints [ j ] ;
268
- if ( sourcePoint [ property ] === point [ property ] ) {
269
- return {
270
- first : j === segment . start ,
271
- last : j === segment . end ,
272
- point
273
- } ;
274
- }
275
+ const firstValue = linePoints [ segment . start ] [ property ] ;
276
+ const lastValue = linePoints [ segment . end ] [ property ] ;
277
+ if ( pointValue >= firstValue && pointValue <= lastValue ) {
278
+ first = pointValue === firstValue ;
279
+ last = pointValue === lastValue ;
280
+ break ;
275
281
}
276
282
}
277
- return { } ;
283
+ return { first , last , point } ;
278
284
}
279
285
280
286
function getTarget ( source ) {
@@ -305,23 +311,20 @@ function getTarget(source) {
305
311
function createBoundaryLine ( boundary , line ) {
306
312
let points = [ ] ;
307
313
let _loop = false ;
308
- let _refPoints = false ;
309
314
310
315
if ( isArray ( boundary ) ) {
311
316
_loop = true ;
312
317
// @ts -ignore
313
318
points = boundary ;
314
319
} else {
315
320
points = pointsFromSegments ( boundary , line ) ;
316
- _refPoints = true ;
317
321
}
318
322
319
323
return points . length ? new Line ( {
320
324
points,
321
325
options : { tension : 0 } ,
322
326
_loop,
323
- _fullLoop : _loop ,
324
- _refPoints
327
+ _fullLoop : _loop
325
328
} ) : null ;
326
329
}
327
330
@@ -392,17 +395,6 @@ function _segments(line, target, property) {
392
395
const tpoints = target . points ;
393
396
const parts = [ ] ;
394
397
395
- if ( target . _refPoints ) {
396
- // Update properties from reference points. (In case those points are animating)
397
- for ( let i = 0 , ilen = tpoints . length ; i < ilen ; ++ i ) {
398
- const point = tpoints [ i ] ;
399
- const prop = point . _prop ;
400
- if ( prop ) {
401
- point [ prop ] = point . _ref [ prop ] ;
402
- }
403
- }
404
- }
405
-
406
398
for ( let i = 0 ; i < segments . length ; i ++ ) {
407
399
const segment = segments [ i ] ;
408
400
const bounds = getBounds ( property , points [ segment . start ] , points [ segment . end ] , segment . loop ) ;
@@ -464,7 +456,7 @@ function interpolatedLineTo(ctx, target, point, property) {
464
456
465
457
function _fill ( ctx , cfg ) {
466
458
const { line, target, property, color, scale} = cfg ;
467
- const segments = _segments ( cfg . line , cfg . target , property ) ;
459
+ const segments = _segments ( line , target , property ) ;
468
460
469
461
ctx . fillStyle = color ;
470
462
for ( let i = 0 , ilen = segments . length ; i < ilen ; ++ i ) {
@@ -535,8 +527,7 @@ export default {
535
527
fill : decodeFill ( line , i , count ) ,
536
528
chart,
537
529
scale : meta . vScale ,
538
- line,
539
- target : undefined
530
+ line
540
531
} ;
541
532
}
542
533
@@ -551,7 +542,6 @@ export default {
551
542
}
552
543
553
544
source . fill = resolveTarget ( sources , i , propagate ) ;
554
- source . target = source . fill !== false && getTarget ( source ) ;
555
545
}
556
546
} ,
557
547
@@ -572,13 +562,14 @@ export default {
572
562
beforeDatasetDraw ( chart , args ) {
573
563
const area = chart . chartArea ;
574
564
const ctx = chart . ctx ;
575
- const meta = args . meta . $filler ;
565
+ const source = args . meta . $filler ;
576
566
577
- if ( ! meta || meta . fill === false ) {
567
+ if ( ! source || source . fill === false ) {
578
568
return ;
579
569
}
580
570
581
- const { line, target, scale} = meta ;
571
+ const target = getTarget ( source ) ;
572
+ const { line, scale} = source ;
582
573
const lineOpts = line . options ;
583
574
const fillOption = lineOpts . fill ;
584
575
const color = lineOpts . backgroundColor ;
0 commit comments