GithubHelp home page GithubHelp logo

nvdnkpr / rickshaw Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shutterstock/rickshaw

1.0 0.0 0.0 1.23 MB

JavaScript toolkit for creating interactive real-time graphs

Home Page: http://code.shutterstock.com/rickshaw/

rickshaw's Introduction

Rickshaw

Rickshaw is a JavaScript toolkit for creating interactive time series graphs, developed at Shutterstock

Getting Started

Getting started with a simple graph is straightforward. Here's the gist:

var graph = new Rickshaw.Graph( {
  element: document.querySelector('#graph'),
  series: [
    {
      color: 'steelblue',
      data: [ { x: 0, y: 23}, { x: 1, y: 15 }, { x: 2, y: 79 } ],
    }, {
      color: 'lightblue',
      data: [ { x: 0, y: 30}, { x: 1, y: 20 }, { x: 2, y: 64 } ],
    }
  ]
} );

graph.render();

See the overview, tutorial, and examples for more.

Rickshaw.Graph

A 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()

element

A reference to an HTML element that should hold the graph.

series

Array of objects containing series data to plot. Each object should contain data at a minimum, an 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.

renderer

A string containing the name of the renderer to be used. Options include area, stack, bar, line, and scatterplot.

width

Width of the graph in pixels. Falls back to the width of the element, or defaults to 400 if the element has no width.

height

Height of the graph in pixels. Falls back to the height of the element, or defaults to 250 if the element has no height.

min

Lower value on the Y-axis, or auto for the lowest value in the series. Defaults to 0.

max

Highest value on the Y-axis. Defaults to the highest value in the series.

padding

An object containing any of top, right, bottom, and left properties specifying padding around the extrema of the data in the graph. Defaults to 0.01 on top for 1% padding, and 0 on other sides.

interpolation

Line smoothing / interpolation method (see D3 docs); notable options:

  • linear: straight lines between points
  • step-after: square steps from point to point
  • cardinal: smooth curves via cardinal splines (default)
  • basis: smooth curves via B-splines

Methods

Once you have instantiated a graph, call methods below to get pixels on the screen, change configuration, and set callbacks.

render()

Draw or redraw the graph.

configure()

Set 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.

onUpdate(f)

Add a callback to run when the graph is rendered

Extensions

Once you have a basic graph, extensions let you add functionality. See the overview and examples listing for more.

  • Rickshaw.Graph.Legend - add a basic legend

  • Rickshaw.Graph.HoverDetail - show details on hover

  • Rickshaw.Graph.JSONP - get data via a JSONP request

  • Rickshaw.Graph.Annotate - add x-axis annotations

  • Rickshaw.Graph.RangeSlider - dynamically zoom on the x-axis with a slider

  • Rickshaw.Graph.Axis.Time - add x-axis time labels

  • Rickshaw.Graph.Behavior.Series.Highlight - highlight series on legend hover

  • Rickshaw.Graph.Behavior.Series.Order - reorder series in the stack with drag-and-drop

  • Rickshaw.Graph.Behavior.Series.Toggle - toggle series on and off through the legend

Rickshaw.Color.Palette

Rickshaw 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.

var palette = new Rickshaw.Color.Palette( { scheme: 'spectrum2001' } );
    
palette.color() // => first color in the palette
palette.color() // => next color in the palette...

Color Schemes

  • classic9
  • colorwheel
  • cool
  • munin
  • spectrum14
  • spectrum2000
  • spectrum2001

Interpolation

For graphs with more series than palettes have colors, sepcify an interpolatedStopsCount to the palette constructor.

Rickshaw and Cross-Browser Support

This library works in modern browsers and Internet Explorer 9.

Rickshaw 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.

Dependencies & Building

Rickshaw relies on the fantastic D3 visualization library to do lots of the heavy lifting for stacking and rendering to SVG.

Some extensions require jQuery and jQuery UI, but for drawing some basic graphs you'll be okay without.

For building, we need Node and npm. Running 'make' should get you going with any luck.

Authors

This library was developed by David Chester, Douglas Hunter, and Silas Sewell at Shutterstock

License

Copyright (C) 2011 by Shutterstock Images, LLC

Permission 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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE 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.

rickshaw's People

Contributors

acmurthy avatar bkovacevich avatar dchester avatar gt8073a avatar kvisle avatar kyleconroy avatar mthenw avatar silas avatar tgolen avatar travisbeck avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.