From a75af90a6ea2824937e187822c7faa7a93ea118b Mon Sep 17 00:00:00 2001 From: Pablo Aragon Date: Mon, 22 Apr 2024 15:31:37 +0200 Subject: [PATCH] 13616-Fix text color chartjs with dark theme --- pandora_console/include/graphs/fgraph.php | 5 +++ .../include/styles/pandora_black.css | 4 +++ .../vendor/artica/phpchartjs/src/Options.php | 33 ++++++++++++++++++- .../phpchartjs/src/Renderer/JavaScript.php | 32 +++++++++++++++--- 4 files changed, 69 insertions(+), 5 deletions(-) diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 0d872bc8ee..b7593b592c 100644 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -547,6 +547,7 @@ function line_graph( function get_build_setup_charts($type, $options, $data) { global $config; + $user_info = get_user_info($config['id_user']); $factory = new Factory(); @@ -1294,6 +1295,10 @@ function get_build_setup_charts($type, $options, $data) } } + if (isset($user_info['id_skin']) === true) { + $chart->options()->setTheme($user_info['id_skin']); + } + // Add Datasets. $setData = $chart->createDataSet(); switch ($type) { diff --git a/pandora_console/include/styles/pandora_black.css b/pandora_console/include/styles/pandora_black.css index b1b404ae16..dde4085937 100644 --- a/pandora_console/include/styles/pandora_black.css +++ b/pandora_console/include/styles/pandora_black.css @@ -2094,3 +2094,7 @@ select option:checked { #horizontalBar > .labels > .label > div[style^="background"] { filter: invert(1); } + +.color_666 { + color: var(--text-color); +} diff --git a/pandora_console/vendor/artica/phpchartjs/src/Options.php b/pandora_console/vendor/artica/phpchartjs/src/Options.php index b1b5c91ad3..eecd8fa935 100644 --- a/pandora_console/vendor/artica/phpchartjs/src/Options.php +++ b/pandora_console/vendor/artica/phpchartjs/src/Options.php @@ -92,6 +92,11 @@ class Options implements ChartOwnedInterface, ArraySerializableInterface, JsonSe */ protected $indexAxis; + /** + * @var string + */ + protected $theme; + /** * @return Layout @@ -194,7 +199,7 @@ class Options implements ChartOwnedInterface, ArraySerializableInterface, JsonSe /** - * @return bool + * @return boolean */ public function disableAnimation() { @@ -323,6 +328,32 @@ class Options implements ChartOwnedInterface, ArraySerializableInterface, JsonSe } + /** + * Get font color. + * + * @return string + */ + public function getTheme() + { + return $this->theme; + } + + + /** + * Set font color. + * + * @param string $Theme Global font color. + * + * @return $this + */ + public function setTheme($theme) + { + $this->theme = $theme; + + return $this; + } + + /** * @return array */ diff --git a/pandora_console/vendor/artica/phpchartjs/src/Renderer/JavaScript.php b/pandora_console/vendor/artica/phpchartjs/src/Renderer/JavaScript.php index 3a0144bd9a..6b4848cb00 100644 --- a/pandora_console/vendor/artica/phpchartjs/src/Renderer/JavaScript.php +++ b/pandora_console/vendor/artica/phpchartjs/src/Renderer/JavaScript.php @@ -30,7 +30,7 @@ class JavaScript extends Renderer // Watermark. if (empty($this->chart->defaults()->getWatermark()) === false) { - $script[] = 'const chart_watermark_'.$this->chart->getId().' = { + $script[] = 'const chart_watermark_'.$this->chart->getId().' = { id: "chart_watermark_'.$this->chart->getId().'", beforeDraw: (chart) => { if (Object.prototype.hasOwnProperty.call(chart, "config") && @@ -128,11 +128,9 @@ class JavaScript extends Renderer } } };'; - $script[] = 'Chart.register(chart_watermark_'.$this->chart->getId().');'; + $script[] = 'Chart.register(chart_watermark_'.$this->chart->getId().');'; } - - // Create chart. $script[] = 'try {'; $script[] = " var chart = new Chart( ctx, {$json} );"; @@ -143,6 +141,32 @@ class JavaScript extends Renderer $script[] = ' Chart.defaults.font.style = "'.($this->chart->defaults()->getFonts()->getStyle() ?? 'normal').'";'; $script[] = ' Chart.defaults.font.weight = "'.($this->chart->defaults()->getFonts()->getWeight() ?? '').'";'; + if ($this->chart->options()->getTheme() !== null) { + if ((int) $this->chart->options()->getTheme() === 2) { + $script[] = ' Chart.defaults.color = "#ffffff";'; + + $script[] = ' + if (chart.config.options.scales !== undefined + && chart.config.options.scales.x !== undefined + && chart.config.options.scales.x.ticks !== undefined + ) { + chart.config.options.scales.x.ticks.color = "#ffffff"; + } + + if (chart.config.options.scales !== undefined && + chart.config.options.scales.y !== undefined && + chart.config.options.scales.y.ticks !== undefined + ) { + chart.config.options.scales.y.ticks.color = "#ffffff"; + } + + if (chart.config.options.title !== undefined ) { + chart.config.options.title.fontColor = "#ffffff"; + } + '; + } + } + $script[] = '} catch (error) {'; $script[] = ' console.error(error);'; $script[] = '}';