Skip to content

Commit 1b3ba18

Browse files
committed
Add tests, VueUiDonutEvolution minor improvements
1 parent eb6dee0 commit 1b3ba18

File tree

6 files changed

+675
-359
lines changed

6 files changed

+675
-359
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
![GitHub issues](https://img.shields.io/github/issues/graphieros/vue-data-ui)
1515
![NPM](https://img.shields.io/npm/l/vue-data-ui)
1616
![npm](https://img.shields.io/npm/dt/vue-data-ui)
17-
![Static Badge](https://img.shields.io/badge/components-29-green)
17+
![Static Badge](https://img.shields.io/badge/components-30-green)
1818

1919
[Interactive documentation](https://vue-data-ui.graphieros.com/)
2020

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "vue-data-ui",
33
"private": false,
4-
"version": "1.9.35",
4+
"version": "1.9.36",
55
"type": "module",
66
"description": "A user-empowering data visualization Vue components library",
77
"keywords": [
@@ -62,6 +62,7 @@
6262
"prod": "npm run test && npx cypress run --component && npm run clean && vite build --mode production && node copy-types.cjs && npm i",
6363
"build:dev": "npm run build && npm run dev",
6464
"test": "vitest --run",
65+
"test:w": "vitest --watch",
6566
"test:e2e": "npx cypress open"
6667
},
6768
"devDependencies": {

src/components/vue-ui-donut-evolution.vue

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup>
22
import { ref, computed, nextTick } from "vue";
3-
import { calcMarkerOffsetX, calcMarkerOffsetY, calcNutArrowPath, canShowValue, closestDecimal, makeDonut, palette, convertColorToHex, opacity, makeXls, createUid } from '../lib';
3+
import { calcMarkerOffsetX, calcMarkerOffsetY, calcNutArrowPath, canShowValue, closestDecimal, makeDonut, palette, convertColorToHex, opacity, makeXls, createUid, sumByAttribute } from '../lib';
44
import pdf from "../pdf";
55
import img from "../img";
66
import mainConfig from "../default_configs.json";
@@ -179,13 +179,8 @@ const yLabels = computed(() => {
179179
return steps;
180180
});
181181
182-
// lib
183-
function sumValues(source) {
184-
return [...source].map(s => s.value).reduce((a, b) => a + b, 0);
185-
}
186-
// lib
187182
function displayArcPercentage(arc, stepBreakdown) {
188-
return isNaN(arc.value / sumValues(stepBreakdown)) ? 0 : ((arc.value / sumValues(stepBreakdown)) * 100).toFixed(0) + "%";
183+
return isNaN(arc.value / sumByAttribute(stepBreakdown, 'value')) ? 0 : ((arc.value / sumByAttribute(stepBreakdown, "value")) * 100).toFixed(0) + "%";
189184
}
190185
191186
function leave() {
@@ -641,13 +636,12 @@ defineExpose({
641636
:stroke="donutEvolutionConfig.style.chart.color"
642637
stroke-width="1.5"
643638
/>
644-
<rect
639+
<circle
645640
@click="unfixDatapoint"
646641
@keypress.enter="unfixDatapoint"
647-
:x="svg.absoluteWidth - padding.right - 20"
648-
:y="padding.top"
649-
:width="20"
650-
:height="20"
642+
:cx="svg.absoluteWidth - padding.right - svg.width / 40"
643+
:cy="padding.top + svg.height / 30"
644+
:r="svg.height / 12"
651645
fill="transparent"
652646
style="cursor:pointer"
653647
tabindex="0"
@@ -669,16 +663,6 @@ defineExpose({
669663
:r="svg.height / 7"
670664
:fill="donutEvolutionConfig.style.chart.backgroundColor"
671665
/>
672-
<text
673-
text-anchor="middle"
674-
:x="padding.left + svg.width / 2"
675-
:y="padding.top + (svg.height / 2) + 14 / 3"
676-
:font-size="14"
677-
:font-weight="'bold'"
678-
:fill="donutEvolutionConfig.style.chart.layout.dataLabels.color"
679-
>
680-
{{ labellizeValue(fixedDatapoint.subtotal) }}
681-
</text>
682666
<path
683667
v-for="(arc, k) in fixedDatapoint.donutFocus"
684668
:d="arc.path"
@@ -705,6 +689,22 @@ defineExpose({
705689
:r="svg.height / 3.8"
706690
:fill="`url(#focus_${uid})`"
707691
/>
692+
<circle
693+
:cx="padding.left + (svg.width / 2)"
694+
:cy="padding.top + (svg.height / 2)"
695+
:r="svg.height / 7.7"
696+
:fill="donutEvolutionConfig.style.chart.backgroundColor"
697+
/>
698+
<text
699+
text-anchor="middle"
700+
:x="padding.left + svg.width / 2"
701+
:y="padding.top + (svg.height / 2) + 14 / 3"
702+
:font-size="14"
703+
:font-weight="'bold'"
704+
:fill="donutEvolutionConfig.style.chart.layout.dataLabels.color"
705+
>
706+
{{ labellizeValue(fixedDatapoint.subtotal) }}
707+
</text>
708708
<text
709709
v-if="donutEvolutionConfig.style.chart.layout.grid.xAxis.dataLabels.values[fixedDatapoint.index]"
710710
:x="padding.left + 6"
@@ -749,8 +749,11 @@ defineExpose({
749749
</template>
750750
<template #td="{td}">
751751
<span v-if="td.value === null">-</span>
752-
<span v-else>
753-
{{ !isNaN(td.value) ? donutEvolutionConfig.style.chart.layout.dataLabels.prefix : '' }}{{ !isNaN(td.value) && td.value !== null ? Number(td.value.toFixed(donutEvolutionConfig.table.td.roundingValue)).toLocaleString() : td }}{{ !isNaN(td.value) ? donutEvolutionConfig.style.chart.layout.dataLabels.suffix : '' }}
752+
<b v-else>
753+
{{ !isNaN(td.value) ? donutEvolutionConfig.style.chart.layout.dataLabels.prefix : '' }}{{ !isNaN(td.value) && td.value !== null ? Number(td.value.toFixed(donutEvolutionConfig.table.td.roundingValue)).toLocaleString() : td }}{{ !isNaN(td.value) ? donutEvolutionConfig.style.chart.layout.dataLabels.suffix : '' }}
754+
</b>
755+
<span>
756+
{{ td.percentage && !isNaN(td.percentage) ? `(${Number(td.percentage.toFixed(donutEvolutionConfig.table.td.roundingPercentage)).toLocaleString()}%)` : '' }}
754757
</span>
755758
</template>
756759
</DataTable>

0 commit comments

Comments
 (0)