= first_log_id AND log.log_id < next_log_id WHERE log_id > $start_log_id AND location_id IN ( $list ) GROUP BY TIMESTAMPDIFF(MINUTE, log_timestamp, NOW()) DIV ?, location_id ORDER BY timeh EOQ , $_GET['avg']); $range = array(); foreach (array ( 'temp', 'rhum', 'ahum', 'time' ) as $kind) { $range[$kind] = array( 'min' => 10000, 'max' => -10000 ); } while ($row = mysqli_fetch_assoc($info)) { foreach (array ( 'temp', 'rhum', 'ahum' ) as $kind) { if (!isset($location_ids[$row['location_id']][$kind])) continue; if ($row[$kind] > $range[$kind]['max']) $range[$kind]['max'] = $row[$kind]; if ($row[$kind] < $range[$kind]['min']) $range[$kind]['min'] = $row[$kind]; if ($row['timeh'] > $range['time']['max']) $range['time']['max'] = $row['timeh']; if ($row['timeh'] < $range['time']['min']) $range['time']['min'] = $row['timeh']; $location_ids[$row['location_id']][$kind][] = array ( $row['timeh'], $row[$kind] ); } } function normalize($x, $scale, $range) { $diff = $range['max'] - $range['min']; return $scale*($range['max'] - $x)/$diff; } #$colors = array ( '#328', '#8ce', '#4a9', '#173', '#993', '#dc7', '#c67', '#825', '#a49' ); #$colors = array ( '#008', '#080', '#800', '#440', '#404', '#044', '#622', '#262', '#226' ); //$colors = array ( '#e6194B', '#3cb44b', '#4363d8', '#f58231', '#911eb4', '#42d4f4', '#f032e6', '#bfef45', '#9A6324', '#808000' ); $colors = array (); $index_to_id = array(); $colorcount = count($location_info); foreach ($location_info as $location_id => $data) { $index_to_id[] = $location_id; array_push($colors, $data['color']); //$color = array_shift($colors); //if (!$color) break; //$location_info[$location_id]['color'] = $color; } //header('Content-type: text/plain'); //print_r($location_info); //exit; require_once __DIR__.'/php-svg-0.9.0/autoloader.php'; use SVG\SVG; use SVG\Nodes\Shapes\SVGRect; use SVG\Nodes\Texts\SVGText; use SVG\Nodes\Shapes\SVGLine; use SVG\Nodes\Shapes\SVGPath; $sizex = 1024; $sizey = 600; // svg coordinate system have origin at top left, the x axis extends to the right // and the y axis extends down // image with 100x100 viewport $image = new SVG($sizex, $sizey); $doc = $image->getDocument(); $doc->setAttribute('viewBox', '0 0 1024 600'); // remove these two, this allows // the browser to resize the svg $doc->removeAttribute('width'); $doc->removeAttribute('height'); $xmargin = 51; $ymargin = 30; function calcdiv($range, $gewenst) { $log = log10($range); $floor = floor($log); $factors = array ( 2, 2, 2.5 ); $switchon = $log - $floor; if ($switchon >= log10(5)) { $start = 2; $cleanlog = $floor + log10(5); } else if ($switchon >= log10(2)) { $start = 0; $cleanlog = $floor + log10(2); } else { $start = 1; $cleanlog = $floor; } $div = pow(10, $cleanlog); $count = $range/$div; while ($count < $gewenst) { $count *= $factors[$start%3]; $div /= $factors[$start%3]; $start++; } return $div; } $sep = array('temp' => '1,0', 'rhum' => '3,7', 'ahum' => '7,3'); if ($range['temp']['min'] < $range['temp']['max']) { $div = calcdiv($range['temp']['max'] - $range['temp']['min'], 4); for ($bla = ceil($range['temp']['min']/$div)*$div; $bla <= floor($range['temp']['max']/$div)*$div+ $div/2; $bla += $div) { $y = normalize($bla, ($sizey-$ymargin), $range['temp']); $doc->addChild((new SVGLine($xmargin, $y, $sizex, $y))->setStyle('stroke', '#ccc')->setStyle('stroke-dasharray', $sep['temp'])); $doc->addChild((new SVGText($bla.'℃', $xmargin, $y))->setSize(9)->setAttribute('alignment-baseline', 'middle')->setAttribute('text-anchor', 'end')); } } if ($range['rhum']['min'] < $range['rhum']['max']) { $div = calcdiv($range['rhum']['max'] - $range['rhum']['min'], 4); for ($bla = ceil($range['rhum']['min']/$div)*$div; $bla <= floor($range['rhum']['max']/$div)*$div+ $div/2; $bla += $div) { $y = normalize($bla, ($sizey-$ymargin), $range['rhum']); $doc->addChild((new SVGLine(3/4*$xmargin, $y, $sizex, $y))->setStyle('stroke', '#ccc')->setStyle('stroke-dasharray', $sep['rhum'])); $doc->addChild((new SVGText($bla.'%', .5*$xmargin, $y))->setSize(9)->setAttribute('alignment-baseline', 'middle')->setAttribute('text-anchor', 'middle')); } //$doc->addChild((new SVGText(round($range['rhum']['max'], 0).'%', 0, 24))->setSize(12)); //$doc->addChild((new SVGText('rhum', 0, ($sizey-$ymargin)/2 - 4))->setSize(12)); //$doc->addChild((new SVGLine(0, ($sizey-$ymargin)/2, $xmargin - 5, ($sizey-$ymargin)/2))->setStyle('stroke', '#000')->setStyle('stroke-dasharray', $sep['rhum'])); //$doc->addChild((new SVGText(round($range['rhum']['min'], 0).'%', 0, ($sizey-$ymargin) - 17))->setSize(12)); } if ($range['ahum']['min'] < $range['ahum']['max']) { $div = calcdiv($range['ahum']['max'] - $range['ahum']['min'], 4); for ($bla = ceil($range['ahum']['min']/$div)*$div; $bla <= floor($range['ahum']['max']/$div)*$div+ $div/2; $bla += $div) { $y = normalize($bla, ($sizey-$ymargin), $range['ahum']); $doc->addChild((new SVGLine(2/4*$xmargin, $y, $sizex, $y))->setStyle('stroke', '#ccc')->setStyle('stroke-dasharray', $sep['ahum'])); $doc->addChild((new SVGText($bla.'g/m³', 0, $y))->setSize(9)->setAttribute('alignment-baseline', 'middle')->setAttribute('text-anchor', 'start')); } /*$doc->addChild((new SVGText(round($range['ahum']['max'], 2).'g/m³', 0, 36))->setSize(12)); $doc->addChild((new SVGText('ahum', 0, ($sizey-$ymargin)/2 + 26))->setSize(12)); $doc->addChild((new SVGLine(0, ($sizey-$ymargin)/2 + 30, $xmargin - 5, ($sizey-$ymargin)/2+30))->setStyle('stroke', '#000')->setStyle('stroke-dasharray', $sep['ahum'])); $doc->addChild((new SVGText(round($range['ahum']['min'], 2).'g/m³', 0, ($sizey-$ymargin)-5))->setSize(12));*/ } $doc->addChild((new SVGLine($xmargin,($sizey-$ymargin), $sizex, ($sizey-$ymargin)))->setStyle('stroke', '#000')); $doc->addChild((new SVGLine($xmargin, 0, $xmargin, ($sizey-$ymargin)))->setStyle('stroke', '#000')); $legendspace = ($sizex - $xmargin)/$colorcount; for ($i = 0; $i < min(count($location_info), $colorcount); $i++) { $doc->addChild((new SVGText($location_info[$index_to_id[$i]]['location_name'], $xmargin + $legendspace*$i + 12, $sizey-5))->setSize(12)); $square = new SVGRect($xmargin + $legendspace*$i, $sizey -16, 10, 10); $square->setStyle('fill', $location_info[$index_to_id[$i]]['color']); $square->setStyle('stroke', '#000'); $doc->addChild($square); } foreach ($location_ids as $location_id => $stuff) { foreach ($stuff as $kind => $data) { if (count($data) <= 1) continue; $command = "M"; $path = ''; foreach ($data as $points) { $x1 = normalize($points[0], $sizex - $xmargin, $range['time']) + $xmargin; $y1 = normalize($points[1], ($sizey-$ymargin), $range[$kind]); $path .= "$command $x1 $y1"; $command = " L"; } $doc ->addChild((new SVGPath($path))->setStyle('stroke', $location_info[$location_id]['color'])->setStyle('stroke-dasharray', $sep[$kind])->setStyle('fill', 'none')); } } ?> Weerstation

Weerstation / / h

toXMLString(false); ?>