Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improved static chart export

  • Loading branch information...
commit c594cbf83a622b7b46536eeba2cdb659a637bf19 1 parent 604451a
@gka gka authored
Showing with 50 additions and 10 deletions.
  1. +48 −0 scripts/export_chart.js
  2. +2 −10 scripts/export_charts.php
View
48 scripts/export_chart.js
@@ -0,0 +1,48 @@
+var page = require('webpage').create(),
+ system = require('system'),
+ address, output, size, format, orient;
+
+
+
+if (system.args.length < 3 || system.args.length > 5) {
+ console.log('Usage: rasterize.js URL filename [format]');
+ console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
+ phantom.exit(1);
+} else {
+ address = system.args[1];
+ output = system.args[2];
+ format = system.args[3];
+
+ if (output.substr(-4) === ".pdf") {
+ page.viewportSize = {
+ 'landscape': { width: 1500, height: 1050 },
+ 'portrait': { width: 1150, height: 1300 },
+ 'square': { width: 1300, height: 1200 }
+ }[format];
+ page.paperSize = {
+ 'landscape': { width: '27cm', height: '20cm' },
+ 'portrait': { width: '24cm', height: '27cm' },
+ 'square': { width: '27cm', height: '27cm' }
+ }[format];
+ page.zoomFactor = 1.2;
+ } else {
+ page.zoomFactor = 2;
+ page.viewportSize = {
+ 'landscape': { width: 1600, height: 1200 },
+ 'portrait': { width: 1300, height: 1600 },
+ 'square': { width: 1500, height: 1500 }
+ }[format];
+ }
+
+ page.open(address, function (status) {
+ if (status !== 'success') {
+ console.log('Unable to load the address!');
+ phantom.exit();
+ } else {
+ window.setTimeout(function () {
+ page.render(output);
+ phantom.exit();
+ }, 200);
+ }
+ });
+}
View
12 scripts/export_charts.php
@@ -51,20 +51,12 @@
foreach ($jobs as $job) {
$params = json_decode($job['parameter'], true);
- $dim = array(
- 'landscape' => array(1200,700),
- 'portrait' => array(800,1000),
- 'square' => array(900,900)
- );
- $w = $dim[$params['ratio']][0];
- $h = $dim[$params['ratio']][1];
-
- $url = 'http://' . $cfg['domain'] . '/chart/' . $job['chart_id'] . '/?fs=1';
+ $url = 'http://' . $cfg['domain'] . '/chart/' . $job['chart_id'] . '/' . ($params['format'] == 'pdf' ? '?fs=1' : '');
$outfile = '../charts/exports/' . $job['chart_id'] . '-' . $params['ratio'] . '.' . $params['format'];
$out = array();
- $cmd = $cfg['phantomjs']['path'] . ' render.js '. $url.' '.$outfile.' '.$w.' '.$h;
+ $cmd = $cfg['phantomjs']['path'] . ' export_chart.js '. $url.' '.$outfile.' '.$params['ratio'];
//print "\n".'running '.$cmd;
exec($cmd, $out);
Please sign in to comment.
Something went wrong with that request. Please try again.