Skip to content

Commit 426cea8

Browse files
committed
VueUiWaffle added optional captions visible in horizontal mode
1 parent 5101627 commit 426cea8

File tree

6 files changed

+92
-4
lines changed

6 files changed

+92
-4
lines changed

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: 1 addition & 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": "2.0.29",
4+
"version": "2.0.30",
55
"type": "module",
66
"description": "A user-empowering data visualization Vue components library",
77
"keywords": [

src/App.vue

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2451,6 +2451,30 @@ const xyConfig = ref({
24512451
const waffleConfig = ref({
24522452
style: {
24532453
chart: {
2454+
layout: {
2455+
grid: {
2456+
vertical: false
2457+
},
2458+
labels: {
2459+
dataLabels: {
2460+
prefix: "$",
2461+
suffix: ""
2462+
},
2463+
captions: {
2464+
"show": true,
2465+
"showSerieName": true,
2466+
"serieNameAbbreviation": true,
2467+
"serieNameMaxAbbreviationSize": 3,
2468+
"fontSize": 20,
2469+
"showValue": true,
2470+
"showPercentage": true,
2471+
"roundingValue": 0,
2472+
"roundingPercentage": 0,
2473+
"offsetX": 0,
2474+
"offsetY": 0
2475+
}
2476+
}
2477+
},
24542478
tooltip: {
24552479
customFormat: ({seriesIndex, datapoint, series, config}) => {
24562480
console.log({seriesIndex, datapoint, series, config})

src/components/vue-ui-waffle.vue

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script setup>
22
import { ref, computed, nextTick } from "vue";
33
import {
4+
abbreviate,
5+
adaptColorToBackground,
46
convertColorToHex,
57
createCsvContent,
68
createUid,
@@ -61,6 +63,8 @@ const mutableConfig = ref({
6163
showTable: waffleConfig.value.table.show
6264
})
6365
66+
const captions = computed(() => waffleConfig.style.chart.layout.labels.captions)
67+
6468
const svg = computed(() => {
6569
const height = mutableConfig.value.inside ? 704 : 512;
6670
return {
@@ -187,13 +191,21 @@ const rects = computed(() => {
187191
return cumulatedSet.value.flatMap((serie, s) => {
188192
return serie.rects.map((rect, i) => {
189193
return {
194+
isFirst: i === 0,
195+
isLongEnough: rect.length > 2,
190196
name: serie.name,
191197
color: serie.color,
192198
value: serie.value,
193199
serieIndex: s,
200+
absoluteStartIndex: i < 3,
194201
...serie
195202
}
196203
})
204+
}).map((s, i) => {
205+
return {
206+
...s,
207+
isAbsoluteFirst: i % waffleConfig.value.style.chart.layout.grid.size === 0,
208+
}
197209
})
198210
});
199211
@@ -202,6 +214,8 @@ const positions = computed(() => {
202214
for(let i = 0; i < waffleConfig.value.style.chart.layout.grid.size; i += 1) {
203215
for(let j = 0; j < waffleConfig.value.style.chart.layout.grid.size; j += 1) {
204216
grid.push({
217+
isStartOfLine: j === 0,
218+
position: waffleConfig.value.style.chart.layout.grid.vertical ? i : j,
205219
x: (waffleConfig.value.style.chart.layout.grid.vertical ? i : j) * (rectDimension.value + waffleConfig.value.style.chart.layout.grid.spaceBetween),
206220
y: (waffleConfig.value.style.chart.layout.grid.vertical ? j : i) * (rectDimension.value + waffleConfig.value.style.chart.layout.grid.spaceBetween) + drawingArea.value.top,
207221
})
@@ -543,6 +557,30 @@ defineExpose({
543557
:stroke="waffleConfig.style.chart.layout.rect.stroke"
544558
:stroke-width="waffleConfig.style.chart.layout.rect.strokeWidth"
545559
/>
560+
<template v-for="(position, i) in positions">
561+
<foreignObject
562+
v-if="!waffleConfig.style.chart.layout.grid.vertical && waffleConfig.style.chart.layout.labels.captions.show && ((rects[i].isFirst && position.position < waffleConfig.style.chart.layout.grid.size - 3) || (rects[i].isAbsoluteFirst && i % waffleConfig.style.chart.layout.grid.size === 0 && rects[i].absoluteStartIndex))"
563+
:x="position.x + waffleConfig.style.chart.layout.labels.captions.offsetX"
564+
:y="position.y + waffleConfig.style.chart.layout.labels.captions.offsetY"
565+
:height="absoluteRectDimension"
566+
:width="absoluteRectDimension * 3"
567+
>
568+
<div class="vue-ui-waffle-caption" :style="`height: 100%; width: 100%; font-size:${waffleConfig.style.chart.layout.labels.captions.fontSize}px;display:flex;align-items:center;justify-content:flex-start;padding: 0 ${absoluteRectDimension / 12}px;color:${adaptColorToBackground(rects[i].color)};gap:2px`">
569+
<span v-if="waffleConfig.style.chart.layout.labels.captions.showSerieName">
570+
{{ waffleConfig.style.chart.layout.labels.captions.serieNameAbbreviation ? abbreviate({ source: rects[i].name, length: waffleConfig.style.chart.layout.labels.captions.serieNameMaxAbbreviationSize}) : rects[i].name }} :
571+
</span>
572+
<span v-if="waffleConfig.style.chart.layout.labels.captions.showPercentage">
573+
{{ dataLabel({ v: rects[i].proportion, s: '%', r: waffleConfig.style.chart.layout.labels.captions.roundingPercentage }) }}
574+
</span>
575+
<span v-if="waffleConfig.style.chart.layout.labels.captions.showPercentage && waffleConfig.style.chart.layout.labels.captions.showValue">
576+
({{ dataLabel({ p: waffleConfig.style.chart.layout.labels.dataLabels.prefix, v: rects[i].value, s: waffleConfig.style.chart.layout.labels.dataLabels.suffix, r: waffleConfig.style.chart.layout.labels.captions.roundingValue }) }})
577+
</span>
578+
<span v-if="!waffleConfig.style.chart.layout.labels.captions.showPercentage && waffleConfig.style.chart.layout.labels.captions.showValue">
579+
{{ dataLabel({ p: waffleConfig.style.chart.layout.labels.dataLabels.prefix, v: rects[i].value, s: waffleConfig.style.chart.layout.labels.dataLabels.suffix, r: waffleConfig.style.chart.layout.labels.captions.roundingValue }) }}
580+
</span>
581+
</div>
582+
</foreignObject>
583+
</template>
546584
<rect
547585
v-for="(position, i) in positions"
548586
:data-cy="`waffle-rect-${i}`"

src/default_configs.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,10 +593,23 @@
593593
"dataLabels": {
594594
"prefix": "",
595595
"suffix": ""
596+
},
597+
"captions": {
598+
"show": false,
599+
"showSerieName": false,
600+
"serieNameAbbreviation": true,
601+
"serieNameMaxAbbreviationSize": 3,
602+
"fontSize": 12,
603+
"showValue": true,
604+
"showPercentage": true,
605+
"roundingValue": 0,
606+
"roundingPercentage": 0,
607+
"offsetX": 0,
608+
"offsetY": 0
596609
}
597610
},
598611
"grid": {
599-
"size": 20,
612+
"size": 10,
600613
"spaceBetween": 2,
601614
"vertical": false
602615
},

types/vue-data-ui.d.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,6 +2468,19 @@ declare module 'vue-data-ui' {
24682468
prefix?: string;
24692469
suffix?: string;
24702470
};
2471+
captions?: {
2472+
show?: boolean;
2473+
showSerieName?: boolean;
2474+
serieNameAbbreviation?: boolean;
2475+
serieNameMaxAbbreviationSize?: number;
2476+
fontSize?: number;
2477+
showValue?: boolean;
2478+
showPercentage?: boolean;
2479+
roundingValue?: number;
2480+
roundingPercentage?: number;
2481+
offsetX?: number;
2482+
offsetY?: number;
2483+
};
24712484
};
24722485
grid?: {
24732486
size?: number;

0 commit comments

Comments
 (0)