Skip to content

Commit a690b0a

Browse files
committed
improve chart component
1 parent 351af7b commit a690b0a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

sqlpage/sqlpage.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
/* !include https://cdn.jsdelivr.net/npm/[email protected]/dist/apexcharts.min.js */
44

55
function sqlpage_chart() {
6+
7+
const tblrColors = Object.fromEntries(['azure', 'red', 'lime', 'blue', 'pink', 'indigo', 'purple', 'yellow', 'cyan', 'green', 'orange', 'cyan']
8+
.map(c => [c, getComputedStyle(document.documentElement).getPropertyValue('--tblr-' + c)]));
9+
610
/** @typedef { { [name:string]: {data:{x:number,y:number}[], name:string} } } Series */
711

812
/**
@@ -43,6 +47,11 @@ function sqlpage_chart() {
4347
if (data.ymin == null) data.ymin = 0;
4448
if (data.ymax == null) data.ymax = undefined;
4549

50+
const colors = [
51+
...data.colors.filter(c => c).map(c => tblrColors[c]),
52+
...Object.values(tblrColors)
53+
];
54+
4655
let series = Object.values(series_map);
4756

4857
// tickamount is the number of intervals, not the number of ticks
@@ -80,7 +89,6 @@ function sqlpage_chart() {
8089
enabled: !!data.labels,
8190
},
8291
fill: {
83-
opacity: .7,
8492
type: data.type === 'area' ? 'gradient' : 'solid',
8593
},
8694
stroke: {
@@ -115,6 +123,10 @@ function sqlpage_chart() {
115123
sizeOffset: 5,
116124
}
117125
},
126+
tooltip: {
127+
fillSeriesColor: false,
128+
},
129+
colors,
118130
series,
119131
};
120132
if (labels) options.labels = labels;

sqlpage/templates/chart.handlebars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"logarithmic": {{stringify logarithmic}},
2626
"stacked": {{stringify stacked}},
2727
"height": {{stringify (default height 250)}},
28+
"colors": {{stringify (to_array color)}},
2829
"points": [
2930
{{~#each_row~}}
3031
{{~#if (gt @row_index 0)}},{{/if~}}

0 commit comments

Comments
 (0)