ScatterChart   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 64
c 0
b 0
f 0
wmc 7
lcom 1
cbo 4
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getScatterData() 0 3 1
A defaultOptions() 0 12 1
A chartType() 0 3 1
A makePalette() 0 8 1
A data() 0 16 2
1
<?php namespace rtens\domin\delivery\web\renderers\charting\charts;
2
3
use rtens\domin\delivery\web\renderers\charting\Chart;
4
use rtens\domin\parameters\Color;
5
use rtens\domin\delivery\web\renderers\charting\data\ScatterDataPoint;
6
use rtens\domin\delivery\web\renderers\charting\data\ScatterDataSet;
7
8
class ScatterChart extends Chart {
9
10
    /** @var array|ScatterDataSet[] */
11
    private $scatterData = [];
12
13
    /**
14
     * ScatterChart constructor.
15
     * @param array|ScatterDataSet[] $scatterData
16
     */
17
    public function __construct($scatterData) {
18
        parent::__construct();
19
        $this->scatterData = $scatterData;
20
    }
21
22
    /**
23
     * @return array|\rtens\domin\delivery\web\renderers\charting\data\ScatterDataSet[]
24
     */
25
    public function getScatterData() {
26
        return $this->scatterData;
27
    }
28
29
    protected function defaultOptions() {
30
        return array_merge(parent::defaultOptions(), [
31
            'showTooltips' => true,
32
            'scaleShowHorizontalLines' => true,
33
            'scaleShowLabels' => true,
34
            'scaleLabel' => "<%=value%>",
35
            'scaleArgLabel' => "<%=value%>",
36
            'multiTooltipTemplate' => '<%=datasetLabel%>: <%=arg%>; <%=value%>',
37
            'scaleBeginAtZero' => true,
38
            'datasetStroke' => false
39
        ]);
40
    }
41
42
    public function chartType() {
43
        return "Scatter";
44
    }
45
46
    public function makePalette(Color $color) {
47
        list($red, $green, $blue) = $color->asArray();
48
        return [
49
            'strokeColor' => "rgba($red,$green,$blue,1)",
50
            'pointColor' => "rgba($red,$green,$blue,1)",
51
            'pointStrokeColor' => "rgba($red,$green,$blue,0.8)",
52
        ];
53
    }
54
55
    public function data() {
56
        return array_map(function (ScatterDataSet $data) {
57
            return array_merge(
58
                [
59
                    'label' => $data->getLabel(),
60
                    'data' => array_map(function (ScatterDataPoint $point) {
61
                        return [
62
                            'x' => $point->getX(),
63
                            'y' => $point->getY(),
64
                            'r' => $point->getR(),
65
                        ];
66
                    }, $data->getDataPoints())
67
                ],
68
                $this->makePalette($data->getColor() ?: $this->provideColor()));
69
        }, $this->scatterData);
70
    }
71
}