1# Rickshaw 2 3Rickshaw is a JavaScript toolkit for creating interactive time series graphs, developed at [Shutterstock](http://www.shutterstock.com) 4 5## Getting Started 6 7Getting started with a simple graph is straightforward. Here's the gist: 8 9```javascript 10var graph = new Rickshaw.Graph( { 11 element: document.querySelector('#graph'), 12 series: [ 13 { 14 color: 'steelblue', 15 data: [ { x: 0, y: 23}, { x: 1, y: 15 }, { x: 2, y: 79 } ] 16 }, { 17 color: 'lightblue', 18 data: [ { x: 0, y: 30}, { x: 1, y: 20 }, { x: 2, y: 64 } ] 19 } 20 ] 21} ); 22 23graph.render(); 24``` 25See the [overview](http://code.shutterstock.com/rickshaw/), [tutorial](http://shutterstock.github.com/rickshaw/tutorial/introduction.html), and [examples](http://shutterstock.github.com/rickshaw/examples/) for more. 26 27## Rickshaw.Graph 28 29A Rickshaw graph. Send an `element` reference, `series` data, and optionally other properties to the constructor before calling `render()` to point the graph. A listing of properties follows. Send these as arguments to the constructor, and optionally set them later on already-instantiated graphs with a call to `configure()` 30 31##### element 32 33A reference to an HTML element that should hold the graph. 34 35##### series 36 37Array of objects containing series data to plot. Each object should contain `data` at a minimum, a sorted array of objects each with x and y properties. Optionally send a `name` and `color` as well. Some renderers and extensions may also support additional keys. 38 39##### renderer 40 41A string containing the name of the renderer to be used. Options include `area`, `stack`, `bar`, `line`, and `scatterplot`. Also see the `multi` meta renderer in order to support different renderers per series. 42 43##### width 44 45Width of the graph in pixels. Falls back to the width of the `element`, or defaults to 400 if the element has no width. 46 47##### height 48 49Height of the graph in pixels. Falls back to the height of the `element`, or defaults to 250 if the element has no height. 50 51##### min 52 53Lower value on the Y-axis, or `auto` for the lowest value in the series. Defaults to 0. 54 55##### max 56 57Highest value on the Y-axis. Defaults to the highest value in the series. 58 59##### padding 60 61An object containing any of `top`, `right`, `bottom`, and `left` properties specifying a padding percentage around the extrema of the data in the graph. Defaults to 0.01 on top for 1% padding, and 0 on other sides. Padding on the bottom only applies when the `yMin` is either negative or `auto`. 62 63##### interpolation 64 65Line smoothing / interpolation method (see [D3 docs](https://github.com/mbostock/d3/wiki/SVG-Shapes#wiki-line_interpolate)); notable options: 66 67 * `linear`: straight lines between points 68 * `step-after`: square steps from point to point 69 * `cardinal`: smooth curves via cardinal splines (default) 70 * `basis`: smooth curves via B-splines 71 72##### stack 73 74Boolean to specify whether series should be stacked while in the context of stacking renderers (area, bar, etc). Defaults to true. 75 76### Methods 77 78Once you have instantiated a graph, call methods below to get pixels on the screen, change configuration, and set callbacks. 79 80##### render() 81 82Draw or redraw the graph. 83 84##### configure() 85 86Set properties on an instantiated graph. Specify any properties the constructor accepts, including `width` and `height` and `renderer`. Call `render()` to redraw the graph and reflect newly-configured properties. 87 88##### onUpdate(f) 89 90Add a callback to run when the graph is rendered 91 92 93## Extensions 94 95Once you have a basic graph, extensions let you add functionality. See the [overview](http://code.shutterstock.com/rickshaw/) and [examples](http://shutterstock.github.com/rickshaw/examples/) listing for more. 96 97* __Rickshaw.Graph.Legend__ - add a basic legend 98 99* __Rickshaw.Graph.HoverDetail__ - show details on hover 100 101* __Rickshaw.Graph.JSONP__ - get data via a JSONP request 102 103* __Rickshaw.Graph.Annotate__ - add x-axis annotations 104 105* __Rickshaw.Graph.RangeSlider__ - dynamically zoom on the x-axis with a slider 106 107* __Rickshaw.Graph.RangeSlider.Preview__ - pan and zoom via graphical preview of entire data set 108 109* __Rickshaw.Graph.Axis.Time__ - add an x-axis and grid lines with time labels 110 111* __Rickshaw.Graph.Axis.X__ - add an x-axis and grid lines with arbitrary labels 112 113* __Rickshaw.Graph.Axis.Y__ - add a y-axis and grid lines 114 115* __Rickshaw.Graph.Axis.Y.Scaled__ - add a y-axis with an alternate scale 116 117* __Rickshaw.Graph.Behavior.Series.Highlight__ - highlight series on legend hover 118 119* __Rickshaw.Graph.Behavior.Series.Order__ - reorder series in the stack with drag-and-drop 120 121* __Rickshaw.Graph.Behavior.Series.Toggle__ - toggle series on and off through the legend 122 123 124## Rickshaw.Color.Palette 125 126Rickshaw comes with a few color schemes. Instantiate a palette and specify a scheme name, and then call color() on the palette to get each next color. 127 128```javascript 129var palette = new Rickshaw.Color.Palette( { scheme: 'spectrum2001' } ); 130 131palette.color() // => first color in the palette 132palette.color() // => next color in the palette... 133``` 134 135#### Color Schemes 136 137 * classic9 138 * colorwheel 139 * cool 140 * munin 141 * spectrum14 142 * spectrum2000 143 * spectrum2001 144 145#### Interpolation 146 147For graphs with more series than palettes have colors, specify an `interpolatedStopCount` to the palette constructor. 148 149## Rickshaw and Cross-Browser Support 150 151This library works in modern browsers and Internet Explorer 9+. 152 153Rickshaw relies on the HTMLElement#classList API, which isn't natively supported in Internet Explorer 9. Rickshaw adds support by including a shim which implements the classList API by extending the HTMLElement prototype. You can disable this behavior if you like, by setting `RICKSHAW_NO_COMPAT` to a true value before including the library. 154 155 156## Dependencies 157 158Rickshaw relies on the fantastic [D3 visualization library](http://mbostock.github.com/d3/) to do lots of the heavy lifting for stacking and rendering to SVG. 159 160Some extensions require [jQuery](http://jquery.com) and [jQuery UI](http://jqueryui.com), but for drawing some basic graphs you'll be okay without. 161 162## Building 163 164For building, we need [Node](http://nodejs.org) and [npm](http://npmjs.org). Running `make` should get you going with any luck. 165 166After doing a build you can run the tests with the command: `npm test` 167 168If you'd like to do your own minification, you will need to give a hint to the minifier to leave variables named `$super` named `$super`. For example, with uglify on the command line: 169 170``` 171$ uglify-js --reserved-names "$super" rickshaw.js > rickshaw.min.js 172``` 173 174Or a sample configuration with `grunt-contrib-uglify`: 175 176```javascript 177uglify: { 178 options: { 179 mangle: { except: ["$super"] } 180 } 181} 182``` 183 184## Contributing 185 186Pull requests are always welcome! Please follow a few guidelines: 187 188- Please don't include updated versions of `rickshaw.js` and `rickshaw.min.js`. Just changes to the source files will suffice. 189- Add a unit test or two to cover the proposed changes 190- Do as the Romans do and stick with existing whitespace and formatting conventions (i.e., tabs instead of spaces, etc) 191- Consider adding a simple example under `examples/` that demonstrates any new functionality 192 193## Authors 194 195This library was developed by David Chester, Douglas Hunter, and Silas Sewell at [Shutterstock](http://www.shutterstock.com) 196 197 198## License 199 200Copyright (C) 2011-2013 by Shutterstock Images, LLC 201 202Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 203 204The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 205 206THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 207 208