Skip to content

Commit 51fbf9f

Browse files
committed
Improvement - VueUiXy - Add optional sum in data table
1 parent f684218 commit 51fbf9f

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

src/components/vue-ui-xy.vue

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,15 +1975,38 @@ export default {
19751975
return { head, body};
19761976
},
19771977
dataTable() {
1978-
const head = [''].concat(this.relativeDataset.map(ds => ds.name)).concat(` <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M18 16v2a1 1 0 0 1 -1 1h-11l6 -7l-6 -7h11a1 1 0 0 1 1 1v2" /></svg>`)
1978+
const showSum = this.FINAL_CONFIG.table.showSum;
1979+
let head = [''].concat(this.relativeDataset.map(ds => ds.name))
1980+
1981+
if(showSum) {
1982+
head = head.concat(` <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M18 16v2a1 1 0 0 1 -1 1h-11l6 -7l-6 -7h11a1 1 0 0 1 1 1v2" /></svg>`)
1983+
}
19791984
19801985
let body = [];
19811986
for(let i = 0; i < this.maxSeries; i += 1) {
19821987
const sum = this.relativeDataset.map(ds => {
19831988
return ds.absoluteValues[i] ?? 0
19841989
}).reduce((a, b) => a + b, 0)
19851990
1986-
body.push([this.timeLabels[i] ?? '-'].concat(this.relativeDataset.map(ds => (ds.absoluteValues[i] ?? 0).toFixed(this.FINAL_CONFIG.table.rounding))).concat((sum ?? 0).toFixed(this.FINAL_CONFIG.table.rounding)))
1991+
body.push([
1992+
this.timeLabels[i] ?? '-']
1993+
.concat(this.relativeDataset
1994+
.map(ds => {
1995+
return this.applyDataLabel(
1996+
ds.type === 'line' ? this.FINAL_CONFIG.line.labels.formatter :
1997+
ds.type === 'bar' ? this.FINAL_CONFIG.bar.labels.formatter :
1998+
this.FINAL_CONFIG.plot.labels.formatter,
1999+
ds.absoluteValues[i] ?? 0,
2000+
this.dataLabel({
2001+
p: ds.prefix || this.FINAL_CONFIG.chart.labels.prefix,
2002+
v: ds.absoluteValues[i] ?? 0,
2003+
s: ds.suffix || this.FINAL_CONFIG.chart.labels.suffix,
2004+
r: this.FINAL_CONFIG.table.rounding
2005+
})
2006+
)}
2007+
))
2008+
.concat(showSum ? (sum ?? 0).toFixed(this.FINAL_CONFIG.table.rounding) : [])
2009+
)
19872010
}
19882011
19892012
const config = {
@@ -2022,7 +2045,9 @@ export default {
20222045
color: datapoint.color,
20232046
type: datapoint.type,
20242047
value: datapoint.absoluteValues.find((_s,i) => i === this.selectedSerieIndex),
2025-
comments: datapoint.comments || []
2048+
comments: datapoint.comments || [],
2049+
prefix: datapoint.prefix || this.FINAL_CONFIG.chart.labels.prefix,
2050+
suffix: datapoint.suffix || this.FINAL_CONFIG.chart.labels.suffix,
20262051
}
20272052
});
20282053
},
@@ -2123,9 +2148,9 @@ export default {
21232148
this.FINAL_CONFIG.plot.labels.formatter,
21242149
s.value,
21252150
this.dataLabel({
2126-
p: this.FINAL_CONFIG.chart.labels.prefix,
2151+
p: s.prefix,
21272152
v: s.value,
2128-
s: this.FINAL_CONFIG.chart.labels.suffix,
2153+
s: s.suffix,
21292154
r: this.FINAL_CONFIG.chart.tooltip.roundingValue,
21302155
}),
21312156
{ datapoint: s }

0 commit comments

Comments
 (0)