Skip to content

Commit b4b5d9d

Browse files
committed
Make tooltip style change with website theme.
1 parent d48d969 commit b4b5d9d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

layouts/shortcodes/heatmap.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,17 @@
2626
--heatmap-colors-light-1: #7bc96f;
2727
--heatmap-colors-light-2: #239a3b;
2828
--heatmap-colors-light-3: #196127;
29+
--tooltip-bg-light: #fff;
30+
--tooltip-textstyle-light: #1c1a1b;
2931

3032
--heatmap-bg-dark: #585c59;
3133
--heatmap-colors-dark-0: #c6e48b;
3234
--heatmap-colors-dark-1: #7bc96f;
3335
--heatmap-colors-dark-2: #239a3b;
3436
--heatmap-colors-dark-3: #196127;
37+
38+
--tooltip-bg-dark: #585c59;
39+
--tooltip-textstyle-dark: #fff;
3540
}
3641
</style>
3742
</head>
@@ -93,6 +98,21 @@
9398
: getCSSVariableValue('--heatmap-bg-light');
9499
}
95100

101+
function getTooltipBgColor(){
102+
const currentTheme = getCurrentTheme();
103+
return currentTheme === 'dark'
104+
? getCSSVariableValue('--tooltip-bg-dark')
105+
: getCSSVariableValue('--tooltip-bg-light');
106+
}
107+
108+
function getTextStyleColor() {
109+
const currentTheme = getCurrentTheme();
110+
return currentTheme === 'dark'
111+
? getCSSVariableValue('--tooltip-textstyle-dark')
112+
: getCSSVariableValue('--tooltip-textstyle-light');
113+
114+
}
115+
96116
function getCSSVariableValue(variableName) {
97117
return getComputedStyle(document.documentElement)
98118
.getPropertyValue(variableName).trim();
@@ -113,6 +133,8 @@
113133
// Reapply the option with theme-specific colors
114134
option.visualMap.inRange.color = getThemeColors();
115135
option.calendar.itemStyle.color = getThemeBgColor();
136+
option.tooltip.backgroundColor = getTooltipBgColor();
137+
option.tooltip.textStyle.color = getTextStyleColor();
116138
myChart.setOption(option);
117139
}
118140

@@ -241,6 +263,10 @@
241263
tooltip: {
242264
hideDelay: 1000,
243265
enterable: true,
266+
textStyle: {
267+
color: getTextStyleColor(),
268+
},
269+
backgroundColor: getTooltipBgColor(),
244270
formatter: function (params) {
245271
const thousandWordsText = {{ default "EN" (.Get "language")}} === "EN" ? 'k words': '千字';
246272
const date = params.data[0];

0 commit comments

Comments
 (0)