From b6cb9a7fd8427aa9fd992e7d0dfacf2474abbd4d Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Wed, 13 Mar 2024 10:40:58 +0100 Subject: [PATCH] #12978 fixed short name in chart --- pandora_console/include/functions_graph.php | 15 +- pandora_console/include/graphs/fgraph.php | 22 + .../artica/phpchartjs/src/Options/Plugins.php | 55 +- .../artica/phpchartjs/src/Options/Tooltip.php | 819 ++++++++++++++++++ 4 files changed, 904 insertions(+), 7 deletions(-) create mode 100644 pandora_console/vendor/artica/phpchartjs/src/Options/Tooltip.php diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 4dbfa743bd..19d4e45467 100644 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -3398,8 +3398,10 @@ function graph_custom_sql_graph( if ($count <= $max_num_elements) { $label = __('Data'); + $full_label = __('Data'); if (empty($data_item['label']) === false) { $label = io_safe_output($data_item['label']); + $full_label = io_safe_output($data_item['label']); if (strlen($label) > $SQL_GRAPH_MAX_LABEL_SIZE) { $first_label = $label; $label = substr( @@ -3413,13 +3415,15 @@ function graph_custom_sql_graph( $labels_bar[] = $label; if ($type === 'sql_graph_hbar') { $data_bar[] = [ - 'y' => $label, - 'x' => $value, + 'full_title' => $full_label, + 'y' => $label, + 'x' => $value, ]; } else { $data_bar[] = [ - 'x' => $label, - 'y' => $value, + 'full_title' => $full_label, + 'x' => $label, + 'y' => $value, ]; } @@ -3493,6 +3497,9 @@ function graph_custom_sql_graph( 'grid' => ['display' => false], ], ], + 'tooltip' => [ + 'title' => ['fullTitle' => true], + ], 'labels' => $labels_bar, ]; diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 5861f67033..0d872bc8ee 100644 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -1272,6 +1272,28 @@ function get_build_setup_charts($type, $options, $data) $chart->labels()->exchangeArray($options['labels']); } + // Edit tooltip. + if (isset($options['tooltip']) === true && empty($options['tooltip']) === false) { + $tooltip_callback_value = 'item.formattedValue'; + if (isset($options['tooltip']['value']) === true && empty($options['tooltip']['value']) === false) { + $tooltip_callback_value = ''.$options['tooltip']['value'].''; + } + + $tooltip_callback_unit = ''; + if (isset($options['tooltip']['unit']) === true && empty($options['tooltip']['unit']) === false) { + $tooltip_callback_unit = '"'.$options['tooltip']['unit'].'"'; + } + + $tooltip_callback = '(item) => " " + '.$tooltip_callback_value.' + "'.$tooltip_callback_unit.'"'; + $chart->options()->getPlugins()->getTooltip()->callbacks()->setLabel($tooltip_callback); + + if (isset($options['tooltip']['title']) === true && empty($options['tooltip']['title']) === false) { + if (isset($options['tooltip']['title']['fullTitle']) === true && $options['tooltip']['title']['fullTitle'] === true) { + $chart->options()->getPlugins()->getTooltip()->callbacks()->setTitle('(item) => item[0].dataset.data[item[0].dataIndex].full_title'); + } + } + } + // Add Datasets. $setData = $chart->createDataSet(); switch ($type) { diff --git a/pandora_console/vendor/artica/phpchartjs/src/Options/Plugins.php b/pandora_console/vendor/artica/phpchartjs/src/Options/Plugins.php index 37d605b248..39bbec138c 100644 --- a/pandora_console/vendor/artica/phpchartjs/src/Options/Plugins.php +++ b/pandora_console/vendor/artica/phpchartjs/src/Options/Plugins.php @@ -14,11 +14,60 @@ class Plugins implements ArraySerializableInterface, JsonSerializable { use ArraySerializable; - protected $legend; + /** + * @var string + */ + private $legend; - protected $title; - protected $datalabels; + /** + * @var string + */ + private $title; + + + /** + * @var string + */ + private $datalabels; + + + /** + * @var string + */ + private $tooltips; + + + /** + * @var string + */ + private $tooltip; + + + /** + * @return Tooltips + */ + public function getTooltips() + { + if (is_null($this->tooltips)) { + $this->tooltips = new Tooltips(); + } + + return $this->tooltips; + } + + + /** + * @return Tooltip + */ + public function getTooltip() + { + if (is_null($this->tooltip)) { + $this->tooltip = new Tooltip(); + } + + return $this->tooltip; + } /** diff --git a/pandora_console/vendor/artica/phpchartjs/src/Options/Tooltip.php b/pandora_console/vendor/artica/phpchartjs/src/Options/Tooltip.php new file mode 100644 index 0000000000..95c7a6cc5f --- /dev/null +++ b/pandora_console/vendor/artica/phpchartjs/src/Options/Tooltip.php @@ -0,0 +1,819 @@ +enabled; + } + + /** + * @param bool $enabled + * + * @return $this + */ + public function setEnabled($enabled) + { + $this->enabled = boolval($enabled); + + return $this; + } + + /** + * @return \Laminas\Json\Expr + */ + public function getCustom() + { + return $this->custom; + } + + /** + * @param \Laminas\Json\Expr $custom + * + * @return $this + */ + public function setCustom($custom) + { + $this->custom = $custom; + + return $this; + } + + /** + * @return string + */ + public function getMode() + { + return $this->mode; + } + + /** + * @param string $mode + * + * @return $this + */ + public function setMode($mode) + { + $this->mode = strval($mode); + + return $this; + } + + /** + * @return bool + */ + public function isIntersect() + { + return $this->intersect; + } + + /** + * @param bool $intersect + * + * @return $this + */ + public function setIntersect($intersect) + { + $this->intersect = boolval($intersect); + + return $this; + } + + /** + * @return string + */ + public function getPosition() + { + return $this->position; + } + + /** + * @param string $position + * + * @return $this + */ + public function setPosition($position) + { + $this->position = strval($position); + + return $this; + } + + /** + * @return Expr + */ + public function getItemSort() + { + return $this->itemSort; + } + + /** + * @param Expr $itemSort + * + * @return $this + */ + public function setItemSort($itemSort) + { + $this->itemSort = new Expr(strval($itemSort)); + + return $this; + } + + /** + * @return Expr + */ + public function getFilter() + { + return $this->filter; + } + + /** + * @param Expr $filter + * + * @return $this + */ + public function setFilter($filter) + { + $this->filter = new Expr(strval($filter)); + + return $this; + } + + /** + * @return string + */ + public function getBackgroundColor() + { + return $this->backgroundColor; + } + + /** + * @param string $backgroundColor + * + * @return $this + */ + public function setBackgroundColor($backgroundColor) + { + $this->backgroundColor = strval($backgroundColor); + + return $this; + } + + /** + * @return string + */ + public function getTitleFontFamily() + { + return $this->titleFontFamily; + } + + /** + * @param string $titleFontFamily + * + * @return $this + */ + public function setTitleFontFamily($titleFontFamily) + { + $this->titleFontFamily = strval($titleFontFamily); + + return $this; + } + + /** + * @return int + */ + public function getTitleFontSize() + { + return $this->titleFontSize; + } + + /** + * @param int $titleFontSize + * + * @return $this + */ + public function setTitleFontSize($titleFontSize) + { + $this->titleFontSize = intval($titleFontSize); + + return $this; + } + + /** + * @return string + */ + public function getTitleFontStyle() + { + return $this->titleFontStyle; + } + + /** + * @param string $titleFontStyle + * + * @return $this + */ + public function setTitleFontStyle($titleFontStyle) + { + $this->titleFontStyle = strval($titleFontStyle); + + return $this; + } + + /** + * @return string + */ + public function getTitleFontColor() + { + return $this->titleFontColor; + } + + /** + * @param string $titleFontColor + * + * @return $this + */ + public function setTitleFontColor($titleFontColor) + { + $this->titleFontColor = strval($titleFontColor); + + return $this; + } + + /** + * @return int + */ + public function getTitleSpacing() + { + return $this->titleSpacing; + } + + /** + * @param int $titleSpacing + * + * @return $this + */ + public function setTitleSpacing($titleSpacing) + { + $this->titleSpacing = intval($titleSpacing); + + return $this; + } + + /** + * @return int + */ + public function getTitleMarginBottom() + { + return $this->titleMarginBottom; + } + + /** + * @param int $titleMarginBottom + * + * @return $this + */ + public function setTitleMarginBottom($titleMarginBottom) + { + $this->titleMarginBottom = intval($titleMarginBottom); + + return $this; + } + + /** + * @return string + */ + public function getBodyFontFamily() + { + return $this->bodyFontFamily; + } + + /** + * @param string $bodyFontFamily + * + * @return $this + */ + public function setBodyFontFamily($bodyFontFamily) + { + $this->bodyFontFamily = strval($bodyFontFamily); + + return $this; + } + + /** + * @return int + */ + public function getBodyFontSize() + { + return $this->bodyFontSize; + } + + /** + * @param int $bodyFontSize + * + * @return $this + */ + public function setBodyFontSize($bodyFontSize) + { + $this->bodyFontSize = intval($bodyFontSize); + + return $this; + } + + /** + * @return string + */ + public function getBodyFontStyle() + { + return $this->bodyFontStyle; + } + + /** + * @param string $bodyFontStyle + * + * @return $this + */ + public function setBodyFontStyle($bodyFontStyle) + { + $this->bodyFontStyle = strval($bodyFontStyle); + + return $this; + } + + /** + * @return string + */ + public function getBodyFontColor() + { + return $this->bodyFontColor; + } + + /** + * @param string $bodyFontColor + * + * @return $this + */ + public function setBodyFontColor($bodyFontColor) + { + $this->bodyFontColor = strval($bodyFontColor); + + return $this; + } + + /** + * @return int + */ + public function getBodySpacing() + { + return $this->bodySpacing; + } + + /** + * @param int $bodySpacing + * + * @return $this + */ + public function setBodySpacing($bodySpacing) + { + $this->bodySpacing = intval($bodySpacing); + + return $this; + } + + /** + * @return string + */ + public function getFooterFontFamily() + { + return $this->footerFontFamily; + } + + /** + * @param string $footerFontFamily + * + * @return $this + */ + public function setFooterFontFamily($footerFontFamily) + { + $this->footerFontFamily = strval($footerFontFamily); + + return $this; + } + + /** + * @return int + */ + public function getFooterFontSize() + { + return $this->footerFontSize; + } + + /** + * @param int $footerFontSize + * + * @return $this + */ + public function setFooterFontSize($footerFontSize) + { + $this->footerFontSize = intval($footerFontSize); + + return $this; + } + + /** + * @return string + */ + public function getFooterFontStyle() + { + return $this->footerFontStyle; + } + + /** + * @param string $footerFontStyle + * + * @return $this + */ + public function setFooterFontStyle($footerFontStyle) + { + $this->footerFontStyle = strval($footerFontStyle); + + return $this; + } + + /** + * @return string + */ + public function getFooterFontColor() + { + return $this->footerFontColor; + } + + /** + * @param string $footerFontColor + * + * @return $this + */ + public function setFooterFontColor($footerFontColor) + { + $this->footerFontColor = strval($footerFontColor); + + return $this; + } + + /** + * @return int + */ + public function getFooterSpacing() + { + return $this->footerSpacing; + } + + /** + * @param int $footerSpacing + * + * @return $this + */ + public function setFooterSpacing($footerSpacing) + { + $this->footerSpacing = intval($footerSpacing); + + return $this; + } + + /** + * @return int + */ + public function getFooterMarginTop() + { + return $this->footerMarginTop; + } + + /** + * @param int $footerMarginTop + * + * @return $this + */ + public function setFooterMarginTop($footerMarginTop) + { + $this->footerMarginTop = intval($footerMarginTop); + + return $this; + } + + /** + * @return int + */ + public function getXPadding() + { + return $this->xPadding; + } + + /** + * @param int $xPadding + * + * @return $this + */ + public function setXPadding($xPadding) + { + $this->xPadding = intval($xPadding); + + return $this; + } + + /** + * @return int + */ + public function getYPadding() + { + return $this->yPadding; + } + + /** + * @param int $yPadding + * + * @return $this + */ + public function setYPadding($yPadding) + { + $this->yPadding = intval($yPadding); + + return $this; + } + + /** + * @return int + */ + public function getCaretSize() + { + return $this->caretSize; + } + + /** + * @param int $caretSize + * + * @return $this + */ + public function setCaretSize($caretSize) + { + $this->caretSize = intval($caretSize); + + return $this; + } + + /** + * @return int + */ + public function getCornerRadius() + { + return $this->cornerRadius; + } + + /** + * @param int $cornerRadius + * + * @return $this + */ + public function setCornerRadius($cornerRadius) + { + $this->cornerRadius = intval($cornerRadius); + + return $this; + } + + /** + * @return string + */ + public function getMultiKeyBackground() + { + return $this->multiKeyBackground; + } + + /** + * @param string $multiKeyBackground + * + * @return $this + */ + public function setMultiKeyBackground($multiKeyBackground) + { + $this->multiKeyBackground = strval($multiKeyBackground); + + return $this; + } + + /** + * @return bool + */ + public function isDisplayColors() + { + return $this->displayColors; + } + + /** + * @param bool $displayColors + * + * @return $this + */ + public function setDisplayColors($displayColors) + { + $this->displayColors = boolval($displayColors); + + return $this; + } + + /** + * @return Callbacks + */ + public function callbacks() + { + if (is_null($this->callbacks)) { + $this->callbacks = new Callbacks(); + } + + return $this->callbacks; + } + + /** + * @return array + */ + public function jsonSerialize() + { + return $this->getArrayCopy(); + } +}