Skip to content

Commit bd7ceeb

Browse files
committed
New feature - VueUiParallelCoordinatePlot - Add formatters
1 parent ede8acb commit bd7ceeb

File tree

4 files changed

+42
-16
lines changed

4 files changed

+42
-16
lines changed

TestingArena/ArenaVueUiParallelCoordinatePlot.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,21 @@ const config = computed(() => {
153153
...c.style.chart.yAxis.labels,
154154
roundings: [0, 0, 0, 1],
155155
suffixes: ['$', '', '£', '%'],
156-
axisNames: ['Axis 1', 'Axis 2', 'Axis 3', '']
156+
axisNames: ['Axis 1', 'Axis 2', 'Axis 3', ''],
157+
formatters: [
158+
({value, config}) => {
159+
return `f0 | ${value}`
160+
},
161+
({value, config}) => {
162+
return `f1 | ${value}`
163+
},
164+
({value, config}) => {
165+
return `f2 | ${value}`
166+
},
167+
({value, config}) => {
168+
return `f3 | ${value}`
169+
},
170+
]
157171
}
158172
}
159173
}

src/components/vue-ui-parallel-coordinate-plot.vue

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,18 @@ const mutableDataset = computed(() => {
347347
});
348348
349349
350-
function makeDataLabel({ value, index }) {
351-
return dataLabel({
352-
p: FINAL_CONFIG.value.style.chart.yAxis.labels.prefixes[index] || '',
353-
v: value,
354-
s: FINAL_CONFIG.value.style.chart.yAxis.labels.suffixes[index] || '',
355-
r: FINAL_CONFIG.value.style.chart.yAxis.labels.roundings[index] || 0
356-
});
350+
function makeDataLabel({ value, index, datapoint }) {
351+
return applyDataLabel(
352+
FINAL_CONFIG.value.style.chart.yAxis.labels.formatters[index] || null,
353+
value,
354+
dataLabel({
355+
p: FINAL_CONFIG.value.style.chart.yAxis.labels.prefixes[index] || '',
356+
v: value,
357+
s: FINAL_CONFIG.value.style.chart.yAxis.labels.suffixes[index] || '',
358+
r: FINAL_CONFIG.value.style.chart.yAxis.labels.roundings[index] || 0
359+
}),
360+
{ datapoint, seriesIndex: index }
361+
)
357362
}
358363
359364
const selectedItem = ref(null);
@@ -390,12 +395,17 @@ function useTooltip({ shape, serieName, serie, relativeIndex, seriesIndex }) {
390395
<div class="vue-ui-tooltip-item" style="text-align:left">
391396
<span>${s}: </span>
392397
<span>
393-
${dataLabel({
394-
p: FINAL_CONFIG.value.style.chart.yAxis.labels.prefixes[i] || '',
395-
v: serie.datapoints[i].value,
396-
s: FINAL_CONFIG.value.style.chart.yAxis.labels.suffixes[i] || '',
397-
r: FINAL_CONFIG.value.style.chart.yAxis.labels.roundings[i] || '',
398-
})}
398+
${applyDataLabel(
399+
FINAL_CONFIG.value.style.chart.yAxis.labels.formatters[i] || null,
400+
serie.datapoints[i].value,
401+
dataLabel({
402+
p: FINAL_CONFIG.value.style.chart.yAxis.labels.prefixes[i] || '',
403+
v: serie.datapoints[i].value,
404+
s: FINAL_CONFIG.value.style.chart.yAxis.labels.suffixes[i] || '',
405+
r: FINAL_CONFIG.value.style.chart.yAxis.labels.roundings[i] || '',
406+
}),
407+
{ datapoint: serie.datapoints[i], seriesIndex: i }
408+
)}
399409
</span>
400410
</div>
401411
`;
@@ -624,7 +634,7 @@ defineExpose({
624634
:font-weight="FINAL_CONFIG.style.chart.yAxis.labels.ticks.bold ? 'bold' : 'normal'"
625635
:style="`opacity:${selectedItem && !mutableConfig.showTooltip ? 0.2 : 1}`"
626636
>
627-
{{ makeDataLabel({ value: tick.value, index: i }) }}
637+
{{ makeDataLabel({ value: tick.value, index: i, datapoint: tick }) }}
628638
</text>
629639
</template>
630640
</g>
@@ -699,7 +709,7 @@ defineExpose({
699709
@mouseleave="selectedItem = null; isTooltip = false;"
700710
:style="`opacity:${selectedItem ? selectedItem === serieSet.id ? 1 : 0.2 : 1}`"
701711
>
702-
{{ makeDataLabel({ value: dp.value, index: k }) }}
712+
{{ makeDataLabel({ value: dp.value, index: k, datapoint: dp }) }}
703713
</text>
704714
</template>
705715

src/useConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3624,6 +3624,7 @@ export function useConfig() {
36243624
roundings: [],
36253625
prefixes: [],
36263626
suffixes: [],
3627+
formatters: [],
36273628
ticks: {
36283629
show: true,
36293630
fontSize: FONT._14,

types/vue-data-ui.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5038,6 +5038,7 @@ declare module 'vue-data-ui' {
50385038
roundings?: number[];
50395039
prefixes?: string[];
50405040
suffixes?: string[];
5041+
formatters?: Formatter[];
50415042
ticks?: {
50425043
show?: boolean;
50435044
fontSize?: number;

0 commit comments

Comments
 (0)