update chart dashboard
This commit is contained in:
@@ -81,6 +81,29 @@ window.config = {
|
||||
enableMenuLocalStorage: true // Enable menu state with local storage support
|
||||
};
|
||||
|
||||
// Choose the label color with the higher contrast against each chart slice.
|
||||
window.config.chartTextColor = function (color) {
|
||||
let hex = String(color || '').trim().replace(/^#/, '');
|
||||
if (/^[0-9a-f]{3}$/i.test(hex)) {
|
||||
hex = hex.split('').map(value => value + value).join('');
|
||||
}
|
||||
if (!/^[0-9a-f]{6}$/i.test(hex)) return '#212529';
|
||||
|
||||
const luminance = function (value) {
|
||||
const channels = value.match(/../g).map(channel => {
|
||||
const srgb = parseInt(channel, 16) / 255;
|
||||
return srgb <= 0.04045 ? srgb / 12.92 : Math.pow((srgb + 0.055) / 1.055, 2.4);
|
||||
});
|
||||
return channels[0] * 0.2126 + channels[1] * 0.7152 + channels[2] * 0.0722;
|
||||
};
|
||||
const background = luminance(hex);
|
||||
const dark = luminance('212529');
|
||||
const darkContrast = (Math.max(background, dark) + 0.05) / (Math.min(background, dark) + 0.05);
|
||||
const lightContrast = 1.05 / (background + 0.05);
|
||||
|
||||
return darkContrast >= lightContrast ? '#212529' : '#ffffff';
|
||||
};
|
||||
|
||||
window.assetsPath = document.documentElement.getAttribute('data-assets-path');
|
||||
window.templateName = document.documentElement.getAttribute('data-template');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user