balain / bullet-p5js

Create a highly customizable bullet chart using p5.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bullet-p5js

Create a bullet graph, based on Stephen Few's spec

Example Graphs

Sample

Built With

Features

  • URL parameter-driven display
  • Simple installation (one js file, bullet.js)
  • Easy to use - most values have reasonable defaults

Usage

  • Download bullet.js
  • Create a simple P5.js page (index.html is provided as an example)
  • Serve the index.html from a standard web server (local or remote) [n.b. opening it as a local file also works]
  • Open the index.html
  • Pass in parameters to configure the graph
    • Required
      • val: Bar's value (no default)
    • Optional
      • label: Text label (default: empty string)
      • max: Maximum value of the graph (default: 100)
      • bins: Number of quantitative groups (default: 4)
      • width: Width (in pixels) of the entire canvas (in pixels; default: 400)
      • height: Height (in pixels) of the canvas (in pixels; default: 30)
      • barHeight: Value bar height (in pixels; default: 20)
      • fontSize: Label font size (default: 12)
      • cross: Cross-bar value (not displayed by default)

Note: All defaults are defined at the top of bullet.js

Example

Example URLs and graphs

Value (here: 80; N.B. this is the only required setting)

Sample

Custom label (here: 'Simple label'; default: no label)

Sample

Crossbar (here: at 37; default: no crossbar)

Sample

Custom bin count (here: 3; default: 4)

Sample

Custom maximum value (here: 150; default: 100)

Sample

Custom canvas height (here: 50; default: 30)

Sample

Custom bar height (here: 10; default: 20)

Sample

Custom font size (here: 10; default: 12)

Sample

Minimal HTML File

<!DOCTYPE html>
<html lang="en">
<head>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.1.9/p5.min.js"></script>
  <script src="./js/bullet.js"></script>
</head>
<body>
<script>
  let bullet // bullet chart object
  let canvas // canvas
  function setup() {
    const val = 33
    // Simplest chart - just the single value is passed in
    bullet = new Bullet(val)
    // All available settings (only `val` is required)
    // bullet = new Bullet(val, decodeURIComponent(label), max, bins, width, height,barHeight,fontSize)
    canvas = createCanvas(bullet.getWidth(), bullet.getHeight())
    bullet.display() // Show the chart
    noLoop()  // Do not execute the draw() method
  }
</script>
</body>
</html>

Hacking

  • Clone the repo
git clone https://github.com/balain/bullet-p5js

Prerequisites

None. (P5.js is loaded from the index.html file)

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Project Link: https://github.com/balain/bullet-p5js

Acknowledgements

About

Create a highly customizable bullet chart using p5.js

License:MIT License


Languages

Language:JavaScript 75.2%Language:HTML 24.8%