Skip to content

Commit

Permalink
Merge 1c57b3f into 7e14f8a
Browse files Browse the repository at this point in the history
  • Loading branch information
Munter committed Oct 20, 2018
2 parents 7e14f8a + 1c57b3f commit e590c7e
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"couch" : false, // CouchDB
"devel" : true, // Development/debugging (alert, confirm, etc)
"dojo" : false, // Dojo Toolkit
"jquery" : true, // jQuery
"jquery" : false, // jQuery
"mootools" : false, // MooTools
"node" : false, // Node.js
"nonstandard" : true, // Widely adopted globals (escape, unescape, etc)
Expand Down
12 changes: 1 addition & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
sudo: required
services:
- docker
language: node_js
cache:
directories:
- node_modules
node_js:
- "4"
- "6"
- "8"
addons:
apt:
packages:
- gcc-4.8
- g++-4.8
- libpango1.0-dev
- libgif-dev
env: CXX="g++-4.8" CC="gcc-4.8"
- "10"

script: "npm run-script travis"
after_success: "<coverage/lcov.info ./node_modules/coveralls/bin/coveralls.js"
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,3 @@ License
-------
This software is licensed under the beerware license. Do whatever you want with it.
If we meet some day, and you think this stuff is worth it, you can buy me a beer in return.


[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/Munter/node-histogram/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

10 changes: 7 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
(function () {
var Canvas,
Image,
getCanvasImageData = function (imageBuffer, callback) {
var canvasImage = new Canvas.Image();
var canvasImage = new Image();
canvasImage.crossOrigin = 'Anonymous';

canvasImage.onerror = function () {
callback(new Error('error while reading from input stream'));
Expand Down Expand Up @@ -108,7 +110,9 @@

if (typeof exports === 'object') {
// Assume nodejs
Canvas = require('canvas');
var canvasPrebuilt = require('canvas-prebuilt');
Canvas = canvasPrebuilt.Canvas;
Image = canvasPrebuilt.Image;
module.exports = histogram;
} else {
// Polyfill canvas constructor
Expand All @@ -119,7 +123,7 @@

return canvas;
};
Canvas.Image = Image;
Image = window.Image;

if (typeof define === 'function') {
// AMD module
Expand Down
33 changes: 14 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,24 @@
],
"main": "lib/index.js",
"dependencies": {
"canvas": "^1.6.7"
"canvas-prebuilt": "2.0.0-alpha.14"
},
"devDependencies": {
"coveralls": "^2.11.9",
"istanbul": "^0.4.3",
"jshint": "^2.9.2",
"mocha": "^3.0.2",
"mocha-lcov-reporter": "^1.2.0",
"mocha-phantomjs-core": "^2.0.1",
"phantomjs-prebuilt": "^2.1.15",
"uglify-js": "^2.6.2",
"unexpected": "^10.13.3"
},
"optionalDependencies": {},
"engines": {
"node": "*"
"coveralls": "^3.0.2",
"jshint": "^2.9.6",
"mocha": "^5.2.0",
"mocha-chrome": "^1.1.0",
"nyc": "^13.1.0",
"uglify-js": "^3.4.9",
"unexpected": "^10.39.1"
},
"scripts": {
"lint": "jshint .",
"phantom": "phantomjs ./node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js test/global.html spec \"`node -pe 'JSON.stringify({useColors:true,grep:process.env.grep})'`\"",
"test": "npm run lint && mocha && npm run phantom",
"preversion": "uglifyjs lib/index.js -m -c > histogram.min.js && git add histogram.min.js",
"travis": "npm run lint && npm run coverage",
"coverage": "istanbul cover _mocha"
"browser-test": "mocha-chrome test/global.html --chrome-flags '[\"--allow-file-access-from-files\"]'",
"node-test": "mocha",
"test": "npm run lint && npm run node-test && npm run browser-test",
"coverage": "nyc --reporter=lcov --reporter=text mocha",
"travis": "npm run lint && npm run coverage && npm run browser-test",
"preversion": "npm t && uglifyjs lib/index.js -m -c > histogram.min.js && git add histogram.min.js"
}
}
7 changes: 2 additions & 5 deletions test/global.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<html>
<head>
<title>Mocha</title>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../node_modules/mocha/mocha.css" />
</head>
Expand All @@ -12,11 +13,7 @@
<script src="../lib/index.js"></script>
<script src="histogram.js"></script>
<script>
if (window.mochaPhantomJS) {
mochaPhantomJS.run();
} else {
mocha.run();
}
mocha.run();
</script>
</body>
</html>
50 changes: 40 additions & 10 deletions test/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,48 @@ describe('Histogram of gradient.png', function () {

it('should be greyscale', function (done) {
histogram(path, function (error, result) {
expect(result.greyscale, 'to be true');
expect(error, 'to be falsy');

expect(result, 'to satisfy', {
greyscale: true
});

done();
});
});

it('should have an alpha channel', function (done) {
histogram(path, function (error, result) {
expect(result.alphachannel, 'to be true');
expect(error, 'to be falsy');
expect(result, 'to satisfy', {
alphachannel: true
});

done();
});
});

it('should have 256 alpha channel colors', function (done) {
it('should have 256 rgba colors', function (done) {
histogram(path, function (error, result) {
expect(result.colors.rgba, 'to be', 256);
expect(error, 'to be falsy');
expect(result, 'to satisfy', {
colors: {
rgba: 256
}
});

done();
});
});

it('should have 1 rgba color', function (done) {
it('should have 1 rgb color', function (done) {
histogram(path, function (error, result) {
expect(result.colors.rgb, 'to be', 1);
expect(error, 'to be falsy');
expect(result, 'to satisfy', {
colors: {
rgb: 1
}
});

done();
});
Expand All @@ -69,30 +86,43 @@ describe('Histogram of gradient-red.png', function () {

it('should be greyscale', function (done) {
histogram(path, function (error, result) {
expect(result.greyscale, 'to be false');
expect(error, 'to be falsy');

expect(result, 'to satisfy', {
greyscale: false
});

done();
});
});

it('should have an alpha channel', function (done) {
histogram(path, function (error, result) {
expect(result.alphachannel, 'to be true');
expect(error, 'to be falsy');

expect(result, 'to satisfy', {
alphachannel: true
});

done();
});
});

it('should have 256 alpha channel colors', function (done) {
histogram(path, function (error, result) {
expect(result.colors.rgba, 'to be', 256);
expect(error, 'to be falsy');

expect(result, 'to satisfy', {
colors: {
rgba: 256
}
});

done();
});
});
});


describe('Histogram of cablecar.gif', function () {
var path = imagePath + 'cablecar.gif';

Expand Down

0 comments on commit e590c7e

Please sign in to comment.