aboutsummaryrefslogtreecommitdiffstats
path: root/php/chart.php
diff options
context:
space:
mode:
authorMaksymilian Jopek <maks@jopek.eu>2023-03-26 18:31:50 +0200
committerMaksymilian Jopek <maks@jopek.eu>2023-03-26 18:31:50 +0200
commit5aa7c4f9499135dd12162045e441f5215ee050aa (patch)
tree4f95f9f2daedb0053a0b6a95a8e354d76b3c115d /php/chart.php
downloadcalendrier-menstruel-5aa7c4f9499135dd12162045e441f5215ee050aa.tar.gz
calendrier-menstruel-5aa7c4f9499135dd12162045e441f5215ee050aa.tar.zst
calendrier-menstruel-5aa7c4f9499135dd12162045e441f5215ee050aa.zip
Full working app
Diffstat (limited to 'php/chart.php')
-rw-r--r--php/chart.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/php/chart.php b/php/chart.php
new file mode 100644
index 0000000..bab5ce9
--- /dev/null
+++ b/php/chart.php
@@ -0,0 +1,46 @@
+<?php
+function drawChart(GdImage $img): void
+{
+ global $X_DATA, $Y_DATA;
+ require "consts.php";
+
+ $xx = [];
+ for ($x = $HOR_SPACE + $LINES->hor->x1; $x <= $LINES->hor->x2 + 1; $x += $HOR_SPACE) {
+ array_push($xx, $x);
+ }
+ $yy = [];
+ for ($y = $LINES->ver->y2 - $VER_SPACE; $y >= $LINES->ver->y1 - 1; $y -= $VER_SPACE) {
+ array_push($yy, $y);
+ }
+
+ $i = 0;
+ $ox = -1;
+ $oy = -1;
+ foreach ($X_DATA as $xd) {
+ $x = $xx[$i];
+
+ if ($xd === NULL) {
+ imagefilledellipse($img, $x, $yy[0] + $VER_SPACE, 7, 7, $COLOR->grey);
+ $ox = -1;
+ $oy = -1;
+ } elseif ($xd < 0) {
+ imagefilledellipse($img, $x, $yy[0] + $VER_SPACE, 7, 7, $COLOR->red);
+ $ox = -1;
+ $oy = -1;
+ } else {
+ $close_to = (($xd * 10 - $Y_DATA[0] * 10) / 10) / (($Y_DATA[1] * 10 - $Y_DATA[0] * 10) / 10) * $VER_SPACE;
+
+ $y = ($yy[0] * 10 - $close_to * 10) / 10;
+
+ imagefilledellipse($img, $x, $y, 7, 7, $COLOR->blue);
+
+ if ($ox >= 0)
+ imageline($img, $ox, $oy, $x, $y, $COLOR->blue);
+
+ $ox = $x;
+ $oy = $y;
+ }
+
+ $i++;
+ }
+}