diff --git a/composer.lock b/composer.lock index 3e3c960..7813473 100644 --- a/composer.lock +++ b/composer.lock @@ -135,12 +135,12 @@ "source": { "type": "git", "url": "https://github.com/seigler/neat-charts.git", - "reference": "f43540f78545765f411fb058f5e2fcce2ecde373" + "reference": "b04fc0416f826c4979c67328f74ec360235f8876" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/seigler/neat-charts/zipball/f43540f78545765f411fb058f5e2fcce2ecde373", - "reference": "f43540f78545765f411fb058f5e2fcce2ecde373", + "url": "https://api.github.com/repos/seigler/neat-charts/zipball/b04fc0416f826c4979c67328f74ec360235f8876", + "reference": "b04fc0416f826c4979c67328f74ec360235f8876", "shasum": "" }, "require": { @@ -171,7 +171,7 @@ "charts", "svg" ], - "time": "2016-07-01 21:57:14" + "time": "2016-07-02 05:39:52" } ], "packages-dev": [], diff --git a/index.php b/index.php index 2836adb..87cab78 100644 --- a/index.php +++ b/index.php @@ -18,7 +18,7 @@ $router->map('GET', '/', function() { }); // map cryptocurrency stuff -$router->map( 'GET', '/charts/[dark|light:theme]/[a:curA]-[btc:curB]/[a:duration]/[svg|png:format]', function($theme, $curA, $curB, $duration, $format) { +$router->map( 'GET', '/charts/[dark|light|sparkline:theme]/[a:curA]-[btc:curB]/[a:duration]/[svg|png:format]', function($theme, $curA, $curB, $duration, $format) { require __DIR__ . '/views/chart.php'; return renderChart( $theme, diff --git a/views/chart.php b/views/chart.php index 92be1e0..f5419e3 100644 --- a/views/chart.php +++ b/views/chart.php @@ -25,10 +25,7 @@ function renderChart( $currencyA, $currencyB, $duration, - $format = 'svg', - $width = 800, - $height = 200, - $fontSize = 12 + $format = 'svg' ) { $durations = [ @@ -50,6 +47,37 @@ function renderChart( ] ]; + $themes = [ + 'light'=>[ + 'lineColor'=>'#fff', + 'labelColor'=>'#fff', + 'width'=>800, + 'height'=>250, + 'smoothed'=>false, + 'fontSize'=>12 + ], + 'dark'=>[ + 'lineColor'=>'#000', + 'labelColor'=>'#000', + 'width'=>800, + 'height'=>250, + 'smoothed'=>false, + 'fontSize'=>12 + ], + 'sparkline'=>[ + 'lineColor'=>'#000', + 'width'=>100, + 'height'=>20, + 'fontSize'=>2, + 'yAxisEnabled'=>false, + 'xAxisEnabled'=>false + ] + ]; + + if (!array_key_exists($theme, $themes)) { + return false; + } + if (array_key_exists($duration, $durations)) { $dataDuration = $durations[$duration]['duration']; $dataResolution = $durations[$duration]['resolution']; @@ -95,14 +123,7 @@ function renderChart( $chartData[$item->date] = $item->weightedAverage; } - $poloniexChart = new NeatCharts\LineChart($chartData, [ - 'width'=>$width, - 'height'=>$height, - 'lineColor'=>($theme == 'dark' ? '#000' : '#fff'), - 'labelColor'=>($theme == 'dark' ? '#000' : '#fff'), - 'smoothed'=>false, - 'fontSize'=>$fontSize - ]); + $poloniexChart = new NeatCharts\LineChart($chartData, $themes[$theme]); $result = $poloniexChart->render(); if ($format == 'png') { diff --git a/views/index.php b/views/index.php index 942736c..610ceb6 100644 --- a/views/index.php +++ b/views/index.php @@ -7,27 +7,22 @@