1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
|
From: William Desportes <williamdes@wdes.fr>
Date: Thu, 26 Dec 2024 14:00:43 +0100
Subject: Replace c-pchart by a polyfill
Forwarded discussion to https://github.com/matomo-org/matomo/issues/20570
Origin: vendor
Forwarded: no
---
libs/ChartLib/ChartLib.php | 317 +++++++++++++++++++++++++++
plugins/ImageGraph/StaticGraph.php | 4 +-
plugins/ImageGraph/StaticGraph/Exception.php | 2 +-
plugins/ImageGraph/StaticGraph/PieGraph.php | 2 +-
4 files changed, 321 insertions(+), 4 deletions(-)
create mode 100644 libs/ChartLib/ChartLib.php
diff --git a/libs/ChartLib/ChartLib.php b/libs/ChartLib/ChartLib.php
new file mode 100644
index 0000000..b53552f
--- /dev/null
+++ b/libs/ChartLib/ChartLib.php
@@ -0,0 +1,317 @@
+<?php
+
+namespace ChartLib {
+ /**
+ * message: "#^Constant AXIS_FORMAT_CUSTOM not found\\.$#"
+ * message: "#^Constant LEGEND_FAMILY_LINE not found\\.$#"
+ * message: "#^Constant LEGEND_FAMILY_BOX not found\\.$#"
+ * message: "#^Constant LEGEND_HORIZONTAL not found\\.$#"
+ * message: "#^Constant LEGEND_NOBORDER not found\\.$#"
+ * message: "#^Constant LEGEND_VERTICAL not found\\.$#"
+ * message: "#^Constant SCALE_MODE_MANUAL not found\\.$#"
+ * message: "#^Constant SCALE_POS_LEFTRIGHT not found\\.$#"
+ * message: "#^Constant SCALE_POS_TOPBOTTOM not found\\.$#"
+ */
+
+ // Copied from https://github.com/szymach/c-pchart/blob/v3.0.17/constants.php
+
+ define("AXIS_FORMAT_CUSTOM", 680007);
+
+ define("SCALE_POS_LEFTRIGHT", 690101);
+ define("SCALE_POS_TOPBOTTOM", 690102);
+ define("SCALE_MODE_MANUAL", 690205);
+
+ define("LEGEND_FAMILY_BOX", 691051);
+ define("LEGEND_FAMILY_LINE", 691053);
+
+ define("LEGEND_NOBORDER", 690800);
+ define("LEGEND_VERTICAL", 690901);
+ define("LEGEND_HORIZONTAL", 690902);
+
+ abstract class Draw {
+
+ /**
+ * GD picture object
+ * @var resource
+ */
+ public $Picture;
+
+ /**
+ * Turn antialias on or off
+ * @var boolean
+ */
+ public $Antialias = true;
+
+ // -----
+
+ /**
+ * Draw a bar chart
+ * @param array $Format
+ */
+ public function drawBarChart(array $Format = [])
+ {
+ }
+
+ /**
+ * @param array $Format
+ * @throws Exception
+ */
+ public function drawScale(array $Format = [])
+ {
+ }
+
+ /**
+ * Write text
+ * @param int|float $X
+ * @param int|float $Y
+ * @param string $Text
+ * @param array $Format
+ * @return array
+ */
+ public function drawText($X, $Y, $Text, array $Format = [])
+ {
+ }
+
+
+ /**
+ * Draw a line chart
+ * @param array $Format
+ */
+ public function drawLineChart(array $Format = [])
+ {
+ }
+ }
+
+ class Pie {
+ public function __construct($pImage, $pData) {
+ }
+
+ /**
+ * Set the color of the specified slice
+ * @param mixed $SliceID
+ * @param array $Format
+ */
+ public function setSliceColor($SliceID, array $Format = [])
+ {
+ }
+
+ /**
+ * Draw the legend of pie chart
+ * @param int $X
+ * @param int $Y
+ * @param array $Format
+ * @return int
+ */
+ public function drawPieLegend($X, $Y, array $Format = [])
+ {
+ }
+
+ /**
+ * Draw a 3D pie chart
+ * @param int $X
+ * @param int $Y
+ * @param array $Format
+ * @return int
+ */
+ public function draw3DPie($X, $Y, array $Format = [])
+ {
+ }
+
+ /**
+ * Draw a pie chart
+ * @param int $X
+ * @param int $Y
+ * @param array $Format
+ * @return int
+ */
+ public function draw2DPie($X, $Y, array $Format = [])
+ {
+ }
+
+ }
+ class Data {
+ public function __construct() {
+ }
+ /**
+ * Return the data & configuration of the series
+ * @return array
+ */
+ public function getData()
+ {
+ return [];
+ }
+
+ /**
+ * Return the max value of a given serie
+ * @param string $Serie
+ * @return mixed
+ */
+ public function getMax($Serie)
+ {
+ return null;
+ }
+
+ /**
+ * Define if a serie should be draw with a special weight
+ * @param mixed $Series
+ * @param int $Weight
+ */
+ public function setSerieWeight($Series, $Weight = 0)
+ {
+ }
+
+ /**
+ * Set the color of one serie
+ * @param mixed $Series
+ * @param array $Format
+ */
+ public function setPalette($Series, array $Format = [])
+ {
+ }
+
+ /**
+ * Set the description of a given serie
+ * @param string|array $Series
+ * @param string $Description
+ */
+ public function setSerieDescription($Series, $Description = "My serie")
+ {
+ }
+ /**
+ * Set the serie that will be used as abscissa
+ * @param string $Serie
+ */
+ public function setAbscissa($Serie)
+ {
+ }
+
+ /**
+ * Add a single point or an array to the given serie
+ * @param mixed $Values
+ * @param string $SerieName
+ * @return int
+ */
+ public function addPoints($Values, $SerieName = "Serie1")
+ {
+ }
+
+ /**
+ * Set the display mode of an Axis
+ * @param int $AxisID
+ * @param int $Mode
+ * @param array $Format
+ */
+ public function setAxisDisplay($AxisID, $Mode = AXIS_FORMAT_DEFAULT, $Format = null)
+ {
+ }
+
+ /**
+ * Set the icon associated to a given serie
+ * @param mixed $Series
+ * @param mixed $Picture
+ */
+ public function setSeriePicture($Series, $Picture = null)
+ {
+ }
+ }
+
+ class Image extends Draw {
+ /**
+ * @param int $XSize
+ * @param int $YSize
+ * @param Data $DataSet
+ * @param boolean $TransparentBackground
+ */
+ public function __construct(
+ $XSize,
+ $YSize,
+ Data $DataSet = null,
+ $TransparentBackground = false
+ ) {
+ $this->Picture = imagecreate($XSize, $YSize)
+ or die("Cannot Initialize new GD image stream");
+ $background = imagecolorallocate($this->Picture, 224, 224, 209);
+ $textColor = imagecolorallocate($this->Picture, 0, 51, 102);
+
+ imagestring(
+ $this->Picture,
+ 2,// Font
+ 5,// X
+ 5,// Y
+ "Graphs renders are disabled",
+ $textColor
+ );
+ }
+
+ /**
+ * Set the graph area position
+ * @param int $X1
+ * @param int $Y1
+ * @param int $X2
+ * @param int $Y2
+ * @return int|null
+ */
+ public function setGraphArea($X1, $Y1, $X2, $Y2)
+ {
+ }
+
+ /**
+ * @param array $Format
+ * @throws \Exception
+ */
+ public function drawScale(array $Format = [])
+ {
+ }
+
+ /**
+ * Draw a filled rectangle
+ * @param int $X1
+ * @param int $Y1
+ * @param int $X2
+ * @param int $Y2
+ * @param array $Format
+ */
+ public function drawFilledRectangle($X1, $Y1, $X2, $Y2, array $Format = [])
+ {
+ }
+
+ /**
+ * Draw the legend of the active series
+ * @param int $X
+ * @param int $Y
+ * @param array $Format
+ */
+ public function drawLegend($X, $Y, array $Format = [])
+ {
+ }
+
+ /**
+ * Set current font properties
+ * @param array $Format
+ */
+ public function setFontProperties($Format = [])
+ {
+ }
+
+ /**
+ * Render the picture to a file
+ * @param string $FileName
+ */
+ public function render($FileName)
+ {
+ imagepng($this->Picture, $FileName);
+ imagedestroy($this->Picture);
+ }
+
+ /**
+ * Render the picture to a web browser stream
+ * @param boolean $BrowserExpire
+ */
+ public function stroke($BrowserExpire = false)
+ {
+ header('Content-type: image/png');
+ imagepng($this->Picture);
+ imagedestroy($this->Picture);
+ }
+ }
+}
diff --git a/plugins/ImageGraph/StaticGraph.php b/plugins/ImageGraph/StaticGraph.php
index 03c37ba..6a82ba6 100644
--- a/plugins/ImageGraph/StaticGraph.php
+++ b/plugins/ImageGraph/StaticGraph.php
@@ -9,8 +9,8 @@
namespace Piwik\Plugins\ImageGraph;
-use CpChart\Data;
-use CpChart\Image;
+use ChartLib\Data;
+use ChartLib\Image;
use Piwik\Container\StaticContainer;
use Piwik\NumberFormatter;
use Piwik\Piwik;
diff --git a/plugins/ImageGraph/StaticGraph/Exception.php b/plugins/ImageGraph/StaticGraph/Exception.php
index bb019d5..e0cab89 100644
--- a/plugins/ImageGraph/StaticGraph/Exception.php
+++ b/plugins/ImageGraph/StaticGraph/Exception.php
@@ -9,7 +9,7 @@
namespace Piwik\Plugins\ImageGraph\StaticGraph;
-use CpChart\Data;
+use ChartLib\Data;
use Piwik\Plugins\ImageGraph\StaticGraph;
/**
diff --git a/plugins/ImageGraph/StaticGraph/PieGraph.php b/plugins/ImageGraph/StaticGraph/PieGraph.php
index da1026c..613ffe2 100644
--- a/plugins/ImageGraph/StaticGraph/PieGraph.php
+++ b/plugins/ImageGraph/StaticGraph/PieGraph.php
@@ -9,7 +9,7 @@
namespace Piwik\Plugins\ImageGraph\StaticGraph;
-use CpChart\Chart\Pie;
+use ChartLib\Chart\Pie;
use Piwik\Plugins\ImageGraph\StaticGraph;
/**
|