11<script setup>
22import { ref , computed , nextTick } from " vue" ;
33import {
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+
6468const 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}`"
0 commit comments