Skip to content

Commit b92ebf5

Browse files
committed
Improvement - VueUiChord - Add optional group percentage display
1 parent 3fcc81a commit b92ebf5

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

src/components/vue-ui-chord.vue

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ import { throttle } from '../canvas-lib';
4242
import { useResponsive } from '../useResponsive';
4343
import themes from "../themes.json";
4444
45-
/**
46-
*
47-
* - Diplay percentages per group (#donut)
48-
* - Add grab cursor when mousedown
49-
*
50-
*/
51-
5245
const { vue_ui_chord: DEFAULT_CONFIG } = useConfig();
5346
5447
const props = defineProps({
@@ -290,7 +283,8 @@ function computeChord(matrix, padAngle) {
290283
endAngle,
291284
name: formattedDataset.value.labels[i],
292285
id: createUid(),
293-
color: formattedDataset.value.colors[i]
286+
color: formattedDataset.value.colors[i],
287+
proportion: groupSums[i] / totalSum
294288
});
295289
currentAngle = endAngle + padAngle;
296290
}
@@ -910,6 +904,7 @@ defineExpose({
910904
:style="{
911905
overflow: 'visible'
912906
}"
907+
:class="{'vue-ui-chord-rotating': dragging, 'vue-ui-chord-idle': !rotating }"
913908
@mousedown.prevent="onDown"
914909
@touchstart.prevent="onDown"
915910
>
@@ -1121,13 +1116,18 @@ defineExpose({
11211116
<g v-if="FINAL_CONFIG.style.chart.arcs.labels.show">
11221117
<template v-if="FINAL_CONFIG.style.chart.arcs.labels.curved">
11231118
<text
1124-
v-for="(_g, i) in chordData.groups"
1119+
v-for="(g, i) in chordData.groups"
11251120
:key="`curved-label-${i}`"
11261121
:font-size="FINAL_CONFIG.style.chart.arcs.labels.fontSize"
11271122
:font-weight="FINAL_CONFIG.style.chart.arcs.labels.bold ? 'bold' : 'normal'"
11281123
:fill="FINAL_CONFIG.style.chart.arcs.labels.adaptColorToBackground ? adaptColorToBackground(formattedDataset.colors[i]) : FINAL_CONFIG.style.chart.arcs.labels.color">
11291124
<textPath :href="`#labelPath-${i}_${uid}`" startOffset="50%" text-anchor="middle">
1130-
{{ formattedDataset.labels[i] }}
1125+
{{ formattedDataset.labels[i] }}{{ FINAL_CONFIG.style.chart.arcs.labels.showPercentage ? dataLabel({
1126+
p: ' (',
1127+
v: isNaN(g.proportion) ? 0 : g.proportion * 100,
1128+
s: '%)',
1129+
r: FINAL_CONFIG.style.chart.arcs.labels.roundingPercentage
1130+
}) : '' }}
11311131
</textPath>
11321132
</text>
11331133
</template>
@@ -1143,8 +1143,14 @@ defineExpose({
11431143
:text-anchor="rotatedMidAngle(g) > Math.PI ? 'end' : 'start'"
11441144
:font-size="FINAL_CONFIG.style.chart.arcs.labels.fontSize"
11451145
:font-weight="FINAL_CONFIG.style.chart.arcs.labels.bold ? 'bold' : 'normal'"
1146-
:fill="FINAL_CONFIG.style.chart.arcs.labels.color">
1147-
{{ formattedDataset.labels[i] }}
1146+
:fill="FINAL_CONFIG.style.chart.arcs.labels.color"
1147+
>
1148+
{{ formattedDataset.labels[i] }}{{ FINAL_CONFIG.style.chart.arcs.labels.showPercentage ? dataLabel({
1149+
p: ' (',
1150+
v: isNaN(g.proportion) ? 0 : g.proportion * 100,
1151+
s: '%)',
1152+
r: FINAL_CONFIG.style.chart.arcs.labels.roundingPercentage
1153+
}) : '' }}
11481154
</text>
11491155
</template>
11501156
</g>
@@ -1324,4 +1330,12 @@ defineExpose({
13241330
transform: rotate(-90deg)
13251331
}
13261332
}
1333+
1334+
.vue-ui-chord-idle {
1335+
cursor: grab;
1336+
}
1337+
1338+
.vue-ui-chord-rotating {
1339+
cursor: grabbing;
1340+
}
13271341
</style>

src/useConfig.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5585,6 +5585,8 @@ export function useConfig() {
55855585
adaptColorToBackground: true, // Applied if curved
55865586
color: COLOR_BLACK, // If curved, applied if !adaptColorToBackground
55875587
offset: 0,
5588+
showPercentage: true,
5589+
roundingPercentage: 0,
55885590
}
55895591
},
55905592
ribbons: {

types/vue-data-ui.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7035,6 +7035,8 @@ declare module "vue-data-ui" {
70357035
adaptColorToBackground?: boolean;
70367036
color?: string;
70377037
offset?: number;
7038+
showPercentage?: boolean;
7039+
roundingPercentage?: number;
70387040
};
70397041
};
70407042
ribbons?: {

0 commit comments

Comments
 (0)