diff options
| author | Maksymilian Jopek <maks@jopek.eu> | 2023-03-26 18:31:50 +0200 |
|---|---|---|
| committer | Maksymilian Jopek <maks@jopek.eu> | 2023-03-26 18:31:50 +0200 |
| commit | 5aa7c4f9499135dd12162045e441f5215ee050aa (patch) | |
| tree | 4f95f9f2daedb0053a0b6a95a8e354d76b3c115d /php/generate-img-map.php | |
| download | calendrier-menstruel-5aa7c4f9499135dd12162045e441f5215ee050aa.tar.gz calendrier-menstruel-5aa7c4f9499135dd12162045e441f5215ee050aa.tar.zst calendrier-menstruel-5aa7c4f9499135dd12162045e441f5215ee050aa.zip | |
Full working app
Diffstat (limited to 'php/generate-img-map.php')
| -rw-r--r-- | php/generate-img-map.php | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/php/generate-img-map.php b/php/generate-img-map.php new file mode 100644 index 0000000..504785d --- /dev/null +++ b/php/generate-img-map.php @@ -0,0 +1,36 @@ +<?php +function gen_img_map(): string +{ + global $X_DATA, $Y_DATA, $FX_DATA; + require "helpers.php"; + require "consts.php"; + + $out = ""; + + $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; + foreach ($X_DATA as $xd) { + $x = $xx[$i]; + if ($xd === NULL) { + $out .= "<area shape='circle' coords='$x," . $yy[0] + $VER_SPACE . ",4' onclick='showMenu(" . $FX_DATA[$i]['id'] . ", null)'>\n"; + } elseif ($xd < 0) { + $out .= "<area shape='circle' coords='$x," . $yy[0] + $VER_SPACE . ",4' onclick='showMenu(" . $FX_DATA[$i]['id'] . ", $xd)'>\n"; + } 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; + $out .= "<area shape='circle' coords='$x,$y,4' onclick='showMenu(" . $FX_DATA[$i]['id'] . ", $xd)'>\n"; + } + + $i++; + } + + return $out; +} |
