/adei/trunk

To get this branch, use:
bzr branch http://darksoft.org/webbzr/adei/trunk

« back to all changes in this revision

Viewing changes to classes/views/calcview.php

  • Committer: Suren A. Chilingaryan
  • Date: 2020-02-05 10:44:04 UTC
  • Revision ID: csa@suren.me-20200205104404-pa4tmue5sni7nybb
Fix time-axes in the channel-arithmetics VIEW

Show diffs side-by-side

added added

removed removed

Lines of Context:
136
136
 
137
137
        $info = array(
138
138
            array("title" => _("Data Points"), "value" => "$total (of $this->max_points)"),
 
139
            array("title" => _("Missing Values"), "value" => "$missing"),
139
140
            array("title" => _("Formula"), "value" => "$this->math_func"),
140
141
            array("title" => _("x"), "value" => "$el_parent_x - $el_x"),
141
142
            array("title" => _("y"), "value" => "$el_parent_y - $el_y"),
142
 
            array("title" => _("Missing or Aggregated Data Points"), "value" => "$missing"),
143
143
        );
144
144
 
145
145
        if (sizeof($data) == 0) {
160
160
        return $view;
161
161
    }
162
162
 
163
 
    private function GetTicks($width, $length, $threshold) {
164
 
        $majTicks = ceil($length / $threshold);
165
 
        if($width < self::small_window_threshold || $majTicks < 20) {
166
 
            return floor($length/4);
167
 
        }
168
 
 
169
 
        return floor($majTicks/10);
 
163
    private function GetTicks($width, $length, $min_tick) {
 
164
        $n_ticks = $width / 40;
 
165
        if (!$n_ticks) $n_ticks = 1;
 
166
        $tick_step = $length / $n_ticks;
 
167
        return $min_tick * ceil($tick_step / $min_tick);
170
168
    }
171
169
 
172
170
    private function GetGraphView($data, $req)
188
186
            if ($width < $this->min_width) $width = $this->min_width;
189
187
            if ($height < $this->min_height) $height = $this->min_height;
190
188
        }
 
189
        $length = $this->ivl->GetWindowSize();
191
190
 
192
191
        $graph = new Graph($width, $height);
193
 
        $graph->SetScale('datlin');
 
192
        if ($length < $GRAPH_SUBSECOND_THRESHOLD)
 
193
            $graph->SetScale('linlin');
 
194
        else
 
195
            $graph->SetScale('datlin');
194
196
        $graph->xaxis->SetPos('min');
195
197
        $graph->xaxis->SetLabelAngle(90);
196
198
        $graph->xaxis->title->SetFont(FF_ARIAL, FS_BOLD);
197
199
        $graph->yaxis->title->SetFont(FF_ARIAL, FS_BOLD);
198
 
        $graph->yaxis->SetTitle("$this->math_func");
 
200
        $graph->xaxis->SetTextLabelInterval(1);
199
201
 
200
202
        $ydata = array_values($data);
201
203
        $xdata = array_keys($data);
202
204
 
203
 
        $max_val = max($ydata); 
204
 
        $yaxis_margin = strlen("$max_val") * 5;
205
 
        $graph->img->SetMargin(20 + $yaxis_margin, 10, 10, 60);
206
 
        $graph->yaxis->SetTitleMargin($yaxis_margin);
 
205
        $graph->img->SetMargin(60, 10, 15, 60);
 
206
        $graph->title->Set("$this->math_func");
207
207
 
208
 
        $length = dsMathPreciseSubstract($xdata[sizeof($xdata) - 1], $xdata[0]);
209
208
        if ($length > 315360000) { // 10 years
210
209
            $graph->xaxis->scale->SetDateFormat('Y');
211
 
            $graph->xaxis->SetTextLabelInterval(1);
212
210
            $graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, 315360000), 315360000);
213
211
        } elseif ($length > 31104000) { // 1 year
214
212
            $graph->xaxis->scale->SetDateFormat('M, Y');
215
 
            $graph->xaxis->SetTextLabelInterval(2);
216
 
            $graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, 31104000), 3104000);
 
213
            $graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, 3104000), 3104000);
217
214
        } elseif ($length > 1036800) { // 12 days
218
215
            $graph->xaxis->scale->SetDateFormat('M d');
219
 
            $graph->xaxis->SetTextLabelInterval(3);
220
 
            $graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, 1036800), 3600*24);
 
