Skip to content

Commit b10f4ec

Browse files
committed
Improvement - VueUiVerticalBar - Add 'none' sort config option
1 parent 42cd83f commit b10f4ec

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

src/components/vue-ui-vertical-bar.vue

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ const immutableDataset = computed(() => {
256256
isSegregated: segregated.value.includes(id),
257257
color: convertColorToHex(serie.color) || customPalette.value[i] || palette[i] || palette[i % palette.length],
258258
children: !serie.children || !serie.children.length ? [] : serie.children
259-
.toSorted((a, b) => isSortDown.value ? b.value - a.value : a.value - b.value)
259+
.toSorted(isSortNeutral.value ? () => 0 : (a, b) => isSortDown.value ? b.value - a.value : a.value - b.value)
260260
.map((c, j) => {
261261
return {
262262
...c,
@@ -282,7 +282,7 @@ const immutableDataset = computed(() => {
282282
})
283283
}
284284
})
285-
.toSorted((a, b) => isSortDown.value ? b.value - a.value : a.value - b.value)
285+
.toSorted(isSortNeutral.value ? () => 0 : (a, b) => isSortDown.value ? b.value - a.value : a.value - b.value)
286286
});
287287
288288
const legendConfig = computed(() => {
@@ -594,9 +594,42 @@ function toggleTable() {
594594
mutableConfig.value.showTable = !mutableConfig.value.showTable;
595595
}
596596
597+
const sorts = ref({
598+
none: 0,
599+
asc: 1,
600+
desc: 2
601+
});
602+
603+
const sortIndex = ref(0);
604+
const isSortNeutral = ref(false);
605+
606+
onMounted(() => {
607+
if (!['none', 'asc', 'desc'].includes(FINAL_CONFIG.value.style.chart.layout.bars.sort)) {
608+
error({
609+
componentName: 'VueUiVerticalBar',
610+
type: 'attributeWrongValue',
611+
property: 'style.chart.layout.bars.sort',
612+
key: FINAL_CONFIG.value.style.chart.layout.bars.sort
613+
})
614+
}
615+
616+
sortIndex.value = sorts.value[FINAL_CONFIG.value.style.chart.layout.bars.sort];
617+
mutableConfig.value.sortDesc = sortIndex.value === 2;
618+
isSortNeutral.value = sortIndex.value === 0;
619+
});
620+
621+
function incrementSort() {
622+
sortIndex.value += 1;
623+
if (sortIndex.value > 2) {
624+
sortIndex.value = 0;
625+
}
626+
}
627+
597628
function toggleSort() {
598-
mutableConfig.value.sortDesc = !mutableConfig.value.sortDesc;
599-
recalculateHeight()
629+
incrementSort();
630+
mutableConfig.value.sortDesc = sortIndex.value === 2;
631+
isSortNeutral.value = sortIndex.value === 0;
632+
recalculateHeight();
600633
}
601634
602635
function toggleTooltip() {

0 commit comments

Comments
 (0)