|
1 | 1 | <script setup> |
2 | | -import { ref, computed, onMounted, nextTick } from "vue"; |
| 2 | +import { ref, computed, onMounted } from "vue"; |
3 | 3 | import { useConfig } from "../useConfig"; |
4 | 4 | import { |
5 | 5 | adaptColorToBackground, |
@@ -246,6 +246,17 @@ const datasetTotals = computed(() => { |
246 | 246 | return sumSeries(unmutableDataset.value.filter(ds => !segregated.value.includes(ds.id))).slice(slicer.value.start, slicer.value.end); |
247 | 247 | }); |
248 | 248 |
|
| 249 | +const displayTotals = computed(() => { |
| 250 | + return sumSeries(unmutableDataset.value.filter(ds => !segregated.value.includes(ds.id)).map(s => { |
| 251 | + return { |
| 252 | + ...s, |
| 253 | + series: s.series.map((dp,i) => { |
| 254 | + return s.signedSeries[i] === -1 ? (dp >= 0 ? -dp : dp) : dp |
| 255 | + }) |
| 256 | + } |
| 257 | + })).slice(slicer.value.start, slicer.value.end); |
| 258 | +}) |
| 259 | +
|
249 | 260 | const datasetSignedTotals = computed(() => { |
250 | 261 | const src = unmutableDataset.value.filter(ds => !segregated.value.includes(ds.id)) |
251 | 262 | return { |
@@ -363,22 +374,18 @@ const formattedDataset = computed(() => { |
363 | 374 | }); |
364 | 375 |
|
365 | 376 | const totalLabels = computed(() => { |
366 | | - const MAX = Math.max(...datasetTotals.value); |
367 | | - const scale = calculateNiceScale(0, MAX, FINAL_CONFIG.value.style.chart.grid.scale.ticks); |
368 | | - const maxTotal = scale.max; |
369 | | -
|
370 | | - return datasetTotals.value.map((t, i) => { |
| 377 | + return displayTotals.value.map((t, i) => { |
371 | 378 | return { |
372 | 379 | value: t, |
373 | | - y: (1 - (t / maxTotal)) * drawingArea.value.height |
| 380 | + sign: t >= 0 ? 1 : -1 |
374 | 381 | } |
375 | 382 | }); |
376 | 383 | }); |
377 | 384 |
|
378 | 385 |
|
379 | 386 | function barDataLabel(val, datapoint, index, dpIndex, signed) { |
380 | 387 |
|
381 | | - const appliedValue = FINAL_CONFIG.value.style.chart.bars.distributed ? signed === 1 ? val : -val : val; |
| 388 | + const appliedValue = signed === - 1 ? (val >= 0 ? -val : val) : val |
382 | 389 | return applyDataLabel( |
383 | 390 | FINAL_CONFIG.value.style.chart.bars.dataLabels.formatter, |
384 | 391 | appliedValue, |
@@ -428,7 +435,7 @@ function useTooltip(seriesIndex) { |
428 | 435 | const datapoint = JSON.parse(JSON.stringify(formattedDataset.value)).map(fd => { |
429 | 436 | return { |
430 | 437 | name: fd.name, |
431 | | - value: fd.series[seriesIndex] === 0 ? 0 : fd.series[seriesIndex] || null, |
| 438 | + value: fd.series[seriesIndex] === 0 ? 0 : (fd.signedSeries[seriesIndex] === -1 ? (fd.series[seriesIndex] >= 0 ? -fd.series[seriesIndex] : fd.series[seriesIndex]) : fd.series[seriesIndex]) || null, |
432 | 439 | proportion: fd.proportions[seriesIndex] || null, |
433 | 440 | color: fd.color, |
434 | 441 | id: fd.id |
@@ -834,7 +841,7 @@ defineExpose({ |
834 | 841 | :font-weight="FINAL_CONFIG.style.chart.bars.totalValues.bold ? 'bold' : 'normal'" |
835 | 842 | :fill="FINAL_CONFIG.style.chart.bars.totalValues.color" |
836 | 843 | > |
837 | | - {{ barDataLabel(total.value, total, i) }} |
| 844 | + {{ barDataLabel(total.value, total, i, total.sign) }} |
838 | 845 | </text> |
839 | 846 | </g> |
840 | 847 | </template> |
|
0 commit comments