https://github.com/component/histogram
Create JavaScript image histograms with Canvas
https://github.com/component/histogram
Last synced: 7 months ago
JSON representation
Create JavaScript image histograms with Canvas
- Host: GitHub
- URL: https://github.com/component/histogram
- Owner: component
- Created: 2012-12-29T19:52:06.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-08-21T17:33:19.000Z (almost 12 years ago)
- Last Synced: 2024-05-08T17:12:09.124Z (about 1 year ago)
- Language: JavaScript
- Homepage: http://component.github.com/histogram/
- Size: 3.97 MB
- Stars: 45
- Watchers: 8
- Forks: 8
- Open Issues: 2
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
README
# histogram
JavaScript image histograms with Canvas.

## Installation
$ component install component/histogram
Or use without component:
$ component build --standalone histogram
## Example
```html
Histogram
.histogram {
background: #1a1a1a;
}
.histogram .channel {
opacity: .4;
}
.histogram .red {
color: #dc1e1a;
}
.histogram .green {
color: #12b81c;
}
.histogram .blue {
color: #46a3d6;
}
var histogram = require('histogram');
var canvas = document.querySelector('canvas');var img = document.createElement('img');
img.src = 'your img here';histogram(img)
.smooth(12)
.draw(canvas);
```
## Styling
By default the histogram will be completely black,
for example the following has only an opacity applied:
Using CSS you can style the canvas histogram however you like,
for example the following CSS:```css
.histogram .channel {
opacity: .4;
}
.histogram .red {
color: #dc1e1a;
}
.histogram .green {
color: #12b81c;
}
.histogram .blue {
color: #46a3d6;
}
```yields:

For the dark theme used in the first image on this page use:
```css
.histogram {
background: #1a1a1a;
}
.histogram .channel {
opacity: .4;
}
.histogram .red {
color: #dc1e1a;
}
.histogram .green {
color: #12b81c;
}
.histogram .blue {
color: #46a3d6;
}
```## Scaling
The histogram's size will adjust to fit the canvas size, so use whatever dimensions you prefer:

## API
### .smooth([n])
By default no smoothing is applied:

When invoked without arguments (`.smooth()`) the
default kernel of `6` is used:
You may also pass any kernel size you wish, here is `20` for
example:
## License
MIT