Plot   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 141
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
dl 0
loc 141
rs 10
c 1
b 0
f 0
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A graph() 0 5 1
A xaxis() 0 3 1
A __construct() 0 7 1
A width() 0 4 1
A yaxis() 0 3 1
A jsonSerialize() 0 8 1
A height() 0 4 1
1
<?php
2
3
/**
4
 * Plot.php - A plot containing one or more graphs.
5
 *
6
 * @package jaxon-flot
7
 * @author Thierry Feuzeu <[email protected]>
8
 * @copyright 2017 Thierry Feuzeu <[email protected]>
9
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
10
 * @link https://github.com/jaxon-php/jaxon-flot
11
 */
12
13
namespace Jaxon\Flot\Plot;
14
15
use JsonSerializable;
16
use Jaxon\Flot\Data\Ticks;
17
18
use function trim;
19
20
class Plot implements JsonSerializable
21
{
22
23
    /**
24
     * The HTML element selector
25
     *
26
     * @var string
27
     */
28
    protected $sSelector;
29
30
    /**
31
     * The graphs
32
     *
33
     * @var array
34
     */
35
    protected $aGraphs = [];
36
37
    /**
38
     * The plot options
39
     *
40
     * @var array
41
     */
42
    protected $aOptions;
43
44
    /**
45
     * The plot width
46
     *
47
     * @var string
48
     */
49
    protected $sWidth;
50
51
    /**
52
     * The plot height
53
     *
54
     * @var string
55
     */
56
    protected $sHeight;
57
58
    /**
59
     * The plot X axis
60
     *
61
     * @var Ticks
62
     */
63
    protected $xAxisX;
64
65
    /**
66
     * The plot Y axis
67
     *
68
     * @var Ticks
69
     */
70
    protected $xAxisY;
71
72
    /**
73
     * The constructor.
74
     *
75
     * @param string        $sSelector            The jQuery selector
76
     */
77
    public function __construct($sSelector)
78
    {
79
        $this->sSelector = trim($sSelector, " \t");
80
        $this->xAxisX = new Ticks();
81
        $this->xAxisY = new Ticks();
82
        $this->sWidth = '';
83
        $this->sHeight = '';
84
    }
85
86
    /**
87
     * Set the container width.
88
     *
89
     * @param string        $sWidth                 The container width
90
     *
91
     * @return static
92
     */
93
    public function width($sWidth): static
94
    {
95
        $this->sWidth = trim($sWidth, " \t");
96
        return $this;
97
    }
98
99
    /**
100
     * Set the container height.
101
     *
102
     * @param string        $sHeight                The container height
103
     *
104
     * @return static
105
     */
106
    public function height($sHeight): static
107
    {
108
        $this->sHeight = trim($sHeight, " \t");
109
        return $this;
110
    }
111
112
    /**
113
     * Add a new graph to the plot.
114
     *
115
     * @param array         $aOptions               The graph options
116
     *
117
     * @return Graph
118
     */
119
    public function graph(array $aOptions = []): Graph
120
    {
121
        $xGraph = new Graph($aOptions);
122
        $this->aGraphs[] = $xGraph;
123
        return $xGraph;
124
    }
125
126
    /**
127
     * Get the graph X axis.
128
     *
129
     * @return Ticks
130
     */
131
    public function xaxis(): Ticks
132
    {
133
        return $this->xAxisX;
134
    }
135
136
    /**
137
     * Get the graph Y axis.
138
     *
139
     * @return Ticks
140
     */
141
    public function yaxis(): Ticks
142
    {
143
        return $this->xAxisY;
144
    }
145
146
    /**
147
     * Convert this object to an array for json format.
148
     *
149
     * This is a method of the JsonSerializable interface.
150
     *
151
     * @return array
152
     */
153
    public function jsonSerialize(): array
154
    {
155
        return [
156
            'selector' => $this->sSelector,
157
            'graphs' => $this->aGraphs,
158
            'xaxis' => $this->xAxisX,
159
            'yaxis' => $this->xAxisY,
160
            'size' => ['width' => $this->sWidth, 'height' => $this->sHeight],
161
        ];
162
    }
163
}
164