Skip to content

Commit 7d88595

Browse files
committed
Improvement - VueUiBullet - Negative values support
1 parent 9feab0b commit 7d88595

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

TestingArena/ArenaVueUiBullet.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@ import { useArena } from "../src/useArena";
99
const { local, build, vduiLocal, vduiBuild } = useArena()
1010
1111
const dataset = ref({
12-
value: 85,
13-
target: 80,
12+
value: -20,
13+
target: -10,
1414
segments: [
1515
{
1616
name: 'Low',
17-
from: 0,
18-
to: 50,
17+
from: -100,
18+
to: -30,
1919
// color: '#4A4A4A'
2020
},
2121
{
2222
name: 'Medium',
23-
from: 50,
24-
to: 70,
23+
from: -30,
24+
to: 0,
2525
// color: '#6A6A6A'
2626
},
2727
{
2828
name: 'High',
29-
from: 70,
29+
from: 0,
3030
to: 100,
3131
// color: '#8A8A8A'
3232
}

src/components/vue-ui-bullet.vue

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,19 @@ const segments = computed(() => {
226226
return [];
227227
};
228228
const scale = calculateNiceScale(minMax.value.min, minMax.value.max, FINAL_CONFIG.value.style.chart.segments.ticks.divisions);
229+
const absMin = scale.min >= 0 ? 0 : Math.abs(scale.min);
230+
229231
const target = {
230-
x: svg.value.left + (props.dataset.target / scale.max * svg.value.chartWidth) - FINAL_CONFIG.value.style.chart.target.width / 2
232+
x: svg.value.left + (((props.dataset.target + absMin) / (scale.max + absMin)) * svg.value.chartWidth) - FINAL_CONFIG.value.style.chart.target.width / 2
231233
}
232234
const value = {
233-
width: activeValue.value / scale.max * svg.value.chartWidth
235+
width: ((activeValue.value + absMin) / (scale.max + absMin)) * svg.value.chartWidth
234236
}
235237
const ticks = scale.ticks.map(t => {
236238
return {
237239
value: t,
238240
y: svg.value.bottom + FINAL_CONFIG.value.style.chart.segments.dataLabels.fontSize + 3 + FINAL_CONFIG.value.style.chart.segments.dataLabels.offsetY,
239-
x: svg.value.left + (t / scale.max * svg.value.chartWidth)
241+
x: svg.value.left + (((t + absMin) / (scale.max + absMin)) * svg.value.chartWidth)
240242
}
241243
})
242244
return {
@@ -248,10 +250,10 @@ const segments = computed(() => {
248250
return {
249251
...segment,
250252
color: segment.color ? convertColorToHex(segment.color) : segmentColors.value[i],
251-
x: svg.value.left + (svg.value.chartWidth * (segment.from / scale.max)),
252-
y: svg.value.top, // no padding
253+
x: svg.value.left + (svg.value.chartWidth * ((segment.from + absMin) / (scale.max + absMin))),
254+
y: svg.value.top,
253255
height: svg.value.chartHeight,
254-
width: svg.value.chartWidth * ((segment.to - segment.from) / scale.max),
256+
width: svg.value.chartWidth * (Math.abs(segment.to - segment.from) / (scale.max + absMin)),
255257
}
256258
})
257259
}

0 commit comments

Comments
 (0)