@@ -15,45 +15,46 @@ import {
1515import {
1616 abbreviate ,
1717 adaptColorToBackground ,
18- assignStackRatios ,
1918 applyDataLabel ,
19+ assignStackRatios ,
20+ buildDisplayedTimeLabels ,
21+ buildInterLineAreas ,
2022 calcLinearProgression ,
2123 calculateNiceScale ,
2224 calculateNiceScaleWithExactExtremes ,
2325 checkNaN ,
2426 convertColorToHex ,
2527 convertCustomPalette ,
2628 createCsvContent ,
29+ createIndividualArea ,
30+ createIndividualAreaWithCuts ,
2731 createPolygonPath ,
32+ createSmoothAreaSegments ,
2833 createSmoothPath ,
29- createStraightPath ,
34+ createSmoothPathWithCuts ,
3035 createStar ,
36+ createStraightPath ,
37+ createStraightPathWithCuts ,
3138 createTSpans ,
3239 createTSpansFromLineBreaksOnX ,
3340 createUid ,
3441 dataLabel ,
3542 downloadCsv ,
43+ error ,
3644 forceValidValue ,
3745 functionReturnsString ,
3846 hasDeepProperty ,
3947 isFunction ,
4048 isSafeValue ,
4149 largestTriangleThreeBucketsArray ,
50+ objectIsEmpty ,
4251 palette ,
4352 placeXYTag ,
4453 setOpacity ,
4554 shiftHue ,
46- error ,
47- objectIsEmpty ,
4855 themePalettes ,
4956 translateSize ,
50- createSmoothPathWithCuts ,
51- createStraightPathWithCuts ,
52- createIndividualAreaWithCuts ,
53- createSmoothAreaSegments ,
54- createIndividualArea ,
5557 treeShake ,
56- buildInterLineAreas ,
5758} from ' ../lib' ;
5859import { throttle } from ' ../canvas-lib.js' ;
5960import { useConfig } from ' ../useConfig' ;
@@ -849,91 +850,6 @@ const modulo = computed(() => {
849850 return Math .min (m, [... new Set (timeLabels .value .map (t => t .text ))].length );
850851});
851852
852- function memoizeDisplayedTimeLabels (fn ) {
853- let prevKey = null ;
854- let prevVal = null ;
855- return (... args ) => {
856- const key = JSON .stringify (args);
857- if (key === prevKey) return prevVal;
858- prevKey = key;
859- prevVal = fn (... args);
860- return prevVal;
861- };
862- }
863-
864- const _buildDisplayedTimeLabels = memoizeDisplayedTimeLabels ((
865- showOnlyFirstAndLast,
866- showOnlyAtModulo,
867- moduloBase,
868- visTexts,
869- allTexts,
870- startAbs,
871- selIdx,
872- maxSeriesCount
873- ) => {
874- if (showOnlyFirstAndLast) {
875- if (visTexts .length <= 2 ) {
876- return visTexts .map ((t , i ) => ({ text: t, absoluteIndex: i }));
877- }
878- const out = visTexts .map ((t , i ) => {
879- const keep = (i === 0 ) || (i === visTexts .length - 1 ) || (selIdx != null && i === selIdx);
880- return { text: keep ? t : ' ' , absoluteIndex: i };
881- });
882- return out;
883- }
884-
885- if (! showOnlyAtModulo) {
886- return visTexts .map ((t , i ) => ({ text: t, absoluteIndex: i }));
887- }
888-
889- const mod = Math .max (1 , moduloBase || 1 );
890- if (maxSeriesCount <= mod) {
891- return visTexts .map ((t , i ) => ({ text: t, absoluteIndex: i }));
892- }
893-
894- const candidates = [];
895- for (let i = 0 ; i < visTexts .length ; i += 1 ) {
896- const cur = visTexts[i] ?? ' ' ;
897- if (! cur) continue ;
898- const prevAbs = startAbs + i - 1 >= 0 ? (allTexts[startAbs + i - 1 ] ?? ' ' ) : null ;
899- if (cur !== prevAbs) candidates .push (i);
900- }
901-
902- if (! candidates .length ) {
903- return visTexts .map ((_t , i ) => ({ text: ' ' , absoluteIndex: i }));
904- }
905-
906- const C = candidates .length ;
907- const base = mod;
908- const minK = Math .max (2 , Math .min (base - 3 , C ));
909- const maxK = Math .min (C , base + 3 );
910-
911- let bestK = Math .min (base, C );
912- let bestScore = Infinity ;
913-
914- for (let k = minK; k <= maxK; k += 1 ) {
915- const remainder = (C - 1 ) % (k - 1 );
916- const drift = Math .abs (k - base);
917- const score = remainder * 10 + drift;
918- if (score < bestScore) { bestScore = score; bestK = k; }
919- }
920-
921- const picked = new Set ();
922- if (bestK <= 1 ) {
923- picked .add (candidates[Math .round ((C - 1 ) / 2 )]);
924- } else {
925- const step = (C - 1 ) / (bestK - 1 );
926- for (let j = 0 ; j < bestK; j += 1 ) {
927- picked .add (candidates[Math .round (j * step)]);
928- }
929- }
930-
931- return visTexts .map ((t , i ) => ({
932- text: picked .has (i) ? t : ' ' ,
933- absoluteIndex: i
934- }));
935- });
936-
937853const displayedTimeLabels = computed (() => {
938854 const cfg = FINAL_CONFIG .value .chart .grid .labels .xAxisLabels ;
939855 const vis = timeLabels .value || [];
@@ -944,7 +860,7 @@ const displayedTimeLabels = computed(() => {
944860 const visTexts = vis .map (l => l? .text ?? ' ' );
945861 const allTexts = all .map (l => l? .text ?? ' ' );
946862
947- return _buildDisplayedTimeLabels (
863+ return buildDisplayedTimeLabels (
948864 !! cfg .showOnlyFirstAndLast ,
949865 !! cfg .showOnlyAtModulo ,
950866 Math .max (1 , modulo .value || 1 ),
@@ -2208,54 +2124,6 @@ const preciseAllTimeLabels = computed(() => {
22082124 text: preciseTimeFormatter .value (i, FINAL_CONFIG .value .chart .zoom .timeFormat ),
22092125 absoluteIndex: i
22102126 }))
2211- })
2212-
2213- // Simple Slicer labels
2214- const useSlicerCustomFormat = ref (false );
2215-
2216- const slicerLabels = computed (() => {
2217- let left = ' ' , right = ' ' ;
2218- if (FINAL_CONFIG .value .chart .zoom .preview .enable ) {
2219- return { left, right };
2220- }
2221- useSlicerCustomFormat .value = false ;
2222- const customFormat = FINAL_CONFIG .value .chart .zoom .customFormat ;
2223- if (isFunction (customFormat)) {
2224- try {
2225- const customLeft = customFormat ({
2226- absoluteIndex: slicer .value .start ,
2227- seriesIndex: slicer .value .start ,
2228- datapoint: selectedSeries .value
2229- });
2230- const customRight = customFormat ({
2231- absoluteIndex: slicer .value .end - 1 ,
2232- seriesIndex: slicer .value .end - 1 ,
2233- datapoint: selectedSeries .value
2234- });
2235- if (typeof customLeft === ' string' && typeof customRight === ' string' ) {
2236- left = customLeft;
2237- right = customRight;
2238- useSlicerCustomFormat .value = true ;
2239- }
2240- } catch (err) {
2241- console .warn (' Custom format cannot be applied on zoom labels.' );
2242- useSlicerCustomFormat .value = false ;
2243- }
2244- }
2245-
2246- if (! useSlicerCustomFormat .value ) {
2247- left = FINAL_CONFIG .value .chart .grid .labels .xAxisLabels .datetimeFormatter .enable && ! FINAL_CONFIG .value .chart .zoom .useDefaultFormat
2248- ? (preciseAllTimeLabels .value [slicer .value .start ]? .text || ' ' )
2249- : (timeLabels .value [0 ]? .text || ' ' );
2250-
2251- const endAbs = Math .max (slicer .value .start , slicer .value .end - 1 )
2252-
2253- right = FINAL_CONFIG .value .chart .grid .labels .xAxisLabels .datetimeFormatter .enable && ! FINAL_CONFIG .value .chart .zoom .useDefaultFormat
2254- ? (preciseAllTimeLabels .value [endAbs]? .text || ' ' )
2255- : (timeLabels .value .at (- 1 )? .text || ' ' )
2256- }
2257-
2258- return { left, right };
22592127});
22602128
22612129const tooltipContent = computed (() => {
@@ -4267,52 +4135,54 @@ defineExpose({
42674135
42684136 < SlicerPreview
42694137 ref= " chartSlicer"
4270- v- if = " FINAL_CONFIG.chart.zoom.show && maxX > 6 && isDataset && slicerReady"
4271- : immediate= " !FINAL_CONFIG.chart.zoom.preview.enable"
4272- : max= " maxX"
4273- : min= " 0"
4274- : valueStart= " slicer.start"
4275- : valueEnd= " slicer.end"
4276- : start= " slicer.start"
4277- : end= " slicer.end"
4278- @update: start= " onSlicerStart"
4279- @update: end= " onSlicerEnd"
4280- : selectedSeries= " selectedSeries"
4281- : customFormat= " FINAL_CONFIG.chart.zoom.customFormat"
4138+ v- if = " FINAL_CONFIG.chart.zoom.show && maxX > 6 && isDataset && slicerReady"
4139+ : allMinimaps= " allMinimaps"
42824140 : background= " FINAL_CONFIG.chart.zoom.color"
4141+ : borderColor= " FINAL_CONFIG.chart.backgroundColor"
4142+ : customFormat= " FINAL_CONFIG.chart.zoom.customFormat"
4143+ : cutNullValues= " FINAL_CONFIG.line.cutNullValues"
4144+ : enableRangeHandles= " FINAL_CONFIG.chart.zoom.enableRangeHandles"
4145+ : enableSelectionDrag= " FINAL_CONFIG.chart.zoom.enableSelectionDrag"
4146+ : end= " slicer.end"
4147+ : focusOnDrag= " FINAL_CONFIG.chart.zoom.focusOnDrag"
4148+ : focusRangeRatio= " FINAL_CONFIG.chart.zoom.focusRangeRatio"
42834149 : fontSize= " FINAL_CONFIG.chart.zoom.fontSize" : useResetSlot= " FINAL_CONFIG.chart.zoom.useResetSlot"
4150+ : immediate= " !FINAL_CONFIG.chart.zoom.preview.enable"
4151+ : inputColor= " FINAL_CONFIG.chart.zoom.color"
4152+ : isPreview= " isPrecog"
42844153 : labelLeft= " timeLabels[0]? timeLabels[0].text : ''"
42854154 : labelRight= " timeLabels.at(-1) ? timeLabels.at(-1).text : ''"
4286- : textColor= " FINAL_CONFIG.chart.color"
4287- : usePreciseLabels= " FINAL_CONFIG.chart.grid.labels.xAxisLabels.datetimeFormatter.enable && !FINAL_CONFIG.chart.zoom.useDefaultFormat"
4288- : preciseLabels= " preciseAllTimeLabels"
4289- : inputColor= " FINAL_CONFIG.chart.zoom.color" : selectColor= " FINAL_CONFIG.chart.zoom.highlightColor"
4290- : borderColor= " FINAL_CONFIG.chart.backgroundColor" : minimap= " minimap"
4291- : smoothMinimap= " FINAL_CONFIG.chart.zoom.minimap.smooth"
4292- : minimapSelectedColor= " FINAL_CONFIG.chart.zoom.minimap.selectedColor"
4293- : minimapSelectionRadius= " FINAL_CONFIG.chart.zoom.minimap.selectionRadius"
4155+ : max= " maxX"
4156+ : min= " 0"
4157+ : minimap= " minimap"
4158+ : minimapCompact= " FINAL_CONFIG.chart.zoom.minimap.compact"
4159+ : minimapFrameColor= " FINAL_CONFIG.chart.zoom.minimap.frameColor"
4160+ : minimapIndicatorColor= " FINAL_CONFIG.chart.zoom.minimap.indicatorColor"
42944161 : minimapLineColor= " FINAL_CONFIG.chart.zoom.minimap.lineColor"
4162+ : minimapMerged= " FINAL_CONFIG.chart.zoom.minimap.merged"
4163+ : minimapSelectedColor= " FINAL_CONFIG.chart.zoom.minimap.selectedColor"
42954164 : minimapSelectedColorOpacity= " FINAL_CONFIG.chart.zoom.minimap.selectedColorOpacity"
42964165 : minimapSelectedIndex= " selectedSerieIndex"
4297- : minimapIndicatorColor= " FINAL_CONFIG.chart.zoom.minimap.indicatorColor"
4298- : verticalHandles= " FINAL_CONFIG.chart.zoom.minimap.verticalHandles"
4299- : refreshStartPoint= " FINAL_CONFIG.chart.zoom.startIndex !== null ? FINAL_CONFIG.chart.zoom.startIndex : 0"
4166+ : minimapSelectionRadius= " FINAL_CONFIG.chart.zoom.minimap.selectionRadius"
4167+ : preciseLabels= " preciseAllTimeLabels.length ? preciseAllTimeLabels : allTimeLabels"
43004168 : refreshEndPoint= " FINAL_CONFIG.chart.zoom.endIndex !== null ? FINAL_CONFIG.chart.zoom.endIndex + 1 : Math.max(...dataset.map(datapoint => lttb(datapoint.series).length))"
4301- : enableRangeHandles= " FINAL_CONFIG.chart.zoom.enableRangeHandles"
4302- : enableSelectionDrag= " FINAL_CONFIG.chart.zoom.enableSelectionDrag"
4303- : minimapCompact= " FINAL_CONFIG.chart.zoom.minimap.compact"
4304- : allMinimaps= " allMinimaps"
4305- : minimapMerged= " FINAL_CONFIG.chart.zoom.minimap.merged"
4306- : minimapFrameColor= " FINAL_CONFIG.chart.zoom.minimap.frameColor"
4307- : cutNullValues= " FINAL_CONFIG.line.cutNullValues"
4308- : focusOnDrag= " FINAL_CONFIG.chart.zoom.focusOnDrag"
4309- : focusRangeRatio= " FINAL_CONFIG.chart.zoom.focusRangeRatio"
4169+ : refreshStartPoint= " FINAL_CONFIG.chart.zoom.startIndex !== null ? FINAL_CONFIG.chart.zoom.startIndex : 0"
4170+ : selectColor= " FINAL_CONFIG.chart.zoom.highlightColor"
4171+ : selectedSeries= " selectedSeries"
4172+ : smoothMinimap= " FINAL_CONFIG.chart.zoom.minimap.smooth"
4173+ : start= " slicer.start"
4174+ : textColor= " FINAL_CONFIG.chart.color"
4175+ : timeLabels= " allTimeLabels"
4176+ : usePreciseLabels= " FINAL_CONFIG.chart.grid.labels.xAxisLabels.datetimeFormatter.enable && !FINAL_CONFIG.chart.zoom.useDefaultFormat"
4177+ : valueEnd= " slicer.end"
4178+ : valueStart= " slicer.start"
4179+ : verticalHandles= " FINAL_CONFIG.chart.zoom.minimap.verticalHandles"
4180+ @futureEnd= " v => setPrecog('end', v)"
4181+ @futureStart= " v => setPrecog('start', v)"
43104182 @reset= " refreshSlicer"
43114183 @trapMouse= " selectMinimapIndex"
4312- @futureStart= " v => setPrecog('start', v)"
4313- @futureEnd= " v => setPrecog('end', v)"
4314- : timeLabels= " allTimeLabels"
4315- : isPreview= " isPrecog"
4184+ @update: end= " onSlicerEnd"
4185+ @update: start= " onSlicerStart"
43164186 >
43174187 < template #reset- action= " { reset }" >
43184188 < slot name= " reset-action" v- bind= " { reset }" / >
0 commit comments