22import {
33 computed ,
44 defineAsyncComponent ,
5+ nextTick ,
56 onMounted ,
67 ref ,
78 toRefs ,
@@ -54,6 +55,8 @@ const svgRef = ref(null);
5455const source = ref (null );
5556const resizeObserver = ref (null );
5657const observedEl = ref (null );
58+ const isAnimating = ref (false );
59+ const raf = ref (null );
5760
5861const uid = ref (createUid ());
5962
@@ -109,18 +112,6 @@ watch(() => props.config, (_newCfg) => {
109112 prepareChart ();
110113}, { deep: true });
111114
112- watch (() => FINAL_DATASET .value , (_ ) => {
113- safeDatasetCopy .value = largestTriangleThreeBucketsArray ({
114- data: FINAL_DATASET .value ,
115- threshold: FINAL_CONFIG .value .downsample .threshold
116- }).map (v => {
117- return ! [undefined , Infinity , - Infinity , null , NaN ].includes (v) ? v : null
118- });
119-
120- animateChart ();
121- fitText (' .vue-ui-sparktrend-progress-label' , 6 );
122- }, { deep: true })
123-
124115function sanitize (arr ) {
125116 return arr .map (v => checkNaN (v))
126117}
@@ -136,9 +127,43 @@ const safeDatasetCopy = ref(largestTriangleThreeBucketsArray({
136127 }
137128}));
138129
139- const isAnimating = ref (false );
130+ watch (downsampled, (ds ) => {
131+ if (raf .value ) {
132+ cancelAnimationFrame (raf .value );
133+ raf .value = null ;
134+ }
140135
141- const raf = ref (null );
136+ if (FINAL_CONFIG .value .style .animation .show ) {
137+ safeDatasetCopy .value = Array (ds .length ).fill (null );
138+ } else {
139+ safeDatasetCopy .value = ds .map (v =>
140+ ! [undefined , Infinity , - Infinity , null ].includes (v) && ! Number .isNaN (v) ? v : null
141+ );
142+ }
143+
144+ animateChart ();
145+ nextTick (() => fitText (' .vue-ui-sparktrend-progress-label' , 6 ));
146+ }, { deep: true , immediate: true });
147+
148+ watch (
149+ () => JSON .stringify (props .dataset ),
150+ () => {
151+ if (raf .value ) {
152+ cancelAnimationFrame (raf .value );
153+ raf .value = null ;
154+ }
155+ manualLoading .value = objectIsEmpty (props .dataset );
156+
157+ const ds = downsampled .value ;
158+ safeDatasetCopy .value = FINAL_CONFIG .value .style .animation .show
159+ ? Array (ds .length ).fill (null )
160+ : ds .map (v => (Number .isFinite (v) ? v : null ));
161+
162+ animateChart ();
163+ nextTick (() => fitText (' .vue-ui-sparktrend-progress-label' , 6 ));
164+ },
165+ { deep: false , immediate: true }
166+ );
142167
143168function animateChart () {
144169 let fps = FINAL_CONFIG .value .style .animation .animationFrames ;
@@ -242,11 +267,27 @@ const drawingArea = computed(() => {
242267});
243268
244269const extremes = computed (() => {
245- const ds = sanitize (downsampled .value );
246- return {
247- max: Math .max (... ds .map (v => checkNaN (v))),
248- min: Math .min (... ds .map (v => checkNaN (v)))
270+ const ds = sanitize (downsampled .value ).filter (Number .isFinite );
271+ if (! ds .length ) return { max: 0 , min: 0 };
272+ let max = ds[0 ], min = ds[0 ];
273+ for (let i = 1 ; i < ds .length ; i++ ) {
274+ const v = ds[i];
275+ if (v > max) max = v;
276+ if (v < min) min = v;
249277 }
278+ return { max, min };
279+ });
280+
281+ const datasetKey = computed (() => {
282+ const ds = downsampled .value ;
283+ const last = ds .length ? ds[ds .length - 1 ] : ' x' ;
284+ return [
285+ uid .value ,
286+ ds .length ,
287+ Number .isFinite (last) ? last : ' x' ,
288+ FINAL_CONFIG .value .downsample .threshold ,
289+ FINAL_CONFIG .value .style .line .smooth ? ' s' : ' l'
290+ ].join (' -' );
250291});
251292
252293const absoluteMin = computed (() => {
@@ -347,7 +388,7 @@ const { fitText } = useFitSvgText({
347388
348389<template >
349390 <div ref =" sparkTrendChart" class =" vue-ui-spark-trend" :id =" uid" :style =" `width:100%;font-family:${FINAL_CONFIG.style.fontFamily};background:${FINAL_CONFIG.style.backgroundColor}`" >
350- <svg ref =" svgRef" :xmlns =" XMLNS" :viewBox =" `0 0 ${svg.width} ${svg.height}`" :style =" `width:100%;background:transparent;overflow:visible`" >
391+ <svg :key = " datasetKey " ref =" svgRef" :xmlns =" XMLNS" :viewBox =" `0 0 ${svg.width} ${svg.height}`" :style =" `width:100%;background:transparent;overflow:visible`" >
351392 <PackageVersion />
352393
353394 <!-- BACKGROUND SLOT -->
0 commit comments