216
            $graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, 3600 * 24), 3600 * 24);
221
217
        } elseif ($length > 86400) { // 1 day
222
218
            $graph->xaxis->scale->SetDateFormat('M d, H:i');
223
 
            $graph->xaxis->SetTextLabelInterval(4);
224
 
            $graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, 86400), 3600 * 4);
 
219
            $graph->img->SetMargin(60, 10, 15, 100);
 
220
            $graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, 3600 * 4), 3600 * 4);
225
221
        } elseif ($length > 14400) { // 4 hours
226
222
            $graph->xaxis->scale->SetDateFormat('H:i');
227
 
            $graph->xaxis->SetTextLabelInterval(4);
228
 
            $graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, 14400), 1800);
 
223
            $graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, 1800), 1800);
229
224
        } elseif ($length > $GRAPH_SUBSECOND_THRESHOLD) {
230
225
            $graph->xaxis->scale->SetDateFormat('H:i:s');
231
 
            $graph->xaxis->SetTextLabelInterval(1);
232
 
            $majTicks = $this->GetTicks($width, $length, $GRAPH_SUBSECOND_THRESHOLD);
233
 
            $graph->xaxis->scale->ticks->Set($majTicks, $majTicks/10);
 
226
            $graph->xaxis->scale->ticks->Set($this->GetTicks($width, $length, $GRAPH_SUBSECOND_THRESHOLD), $GRAPH_SUBSECOND_THRESHOLD);
234
227
        } else {
235
228
            $from = $xdata[0];
236
 
            $ifrom = floor($from);
237
 
            if (is_float($from)) {
238
 
                $rfrom = substr(printf("%.9F", $from - $ifrom), 2);
239
 
            } else {
240
 
                $pos = strpos($from, ".");
241
 
                $rfrom = $pos === false ? 0 : substr($from, $pos + 1);
242
 
            }
243
 
 
244
 
            if ($rfrom) {
245
 
                $date_title .= "." . $rfrom;
246
 
                $rfrom = "0.$rfrom";
247
 
            }
248
 
 
249
 
            if ($length > $this->width / 1000) {
250
 
                $coef = 1000;
251
 
            } elseif ($length > $this->width / 1000000) {
252
 
                $coef = 1000000;
253
 
            } else {
254
 
                $coef = 1000000000;
255
 
            }
256
 
 
257
 
            $reallength = floor($length * $coef);
258
 
            $rem = ($reallength + 10) % 1000;
259
 
            $ilength = $rem < 20 ? $reallength - ($rem - 10) : $reallength;
260
 
 
261
 
            $first_num = substr($ilength, 0, 1);
262
 
            $second_num = substr($ilength, 1, 1);
263
 
            if ($second_num > 4) {
264
 
                if ((++$first_num) == 10) {
265
 
                    $istep = "1" . str_repeat("0", strlen($ilength) - 1);
266
 
                } else {
267
 
                    $istep = $first_num . str_repeat("0", strlen($ilength) - 2);
268
 
                }
269
 
            } else {
270
 
                $istep = $first_num . str_repeat("0", strlen($ilength) - 2);
271
 
            }
272
 
 
273
 
            $ticks = array($istep, $istep / 4);
274
 
            $graph->xaxis->scale->ticks->Set($ticks[0], $ticks[1]);
275
 
            $ticks = floor(($ilength + 1) / $istep);
276
 
            if ($width < 350) {
277
 
                if ($width < 70) $lpt = $ticks;
278
 
                else $lpt = ceil($ticks / ($width / 70));
279
 
            } else  {
280
 
                $lpt = round($ticks / 5);
281
 
            }
282
 
 
283
 
            $graph->xaxis->SetTextLabelInterval($lpt);
284
 
            $graph->xaxis->scale->SetDateFormat(false);
 
229
            foreach ($xdata as &$x) $x = dsMathPreciseSubstract($x, $from);
285
230
        }
286
231
 
287
232
        $lineplot = new LinePlot($ydata, $xdata);
288
 
 
289
233
        $graph->Add($lineplot);
290
234
        $graph->Stroke("$TMP_PATH/$tmp_file");
291
235