diff --git a/index.php b/index.php index 5f12263..86a2891 100644 --- a/index.php +++ b/index.php @@ -20,14 +20,14 @@ $router->map('GET', '/', function() { }); // map cryptocurrency stuff -$router->map( 'GET', '/charts/[BTC_DASH:pair]/[7d|24h:duration]/[svg|png:format]', function($pair, $duration, $format) { +$router->map( 'GET', '/charts/[dark|light:theme]/[a:curA]-[a:curB]/[7d|24h:duration]/[svg|png:format]', function($theme, $curA, $curB, $duration, $format) { require __DIR__ . '/views/chart.php'; renderChart( - $pair, + $theme, + strtoupper($curB.'_'.$curA), 60 * 60 * 24 * ($duration == '7d' ? 7 : 1), ($duration == '7d' ? 1800 : 300), $format, - '#000', 800, 200, 12 @@ -39,12 +39,12 @@ $router->map( 'GET', '/charts/[BTC_DASH:pair]/[7d|24h:duration]/[svg|png:format] $match = $router->match(); // call closure or throw 404 status +if( !$match || !is_callable( $match['target'] ) || false === call_user_func_array( $match['target'], $match['params'] )) { + // no route was matched + header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found'); + echo '

404 Not Found

Page not found

'; +} try { - if( !$match || !is_callable( $match['target'] ) || false === call_user_func_array( $match['target'], $match['params'] )) { - // no route was matched - header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found'); - echo '

404 Not Found

Page not found

'; - } } catch (Exception $e) { header($_SERVER["SERVER_PROTOCOL"]." 500 Server Error", true, 500); echo 'There was some problem generating that for you.'; diff --git a/views/chart.php b/views/chart.php index afa1399..d0a58bb 100644 --- a/views/chart.php +++ b/views/chart.php @@ -21,17 +21,19 @@ function getJson($url) { } function renderChart( + $theme, $pair, $dataDuration = (7 * 24 * 60 * 60), $dataResolution = 1800, $format = 'svg', - $color = '#000', $width = 800, $height = 200, $fontSize = 12 ) { - $result = CacheManager::get('poloniex-'.$pair.'-'.$dataDuration.'-'.$format); + $chartCacheKey = 'poloniex-'.$theme.'-'.$pair.'-'.$dataDuration.'-'.$format; + + $result = CacheManager::get($chartCacheKey); if (is_null($result)) { $startTime = time() - $dataDuration; @@ -54,8 +56,8 @@ function renderChart( $poloniexChart = new NeatCharts\LineChart($chartData, [ 'width'=>800, 'height'=>200, - 'lineColor'=>"#1C75BC", // Dash blue - 'labelColor'=>"#000", + 'lineColor'=>($theme == 'dark' ? '#000' : '#fff'), + 'labelColor'=>($theme == 'dark' ? '#000' : '#fff'), 'smoothed'=>false, 'fontSize'=>12 ]); @@ -63,26 +65,26 @@ function renderChart( if ($format == 'png') { $im = new Imagick(); - $im->setBackgroundColor(new ImagickPixel("transparent")); + $im->setBackgroundColor(new ImagickPixel('transparent')); $im->readImageBlob($result); - $im->setImageFormat("png32"); + $im->setImageFormat('png32'); $result = $im->getImageBlob(); $im->clear(); $im->destroy(); } - CacheManager::set('poloniex-'.$pair.'-'.$dataDuration.'-'.$format, $result, $dataDuration); + CacheManager::set($chartCacheKey, $result); $resultExpires = time() + $dataDuration; } else { - $resultExpires = CacheManager::getInfo('poloniex-'.$pair.'-'.$dataDuration.'-'.$format)[ 'expired_time' ]; + $resultExpires = CacheManager::getInfo($chartCacheKey)[ 'expired_time' ]; $startTime = $resultExpires - $dataDuration; } - header('Expires: '.gmdate("D, d M Y H:i:s", $resultExpires)); + header('Expires: '.gmdate('D, d M Y H:i:s', $resultExpires)); if ($format == 'svg') { header('Content-type: image/svg+xml; charset=utf-8'); header('Content-Disposition: inline; filename="Dash-chart-' . gmdate('Y-m-d\THis+0', $startTime) . '--' . gmdate('Y-m-d\THis+0') . '.svg"'); } else if ($format == 'png') { - header("Content-Type: image/png"); + header('Content-Type: image/png'); header('Content-Disposition: inline; filename="Dash-chart-' . gmdate('Y-m-d\THis+0', $startTime) . '--' . gmdate('Y-m-d\THis+0') . '.png"'); } echo $result; diff --git a/views/fakeStockData.php b/views/fakeStockData.php deleted file mode 100644 index d653ef4..0000000 --- a/views/fakeStockData.php +++ /dev/null @@ -1,23 +0,0 @@ -500, - "height"=>150, - "fontSize"=>10 -]); -print $stockChart->render(); - -?> diff --git a/views/fakeTempData.php b/views/fakeTempData.php deleted file mode 100644 index 64c8e31..0000000 --- a/views/fakeTempData.php +++ /dev/null @@ -1,24 +0,0 @@ -700, - "height"=>400, - "lineColor"=>"#D00", - "labelColor"=>"#777", - "smoothed"=>true -]); -print $tempChart->render(); -?> diff --git a/views/index.php b/views/index.php index 8c624a0..a0bae16 100644 --- a/views/index.php +++ b/views/index.php @@ -3,12 +3,10 @@ - NeatCharts demo + Embeddable Cryptocurrency Charts : Cryptohistory