diff --git a/views/chart.php b/views/chart.php index 5ffdeff..9ec7dc7 100644 --- a/views/chart.php +++ b/views/chart.php @@ -127,7 +127,11 @@ function renderChart( $chartData[$item->date] = $item->weightedAverage; } - $poloniexChart = new NeatCharts\LineChart($chartData, $themes[$theme]); + if ($format == 'svg') { + $chartOptions = array_replace($themes[$theme], ['lineColor'=>'@lineColor']); + } + + $poloniexChart = new NeatCharts\LineChart($chartData, $chartOptions); $result = '' . PHP_EOL; $result .= $poloniexChart->render(); @@ -148,13 +152,26 @@ function renderChart( } header('Expires: '.gmdate(DateTime::RFC1123, $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') { + if ($format == '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; + } else 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"'); + + if (array_key_exists('lineColor', $_GET)) { + $lineColor = htmlspecialchars($_GET['lineColor']); + if (1 === preg_match('/^[a-fA-F0-9]{3,6}/', $lineColor)) { + //this is an HTML color + $lineColor = '#' . $lineColor; + } + } else { + $lineColor = $themes[$theme]['lineColor']; + } + echo str_replace('@lineColor', $lineColor, $result); + } else { + return false; } - echo $result; return true; } diff --git a/views/index.php b/views/index.php index a69ba51..1476066 100644 --- a/views/index.php +++ b/views/index.php @@ -72,8 +72,8 @@

Transparent SVG and PNG charts with your favorite cryptocurrencies

- Poloniex Dash/BTC price -
30 Day Dash price in BTC http://cryptohistory.org/charts/dark/dash-btc/30d/svg
+ Poloniex Dash/BTC price +
30 Day Dash price in BTC http://cryptohistory.org/charts/dark/dash-btc/30d/svg?lineColor=1C74BC

Sparklines too! ETH 7 days: ETH 7d chart <img src="http://cryptohistory.org/charts/sparkline/eth-btc/7d/svg" alt="ETH 7d chart" style="vertical-align: bottom;"> @@ -86,13 +86,15 @@

Theme: dark, light, or sparkline.

Currency: anything active on Poloniex. Prices are all in bitcoin.

Timespan: 1y, 30d, 7d, or 24h.

-

Format: svg (best) or png.

+

Format: svg (best) or png.
+ If you use svg format, you can add ?lineColor= to the end of the URL for a custom plot-line color. +

Examples:

Ethereum 24h, dark SVG: http://cryptohistory.org/charts/dark/eth-btc/24h/svg

Litecoin 30d, light PNG: http://cryptohistory.org/charts/light/ltc-btc/30d/png

-

Doge 1y, dark SVG: http://cryptohistory.org/charts/dark/doge-btc/1y/svg

+

Doge 1y, dark SVG, yellow line: http://cryptohistory.org/charts/dark/doge-btc/1y/svg?lineColor=BB9F32