Skip to content

Commit

Permalink
improve chart component
Browse files Browse the repository at this point in the history
  • Loading branch information
lovasoa committed Jun 10, 2023
1 parent 351af7b commit a690b0a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion sqlpage/sqlpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
/* !include https://cdn.jsdelivr.net/npm/[email protected]/dist/apexcharts.min.js */

function sqlpage_chart() {

const tblrColors = Object.fromEntries(['azure', 'red', 'lime', 'blue', 'pink', 'indigo', 'purple', 'yellow', 'cyan', 'green', 'orange', 'cyan']
.map(c => [c, getComputedStyle(document.documentElement).getPropertyValue('--tblr-' + c)]));

/** @typedef { { [name:string]: {data:{x:number,y:number}[], name:string} } } Series */

/**
Expand Down Expand Up @@ -43,6 +47,11 @@ function sqlpage_chart() {
if (data.ymin == null) data.ymin = 0;
if (data.ymax == null) data.ymax = undefined;

const colors = [
...data.colors.filter(c => c).map(c => tblrColors[c]),
...Object.values(tblrColors)
];

let series = Object.values(series_map);

// tickamount is the number of intervals, not the number of ticks
Expand Down Expand Up @@ -80,7 +89,6 @@ function sqlpage_chart() {
enabled: !!data.labels,
},
fill: {
opacity: .7,
type: data.type === 'area' ? 'gradient' : 'solid',
},
stroke: {
Expand Down Expand Up @@ -115,6 +123,10 @@ function sqlpage_chart() {
sizeOffset: 5,
}
},
tooltip: {
fillSeriesColor: false,
},
colors,
series,
};
if (labels) options.labels = labels;
Expand Down
1 change: 1 addition & 0 deletions sqlpage/templates/chart.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"logarithmic": {{stringify logarithmic}},
"stacked": {{stringify stacked}},
"height": {{stringify (default height 250)}},
"colors": {{stringify (to_array color)}},
"points": [
{{~#each_row~}}
{{~#if (gt @row_index 0)}},{{/if~}}
Expand Down

0 comments on commit a690b0a

Please sign in to comment.