@@ -280,52 +280,80 @@ onBeforeUnmount(() => {
280
280
if (resizeObserver .value ) resizeObserver .value .disconnect ();
281
281
});
282
282
283
+ const absLen = computed (() => Math .max (1 , props .max - props .min ));
284
+ const miniLen = computed (() => Math .max (1 , props .minimap .length ));
285
+ const scaleAbsToMini = computed (() => miniLen .value / absLen .value );
286
+
287
+ function absToMiniStart (i ) {
288
+ const v = Math .floor ((i - props .min ) * scaleAbsToMini .value );
289
+ return Math .min (Math .max (0 , v), miniLen .value );
290
+ }
291
+
292
+ function absToMiniEnd (i ) {
293
+ const v = Math .ceil ((i - props .min ) * scaleAbsToMini .value );
294
+ return Math .min (Math .max (0 , v), miniLen .value );
295
+ }
296
+
297
+ const startMini = computed (() => absToMiniStart (startValue .value ));
298
+ const endMini = computed (() => absToMiniEnd (endValue .value ));
299
+
283
300
const unitWidthX = computed (() => {
284
301
if (! props .minimap .length ) return 0 ;
285
302
return svgMinimap .value .width / props .minimap .length ;
286
303
});
287
304
288
305
const minimapLine = computed (() => {
289
- if (! props .minimap .length ) return [];
306
+ if (! props .minimap .length ) return [];
290
307
const max = Math .max (... props .minimap );
291
308
const min = Math .min (... props .minimap ) - 10 ;
292
309
const diff = max - (min > 0 ? 0 : min);
293
- const points = props .minimap .map ((dp , i ) => {
294
- const normalizedVal = dp - min;
295
- return {
296
- x: svgMinimap .value .width / (props .minimap .length ) * (i) + (unitWidthX .value / 2 ),
297
- y: svgMinimap .value .height - (normalizedVal / diff * (svgMinimap .value .height * 0.9 ))
298
- };
299
- });
310
+
311
+ const points = props .minimap .map ((dp , i ) => ({
312
+ x: (svgMinimap .value .width / props .minimap .length ) * i + (unitWidthX .value / 2 ),
313
+ y: svgMinimap .value .height - ((dp - min) / diff) * (svgMinimap .value .height * 0.9 ),
314
+ }));
315
+
316
+ const s = startMini .value ;
317
+ const e = Math .max (s + 1 , endMini .value );
318
+
300
319
const fullSet = props .smoothMinimap ? createSmoothPath (points) : createStraightPath (points);
301
- const sliced = [ ... points] .slice (props . valueStart , props . valueEnd );
320
+ const sliced = points .slice (s, e );
302
321
const selectionSet = props .smoothMinimap ? createSmoothPath (sliced) : createStraightPath (sliced);
322
+
303
323
return {
304
324
fullSet,
305
325
selectionSet,
306
326
sliced,
307
- firstPlot: points[props . valueStart ],
308
- lastPlot: points[props . valueEnd - 1 ]
327
+ firstPlot: points[s ],
328
+ lastPlot: points[Math . max ( 0 , e - 1 )],
309
329
};
310
330
});
311
331
312
332
const selectionRectCoordinates = computed (() => {
333
+ const s = startMini .value ;
334
+ const e = Math .max (s + 1 , endMini .value );
313
335
return {
314
- x: unitWidthX .value * startValue . value + (unitWidthX .value / 2 ),
315
- width: svgMinimap .value . width * (( endValue . value - startValue . value ) / props . max ) - unitWidthX .value
336
+ x: unitWidthX .value * s + (unitWidthX .value / 2 ),
337
+ width: unitWidthX .value * (e - s) - unitWidthX .value ,
316
338
};
317
339
});
318
340
319
341
const selectedTrap = ref (props .minimapSelectedIndex );
320
342
321
343
watch (() => props .minimapSelectedIndex , (v ) => {
322
- selectedTrap .value = v + props .valueStart ;
344
+ if ([null , undefined ].includes (v)) {
345
+ selectedTrap .value = null ;
346
+ return ;
347
+ }
348
+ selectedTrap .value = absToMiniStart (props .valueStart ) + v;
323
349
}, { immediate: true });
324
350
325
351
function trapMouse (trap ) {
326
352
selectedTrap .value = trap;
327
- if (trap >= props .valueStart && trap < props .valueEnd ) {
328
- emit (' trapMouse' , trap - props .valueStart );
353
+ const s = startMini .value ;
354
+ const e = endMini .value ;
355
+ if (trap >= s && trap < e) {
356
+ emit (' trapMouse' , trap - s);
329
357
}
330
358
}
331
359
@@ -715,7 +743,7 @@ defineExpose({
715
743
stroke-linecap =" round"
716
744
stroke-dasharray =" 2"
717
745
stroke-width =" 1"
718
- v-if =" selectedTrap === trap && trap >= valueStart && trap < valueEnd "
746
+ v-if =" selectedTrap === trap && trap >= startMini && trap < endMini "
719
747
/>
720
748
</g >
721
749
</template >
@@ -730,7 +758,7 @@ defineExpose({
730
758
fill =" transparent"
731
759
style =" pointer-events : all !important ;"
732
760
:style =" {
733
- cursor: trap >= valueStart && trap < valueEnd && enableSelectionDrag ? isMouseDown ? 'grabbing' : 'grab' : 'default',
761
+ cursor: trap >= startMini && trap < endMini && enableSelectionDrag ? isMouseDown ? 'grabbing' : 'grab' : 'default',
734
762
}"
735
763
@mousedown =" isMouseDown = true"
736
764
@mouseup =" isMouseDown = false"
0 commit comments