PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.12.1
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.12.1
5.12.1 5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / vendor / davaxi / sparkline / src / Sparkline / PointTrait.php
matomo / app / vendor / davaxi / sparkline / src / Sparkline Last commit date
DataTrait.php 2 years ago FormatTrait.php 6 months ago Picture.php 6 months ago PointTrait.php 2 years ago StyleTrait.php 2 years ago
PointTrait.php
63 lines
1 <?php
2
3 namespace Davaxi\Sparkline;
4
5 use InvalidArgumentException;
6 /**
7 * Trait PointTrait.
8 */
9 trait PointTrait
10 {
11 /**
12 * @var array
13 */
14 protected $points = [];
15 /**
16 * @param int|string $index
17 * @param float $dotRadius
18 * @param string $colorHex
19 * @param int $seriesIndex
20 */
21 public function addPoint($index, float $dotRadius, string $colorHex, int $seriesIndex = 0)
22 {
23 $mapping = $this->getPointIndexMapping($seriesIndex);
24 if (array_key_exists($index, $mapping)) {
25 $index = $mapping[$index];
26 if ($index < 0) {
27 return;
28 }
29 }
30 if (!is_numeric($index)) {
31 throw new InvalidArgumentException('Invalid index : ' . $index);
32 }
33 $this->checkPointIndex($index, $seriesIndex);
34 $this->points[] = ['series' => $seriesIndex, 'index' => $index, 'radius' => $dotRadius, 'color' => $this->colorHexToRGB($colorHex)];
35 }
36 /**
37 * @param int $seriesIndex
38 * @return array
39 */
40 protected function getPointIndexMapping(int $seriesIndex = 0) : array
41 {
42 $count = $this->getCount($seriesIndex);
43 list($minIndex, $min, $maxIndex, $max) = $this->getExtremeValues($seriesIndex);
44 $mapping = [];
45 $mapping['first'] = $count > 1 ? 0 : -1;
46 $mapping['last'] = $count > 1 ? $count - 1 : -1;
47 $mapping['minimum'] = $min !== $max ? $minIndex : -1;
48 $mapping['maximum'] = $min !== $max ? $maxIndex : -1;
49 return $mapping;
50 }
51 /**
52 * @param int $index
53 * @param int $seriesIndex
54 */
55 protected function checkPointIndex(int $index, int $seriesIndex)
56 {
57 $count = $this->getCount($seriesIndex);
58 if ($index < 0 || $index >= $count) {
59 throw new InvalidArgumentException('Index out of range [0-' . ($count - 1) . '] : ' . $index);
60 }
61 }
62 }
63