Skip to content

Commit 10accf0

Browse files
authored
fix for the statistic graph axis colors - now it's picked from the selected theme (#92)
Signed-off-by: Kai Wagner <kai.wagner@percona.com>
1 parent ed4b57e commit 10accf0

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

app/views/stats/show.html.slim

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,17 @@
791791
return Math.max(320, Math.floor(width));
792792
}
793793

794+
function getChartColors() {
795+
const isDark = document.documentElement.dataset.theme === 'dark';
796+
return {
797+
textColor: isDark ? '#e2e8f0' : '#0f172a',
798+
cardBg: isDark ? '#111827' : '#ffffff',
799+
borderColor: isDark ? '#1f2937' : '#cdd5e7'
800+
};
801+
}
802+
794803
function buildLineSpec(intervals, width, height, enabledSeries) {
804+
const chartColors = getChartColors();
795805
const points = intervals.flatMap(row => (
796806
enabledSeries.map(series => ({
797807
interval_ts: row.interval_ts,
@@ -826,8 +836,8 @@
826836
{ name: "color", type: "ordinal", domain: enabledSeries.map(series => series.key), range: enabledSeries.map(series => series.color || "#666") }
827837
],
828838
axes: [
829-
{ orient: "bottom", scale: "x", format: "%Y-%m-%d", formatType: "utc", labelOverlap: true },
830-
{ orient: "left", scale: "y" }
839+
{ orient: "bottom", scale: "x", format: "%Y-%m-%d", formatType: "utc", labelOverlap: true, labelColor: chartColors.textColor, tickColor: chartColors.textColor, domainColor: chartColors.textColor },
840+
{ orient: "left", scale: "y", labelColor: chartColors.textColor, tickColor: chartColors.textColor, domainColor: chartColors.textColor }
831841
],
832842
signals: [
833843
{ name: "hoverTs", value: null, on: [
@@ -934,6 +944,7 @@
934944
}
935945

936946
function buildStackedBarSpec(intervals, width, height, enabledSeries) {
947+
const chartColors = getChartColors();
937948
const seriesOrder = new Map(enabledSeries.map((series, idx) => [series.key, idx]));
938949
const points = intervals.flatMap(row => (
939950
enabledSeries.map(series => ({
@@ -999,8 +1010,8 @@
9991010
{ name: "color", type: "ordinal", domain: enabledSeries.map(series => series.key), range: enabledSeries.map(series => series.color || "#666") }
10001011
],
10011012
axes: [
1002-
{ orient: "bottom", scale: "x", format: "%Y-%m-%d", formatType: "utc", labelOverlap: true },
1003-
{ orient: "left", scale: "y" }
1013+
{ orient: "bottom", scale: "x", format: "%Y-%m-%d", formatType: "utc", labelOverlap: true, labelColor: chartColors.textColor, tickColor: chartColors.textColor, domainColor: chartColors.textColor },
1014+
{ orient: "left", scale: "y", labelColor: chartColors.textColor, tickColor: chartColors.textColor, domainColor: chartColors.textColor }
10041015
],
10051016
marks: [
10061017
{
@@ -1100,6 +1111,7 @@
11001111
}
11011112

11021113
function buildOverlayBarSpec(intervals, width, height, enabledSeries) {
1114+
const chartColors = getChartColors();
11031115
if (!intervals.length) {
11041116
return { spec: null, points: [] };
11051117
}
@@ -1143,8 +1155,8 @@
11431155
{ name: "y", type: "linear", domain: [0, 1], nice: false, range: "height" }
11441156
],
11451157
axes: [
1146-
{ orient: "bottom", scale: "x", labelOverlap: true },
1147-
{ orient: "left", scale: "y", format: ".0%" }
1158+
{ orient: "bottom", scale: "x", labelOverlap: true, labelColor: chartColors.textColor, tickColor: chartColors.textColor, domainColor: chartColors.textColor },
1159+
{ orient: "left", scale: "y", format: ".0%", labelColor: chartColors.textColor, tickColor: chartColors.textColor, domainColor: chartColors.textColor }
11481160
],
11491161
marks: [
11501162
{
@@ -1247,6 +1259,7 @@
12471259
}
12481260

12491261
function buildLongevityHeatmapSpec(histogram, width) {
1262+
const chartColors = getChartColors();
12501263
const bucketOrder = ["0-1", "2-7", "8-30", "31-90", "91-180", "181-365", "365+"];
12511264
const points = histogram.map(row => ({
12521265
interval_ts: Date.parse(`${row.interval_start}T00:00:00Z`),
@@ -1266,8 +1279,8 @@
12661279
{ name: "color", type: "linear", domain: { data: "heat", field: "count" }, nice: true, range: ["#f2f0f7", "#54278f"] }
12671280
],
12681281
axes: [
1269-
{ orient: "bottom", scale: "x", format: "%Y-%m-%d", formatType: "utc", labelOverlap: true },
1270-
{ orient: "left", scale: "y" }
1282+
{ orient: "bottom", scale: "x", format: "%Y-%m-%d", formatType: "utc", labelOverlap: true, labelColor: chartColors.textColor, tickColor: chartColors.textColor, domainColor: chartColors.textColor },
1283+
{ orient: "left", scale: "y", labelColor: chartColors.textColor, tickColor: chartColors.textColor, domainColor: chartColors.textColor }
12711284
],
12721285
marks: [
12731286
{

0 commit comments

Comments
 (0)