2.4.1 • Published 10 years ago

colorcoded-bar v2.4.1

Weekly downloads
3
License
MIT
Repository
github
Last release
10 years ago

colorcoded-bar

A colorcoded bar.

Example

screenshot

var Bar = require('colorcoded-bar');

// Vertical bar

(function(){
  var bar = new Bar();
  for (var i = 0; i < 100; i++) {
    bar.set(i, 'rgba(1, 1, 1, ' + i / 100 + ')');
  }
  document.body.appendChild(bar.render());
})();

// Horizontal bar

(function(){
  var bar = new Bar();
  for (var i = 0; i < 100; i++) {
    bar.set(i, 'rgba(1, 1, 1, ' + i / 100 + ')');
  }
  document.body.appendChild(bar.render({ horizontal: true }));
})();

// Automatic input scaling

(function(){
  var bar = new Bar();
  for (var i = 0; i < 10; i++) {
    bar.set(i, 'rgba(1, 1, 1, ' + i / 10 + ')');
  }
  document.body.appendChild(bar.render({ height: 200 }));
})();

// Pretty rainbows

(function(){
  var bar = new Bar();
  var height = 500;
  for (var i = 0; i < height; i++) {
    var color = 'hsl(' + Math.round(i / height * 360) + ', 100%, 50%)';
    bar.set(i, color);
  }
  document.body.appendChild(bar.render({ height: height }));
})();

view on requirebin

Installation

$ npm install colorcoded-bar

API

new Bar()

Create a new colorcoded bar.

#set(idx, color)

Set color at idx, any css supported color notation will work.

#render({ canvas, horizontal, height, width })

Render the bar, returning a canvas.

Options:

  • canvas: use an already existing canvas
  • horizontal: render from left to right instead of top to bottom
  • height / width: size the canvas. default: 100

License

MIT

2.4.1

10 years ago

2.4.0

10 years ago

2.3.0

10 years ago

2.2.3

10 years ago

2.2.2

10 years ago

2.2.1

10 years ago

2.2.0

10 years ago

2.1.0

10 years ago

2.0.0

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago