replaceable markerColor

This commit is contained in:
Joshua Seigler 2016-07-03 04:03:34 -04:00
parent de6c5fd59a
commit 2f0ba32e13

View file

@ -49,8 +49,9 @@ function renderChart(
$themes = [ $themes = [
'light'=>[ 'light'=>[
'lineColor'=>'#fff', 'lineColor'=>'#FFF',
'labelColor'=>'#fff', 'markerColor'=>'#FFF',
'labelColor'=>'#FFF',
'width'=>800, 'width'=>800,
'height'=>250, 'height'=>250,
'smoothed'=>false, 'smoothed'=>false,
@ -58,6 +59,7 @@ function renderChart(
], ],
'dark'=>[ 'dark'=>[
'lineColor'=>'#000', 'lineColor'=>'#000',
'markerColor'=>'#000',
'labelColor'=>'#000', 'labelColor'=>'#000',
'width'=>800, 'width'=>800,
'height'=>250, 'height'=>250,
@ -66,6 +68,7 @@ function renderChart(
], ],
'sparkline'=>[ 'sparkline'=>[
'lineColor'=>'#000', 'lineColor'=>'#000',
'markerColor'=>'#F00',
'width'=>100, 'width'=>100,
'height'=>20, 'height'=>20,
'fontSize'=>2, 'fontSize'=>2,
@ -128,7 +131,7 @@ function renderChart(
} }
if ($format == 'svg') { if ($format == 'svg') {
$chartOptions = array_replace($themes[$theme], ['lineColor'=>'@lineColor']); $chartOptions = array_replace($themes[$theme], ['lineColor'=>'@lineColor', 'markerColor'=>'@markerColor']);
} }
$poloniexChart = new NeatCharts\LineChart($chartData, $chartOptions); $poloniexChart = new NeatCharts\LineChart($chartData, $chartOptions);
@ -148,6 +151,7 @@ function renderChart(
$resultExpires = time() + $cacheTimeSeconds; $resultExpires = time() + $cacheTimeSeconds;
} else { } else {
$resultExpires = CacheManager::getInfo($chartCacheKey)[ 'expired_time' ]; $resultExpires = CacheManager::getInfo($chartCacheKey)[ 'expired_time' ];
// TODO cache an object that has the data and a when-expired timestamp to avoid this cache-info lookup
$startTime = $resultExpires - $dataDuration; $startTime = $resultExpires - $dataDuration;
} }
@ -169,7 +173,18 @@ function renderChart(
} else { } else {
$lineColor = $themes[$theme]['lineColor']; $lineColor = $themes[$theme]['lineColor'];
} }
echo str_replace('@lineColor', $lineColor, $result);
if (array_key_exists('markerColor', $_GET)) {
$markerColor = htmlspecialchars($_GET['markerColor']);
if (1 === preg_match('/^[a-fA-F0-9]{3,6}/', $markerColor)) {
//this is an HTML color
$markerColor = '#' . $markerColor;
}
} else {
$markerColor = $themes[$theme]['markerColor'];
}
echo str_replace(['@lineColor', '@markerColor'], [$lineColor, $markerColor], $result);
} else { } else {
return false; return false;
} }