Small server-generated graphs of Guardian content page-views. Uses Ophan data.
If the number of data points is greater than the width of the graph, the points are resampled to fit. If the number of data points is less than the width, the graph is right-justified (so "now" aligns for vertically stacked graphs) and it's width is partially stretched to make the graph more readable. Smoothing is applied, and can be adjusted.
It's useful to specify a
hotLevel that reflects "significant page views per minute" for the type of content in question. This sets the upper y-scale of the graph. Activity beyond this level causes all the graph lines to compress down proportionally.
/ URL displays a form for experimenting with options and producing example Sparkline URLs. Images are served from URLs starting
All parameters are optional.
page : url of the Guardian content. Only the pathname part is used. Default is the empty string.
graphs : comma-separated names of dataseries from the Ophan breakdown, with optional hex colours (after a colon), e.g.
twitter:6666ff,facebook:000099. The following are in Ophan at time of writing:
unknown - to content
unknown - to front
Also supported is
total, which is the default.
markers : comma-separated vertical markers, as unix timestamps, with optional hex colours (after a colon), e.g.
width : in pixels. Default is
height : in pixels. Default is
showStats : show the total hits counter, when set to
1. Default is
showHours : show the elapsed hour markers, when set to
1. Default is
hotLevel: upper y-bound of the graph, in pageviews-per-minute. Beyond this, the whole graph compresses vertically. Default is
50which is appropriate for articles; fronts need a much higher figure. Recent activity beyond this level causes a bold graph line (and a half-bold line at half this level).
hotPeriod : number of minutes over which to calcuate the "recent activity". Default is
alpha : opacity of the graph lines. Range from 0 - 1. Default is
smoothing : number of points over which a moving average is computed, for smoothing. For larger graph widths this can be worth increasing. Default is
Requires Node and Cairo.
$ npm install
Create a file called
ophanKey properties (see
Running on port 80
To rewrite port 80 to port 8080 (or whatever) without using nginx, do this:
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
Add it (minus sudo) to
/etc/rc.local so that it happens on a reboot.
As a persistent background process
$ npm install forever -g
Start the app:
forever start ~/ophan-sparklines/app.js