Skip to content

Commit 8672bba

Browse files
authored
Merge pull request #95 from graphieros/ft-zoom-minimap
Slicer - Improved displays with or without minimap
2 parents 060f22d + e42d3a2 commit 8672bba

File tree

1 file changed

+78
-26
lines changed

1 file changed

+78
-26
lines changed

src/atoms/Slicer.vue

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -197,28 +197,42 @@ const minimapLine = computed(() => {
197197
y: svgMinimap.value.height - (normalizedVal / diff * (svgMinimap.value.height * 0.9))
198198
}
199199
});
200-
return props.smoothMinimap ? createSmoothPath(points) : createStraightPath(points);
200+
const fullSet = props.smoothMinimap ? createSmoothPath(points) : createStraightPath(points);
201+
const sliced = [...points].slice(props.valueStart, props.valueEnd)
202+
const selectionSet = props.smoothMinimap ? createSmoothPath(sliced) : createStraightPath(sliced);
203+
return {
204+
fullSet,
205+
selectionSet,
206+
firstPlot: points[props.valueStart],
207+
lastPlot: points[props.valueEnd - 1]
208+
}
201209
});
202210
203-
const range = computed(() => props.max - props.min);
211+
const range = computed(() => props.max - props.min)
212+
213+
const selectionRect = computed(() => {
214+
return {
215+
left: ((startValue.value - props.min) / range.value) * 100,
216+
width: ((endValue.value - startValue.value) / range.value) * 100
217+
}
218+
})
219+
204220
const leftLabelPosition = computed(() => {
205-
const leftPercent = ((startValue.value - props.min) / range.value) * 100;
206221
return {
207-
left: `calc(${leftPercent}%)`,
222+
left: 0,
208223
color: props.textColor,
209224
fontSize: `${props.fontSize}px`,
210-
top: '-28px',
225+
top: hasMinimap.value ? '28px' : '-28px',
211226
pointerEvents: 'none',
212227
};
213228
});
214229
215230
const rightLabelPosition = computed(() => {
216-
const rightPercent = ((endValue.value - props.min) / range.value) * 100;
217231
return {
218-
left: `calc(${rightPercent}%)`,
232+
right: 0,
219233
color: props.textColor,
220234
fontSize: `${props.fontSize}px`,
221-
top: '28px',
235+
top: hasMinimap.value ? '28px' : '-28px',
222236
direction: 'rtl',
223237
pointerEvents: 'none'
224238
};
@@ -227,10 +241,17 @@ const rightLabelPosition = computed(() => {
227241
</script>
228242

229243
<template>
230-
<div data-html2canvas-ignore>
244+
<div data-html2canvas-ignore style="padding: 0 24px">
231245
<div class="vue-data-ui-slicer-labels" style="position: relative; z-index: 1">
232246
<div v-if="valueStart > 0 || valueEnd < max" style="width: 100%; position: relative">
233-
<button v-if="!useResetSlot" data-cy-reset tabindex="0" role="button" class="vue-data-ui-refresh-button"
247+
<button
248+
v-if="!useResetSlot"
249+
data-cy-reset tabindex="0"
250+
role="button"
251+
class="vue-data-ui-refresh-button"
252+
:style="{
253+
top: hasMinimap ? '36px' : '-16px'
254+
}"
234255
@click="reset">
235256
<BaseIcon name="refresh" :stroke="textColor" />
236257
</button>
@@ -247,29 +268,60 @@ const rightLabelPosition = computed(() => {
247268
<stop offset="100%" stop-color="transparent"/>
248269
</linearGradient>
249270
</defs>
250-
<rect
251-
:x="selectedMap.x"
252-
y="0"
253-
:width="selectedMap.width < 0 ? 0 : selectedMap.width"
254-
:height="svgMinimap.height < 0 ? 0 : svgMinimap.height"
255-
:rx="minimapSelectionRadius"
256-
:fill="`${minimapSelectedColor}`"
257-
:style="{ opacity: minimapSelectedColorOpacity }"
258-
/>
259271
<path
260-
:d="`M0,${svgMinimap.height} ${minimapLine} L${svgMinimap.width},${svgMinimap.height}Z`"
272+
:d="`M0,${svgMinimap.height} ${minimapLine.fullSet} L${svgMinimap.width},${svgMinimap.height}Z`"
261273
:stroke="`${minimapLineColor}`"
262274
:fill="`url(#${uid})`"
263275
stroke-width="1"
264276
stroke-linecap="round"
265277
stroke-linejoin="round"
278+
style="opacity: 1"
266279
/>
280+
<!-- This is not quite there yet: there's an annoying offset between input handles and plots -->
281+
<!-- <path
282+
:d="`M ${minimapLine.selectionSet}`"
283+
:stroke="`${minimapLineColor}`"
284+
fill="transparent"
285+
stroke-width="2"
286+
stroke-linecap="round"
287+
stroke-linejoin="round"
288+
/>
289+
<circle
290+
:cx="minimapLine.firstPlot.x"
291+
:cy="minimapLine.firstPlot.y"
292+
stroke-width="0.5"
293+
:stroke="borderColor"
294+
r="3"
295+
:fill="minimapLineColor"
296+
/>
297+
<circle
298+
:cx="minimapLine.lastPlot.x"
299+
:cy="minimapLine.lastPlot.y"
300+
stroke-width="0.5"
301+
:stroke="borderColor"
302+
r="3"
303+
:fill="minimapLineColor"
304+
/> -->
267305
<line :x1="0" :x2="svgMinimap.width < 0 ? 0 : svgMinimap.width" :y1="(svgMinimap.height < 0 ? 0 : svgMinimap.height)" :y2="(svgMinimap.height < 0 ? 0 : svgMinimap.height)" :stroke="borderColor" stroke-width="1"/>
268-
<line :x1="0" :x2="0" :y1="0" :y2="svgMinimap.height < 0 ? 0 : svgMinimap.height" :stroke="borderColor" stroke-width="3"/>
269-
<line :x1="svgMinimap.width < 0 ? 0 : svgMinimap.width" :x2="svgMinimap.width < 0 ? 0 : svgMinimap.width" :y1="0" :y2="svgMinimap.height < 0 ? 0 : svgMinimap.height" :stroke="borderColor" stroke-width="3"/>
306+
<line :x1="0" :x2="0" :y1="0" :y2="svgMinimap.height < 0 ? 0 : svgMinimap.height" :stroke="borderColor" stroke-width="5"/>
307+
<line :x1="svgMinimap.width < 0 ? 0 : svgMinimap.width" :x2="svgMinimap.width < 0 ? 0 : svgMinimap.width" :y1="0" :y2="svgMinimap.height < 0 ? 0 : svgMinimap.height" :stroke="borderColor" stroke-width="5"/>
270308
</svg>
271309
</div>
310+
<div
311+
class="sel"
312+
:style="{
313+
position: 'absolute',
314+
top: '-33px',
315+
left: `calc(${selectionRect.left}%)`,
316+
background: minimapSelectedColor,
317+
height: '40px',
318+
width: selectionRect.width + '%',
319+
borderRadius: `${minimapSelectionRadius}px ${minimapSelectionRadius}px 0 0`,
320+
opacity: minimapSelectedColorOpacity
321+
}"
322+
/>
272323
</template>
324+
273325
<div class="slider-track"></div>
274326
<div class="range-highlight" :style="highlightStyle"></div>
275327
<input type="range" :min="min" :max="max" v-model="startValue" @input="onStartInput" />
@@ -287,7 +339,7 @@ const rightLabelPosition = computed(() => {
287339
<style scoped lang="scss">
288340
.double-range-slider {
289341
position: relative !important;
290-
width: calc(100% - 48px);
342+
width: calc(100%);
291343
height: 40px;
292344
margin: 0 auto;
293345
padding-bottom: 12px;
@@ -393,8 +445,8 @@ input[type="range"]::-ms-thumb {
393445
394446
.vue-data-ui-refresh-button {
395447
position: absolute;
396-
right: 3px;
397-
top: -20px;
448+
left: 50%;
449+
transform: translateX(-50%);
398450
outline: none;
399451
border: none;
400452
background: transparent;
@@ -411,7 +463,7 @@ input[type="range"]::-ms-thumb {
411463
outline: 1px solid v-bind(slicerColor);
412464
}
413465
&:hover {
414-
transform: rotate(-90deg)
466+
transform: translateX(-50%) rotate(-90deg)
415467
}
416468
}
417469

0 commit comments

Comments
 (0)