fixed caching, increased duration choices

This commit is contained in:
Joshua Seigler 2016-07-02 00:30:02 -04:00
parent 46764e6879
commit c476b92a68
2 changed files with 18 additions and 14 deletions

View file

@ -32,17 +32,21 @@ function renderChart(
) { ) {
$durations = [ $durations = [
// '30d'=> [ '1y'=> [
// 'duration' => 60 * 60 * 24 * 30, 'duration' => 60 * 60 * 24 * 365,
// 'resolution' => 7200 // 2h 'resolution' => 86400 // 1d
// ], ],
'30d'=> [
'duration' => 60 * 60 * 24 * 30,
'resolution' => 7200 // 2h
],
'7d'=> [ '7d'=> [
'duration' => 60 * 60 * 24 * 7, 'duration' => 60 * 60 * 24 * 7,
'resolution' => 1800 // 30m 'resolution' => 1800 // 30m
], ],
'24h' => [ '24h' => [
'duration' => 60 * 60 * 24 * 1, 'duration' => 60 * 60 * 24 * 1,
'resolution' => 900 // 15m 'resolution' => 300 // 15m
] ]
]; ];
@ -92,12 +96,12 @@ function renderChart(
} }
$poloniexChart = new NeatCharts\LineChart($chartData, [ $poloniexChart = new NeatCharts\LineChart($chartData, [
'width'=>800, 'width'=>$width,
'height'=>200, 'height'=>$height,
'lineColor'=>($theme == 'dark' ? '#000' : '#fff'), 'lineColor'=>($theme == 'dark' ? '#000' : '#fff'),
'labelColor'=>($theme == 'dark' ? '#000' : '#fff'), 'labelColor'=>($theme == 'dark' ? '#000' : '#fff'),
'smoothed'=>false, 'smoothed'=>false,
'fontSize'=>12 'fontSize'=>$fontSize
]); ]);
$result = $poloniexChart->render(); $result = $poloniexChart->render();
@ -110,7 +114,7 @@ function renderChart(
$im->clear(); $im->clear();
$im->destroy(); $im->destroy();
} }
CacheManager::set($chartCacheKey, $result); CacheManager::set($chartCacheKey, $result, $dataResolution);
$resultExpires = time() + $dataResolution; $resultExpires = time() + $dataResolution;
} else { } else {
$resultExpires = CacheManager::getInfo($chartCacheKey)[ 'expired_time' ]; $resultExpires = CacheManager::getInfo($chartCacheKey)[ 'expired_time' ];

View file

@ -77,8 +77,8 @@
<section> <section>
<h2>SVG and PNG charts with your favorite cryptocurrencies</h2> <h2>SVG and PNG charts with your favorite cryptocurrencies</h2>
<figure> <figure>
<img src="/charts/light/dash-btc/7d/svg" alt="Poloniex Dash/BTC price"> <img src="/charts/light/dash-btc/30d/svg" alt="Poloniex Dash/BTC price">
<figcaption>7 Day Dash price in BTC <code>http://cryptohistory.org/charts/light/dash-btc/7d/svg</code></figcaption> <figcaption>30 Day Dash price in BTC <code>http://cryptohistory.org/charts/light/dash-btc/30d/svg</code></figcaption>
</figure> </figure>
</section> </section>
<section> <section>
@ -87,14 +87,14 @@
<code>http://cryptohistory.org/charts/{theme}/{currency}-btc/{timespan}/{format}</code></p> <code>http://cryptohistory.org/charts/{theme}/{currency}-btc/{timespan}/{format}</code></p>
<p>Theme: <code>dark</code> or <code>light</code>. (More planned)</p> <p>Theme: <code>dark</code> or <code>light</code>. (More planned)</p>
<p>Currency: anything active on Poloniex. Prices are all in bitcoin.</p> <p>Currency: anything active on Poloniex. Prices are all in bitcoin.</p>
<p>Timespan: <code>7d</code> or <code>24h</code>. (More planned)</p> <p>Timespan: <code>1y</code>, <code>30d</code>, <code>7d</code>, or <code>24h</code>.</p>
<p>Format: <code>svg</code> (best) or <code>png</code>.</p> <p>Format: <code>svg</code> (best) or <code>png</code>.</p>
</section> </section>
<section> <section>
<h2>Examples:</h2> <h2>Examples:</h2>
<p>Ethereum 24h, dark SVG: <code><a href="/charts/dark/eth-btc/24h/svg" target="_blank">http://cryptohistory.org/charts/dark/eth-btc/24h/svg</a></code></p> <p>Ethereum 24h, dark SVG: <code><a href="/charts/dark/eth-btc/24h/svg" target="_blank">http://cryptohistory.org/charts/dark/eth-btc/24h/svg</a></code></p>
<p>Litecoin 7d, light colored PNG: <code><a href="/charts/dark/ltc-btc/7d/png" target="_blank">http://cryptohistory.org/charts/dark/ltc-btc/7d/png</a></code></p> <p>Litecoin 30d, light colored PNG: <code><a href="/charts/dark/ltc-btc/7d/png" target="_blank">http://cryptohistory.org/charts/dark/ltc-btc/30d/png</a></code></p>
<p>Factom 7d, dark SVG: <code><a href="/charts/dark/fct-btc/24h/svg" target="_blank">http://cryptohistory.org/charts/dark/fct-btc/24h/svg</a></code></p> <p>Doge 1y, dark SVG: <code><a href="/charts/dark/fct-btc/24h/svg" target="_blank">http://cryptohistory.org/charts/dark/doge-btc/30d/svg</a></code></p>
</section> </section>
</main> </main>
<footer> <footer>