1 | <?php |
||
54 | class SeriesDataHelper extends Component implements JsonSerializable |
||
55 | { |
||
56 | |||
57 | /** |
||
58 | * @var array column configuration |
||
59 | */ |
||
60 | protected $columns; |
||
61 | |||
62 | /** |
||
63 | * @var BaseDataProvider|array the underlying data source |
||
64 | */ |
||
65 | protected $data; |
||
66 | |||
67 | |||
68 | /** |
||
69 | * Constructor |
||
70 | * |
||
71 | * @param BaseDataProvider|array $data the underlying data source |
||
72 | * @param array $columns column configuration |
||
73 | * @param array $config for future use |
||
74 | * @see setColumns() |
||
75 | * @see setData() |
||
76 | */ |
||
77 | public function __construct($data, $columns, $config = []) |
||
84 | |||
85 | |||
86 | /** |
||
87 | * Sets the underlying data source. |
||
88 | * |
||
89 | * @param BaseDataProvider|array $data the data source |
||
90 | * @throws InvalidParamException |
||
91 | */ |
||
92 | public function setData($data) |
||
105 | |||
106 | |||
107 | /** |
||
108 | * Sets the column configuration. |
||
109 | * |
||
110 | * Each element can be either an array `['column', 'format']` or a shortcut string |
||
111 | * `'column:format'`. |
||
112 | * |
||
113 | * Column can be a string representing the attribute, field, or key from the |
||
114 | * source data. It can even be an integer if the source data uses numeric keys. |
||
115 | * |
||
116 | * Format can be one of the built-in formatters ('datetime', 'float', 'int', 'raw', 'string', or |
||
117 | * 'timestamp') or a callable that is used to prepare each data value. If format is omitted, the |
||
118 | * raw value will be passed to the chart. |
||
119 | * |
||
120 | * Example showing different ways to specify a column: |
||
121 | * |
||
122 | * ```php |
||
123 | * [ |
||
124 | * ['date_measured', 'datetime'], |
||
125 | * 'open', |
||
126 | * 'high:float', |
||
127 | * ['low', 'float'], |
||
128 | * ['close', function($value) { |
||
129 | * return ceil($value); |
||
130 | * }] |
||
131 | * ] |
||
132 | * ``` |
||
133 | * |
||
134 | * @param array $columns |
||
135 | * @throws InvalidParamException |
||
136 | */ |
||
137 | public function setColumns($columns) |
||
145 | |||
146 | |||
147 | /** |
||
148 | * @inheritdoc |
||
149 | */ |
||
150 | public function jsonSerialize() |
||
154 | |||
155 | |||
156 | /** |
||
157 | * Processes the source data and returns the result. |
||
158 | * |
||
159 | * @return array the processed data |
||
160 | */ |
||
161 | public function process() |
||
189 | |||
190 | |||
191 | /** |
||
192 | * Prepares the [[$columns]] for use by [[process()]]. |
||
193 | */ |
||
194 | protected function normalizeColumns() |
||
224 | |||
225 | |||
226 | /** |
||
227 | * Built-in formatters, which can be used in the [[$columns]] configuration. |
||
228 | * |
||
229 | * @return callable[] |
||
230 | */ |
||
231 | protected function getFormatters() |
||
242 | } |
||
243 |