patternomaly
Advanced tools
Comparing version 1.1.0 to 1.2.0
{ | ||
"env": { | ||
"browser": true, | ||
"es6": true, | ||
"node": true | ||
"browser": true, | ||
"es6": true, | ||
"node": true, | ||
"mocha": true | ||
}, | ||
@@ -12,25 +13,28 @@ "globals": { | ||
"parserOptions": { | ||
"sourceType": "module" | ||
"sourceType": "module" | ||
}, | ||
"rules": { | ||
"indent": [ | ||
"error", | ||
2, | ||
{ | ||
"SwitchCase": 1 | ||
} | ||
], | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ | ||
"error", | ||
"single" | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
] | ||
"indent": [ | ||
"error", | ||
2, | ||
{ | ||
"SwitchCase": 1 | ||
} | ||
], | ||
"linebreak-style": [ | ||
"error", | ||
"unix" | ||
], | ||
"quotes": [ | ||
"error", | ||
"single" | ||
], | ||
"semi": [ | ||
"error", | ||
"always" | ||
], | ||
"prefer-arrow-callback": [ | ||
"error" | ||
] | ||
} | ||
} |
export { | ||
default as draw, | ||
draw, | ||
generate | ||
} from './src/patterns'; |
{ | ||
"name": "patternomaly", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Easily generate patterns for use in data graphics", | ||
"main": "dist/patterns.js", | ||
"browser": "dist/patterns.js", | ||
"jsnext:main": "index.js", | ||
"main": "dist/patternomaly.js", | ||
"jsnext:main": "dist/patternomaly.mjs", | ||
"scripts": { | ||
"prebuild": "npm run lint", | ||
"build": "rollup -c", | ||
"build:watch": "rollup -c -w", | ||
"pretest": "npm run build", | ||
"test": "mocha", | ||
"test:watch": "mocha -w", | ||
"prepublish": "npm test", | ||
"lint": "eslint src/ test/" | ||
}, | ||
"directories": { | ||
@@ -13,22 +22,17 @@ "test": "test" | ||
"devDependencies": { | ||
"babel-cli": "^6.11.4", | ||
"babel-preset-es2015": "^6.9.0", | ||
"babel-preset-es2015-rollup": "^1.1.1", | ||
"babel-tape-runner": "^2.0.1", | ||
"babel-eslint": "^6.1.2", | ||
"babel-plugin-external-helpers": "^6.8.0", | ||
"babel-preset-es2015": "^6.13.2", | ||
"babel-register": "^6.11.6", | ||
"babelrc-rollup": "^3.0.0", | ||
"canvas": "^1.4.0", | ||
"chai": "^3.5.0", | ||
"eslint": "^3.2.2", | ||
"faucet": "0.0.1", | ||
"rollup": "^0.26.3", | ||
"jsdom": "^9.8.3", | ||
"mocha": "^3.0.2", | ||
"rollup": "^0.34.7", | ||
"rollup-plugin-babel": "^2.6.1", | ||
"tape": "^4.5.1", | ||
"tape-run": "^2.1.4", | ||
"watch": "^0.19.1" | ||
"rollup-plugin-istanbul": "^1.0.0", | ||
"rollup-watch": "^2.5.0" | ||
}, | ||
"scripts": { | ||
"build": "rollup -c", | ||
"build:watch": "watch 'npm run build' src/ test/", | ||
"test": "npm run build && tape test/unit/**/*.js | faucet", | ||
"test:watch": "watch 'npm test' src/ test/", | ||
"lint": "eslint src/ test/" | ||
}, | ||
"author": { | ||
@@ -35,0 +39,0 @@ "name": "Tom Loudon", |
@@ -1,7 +0,5 @@ | ||
# Canvas patterns | ||
# Patternomaly | ||
Easily generate patterns for use in data graphics. | ||
npm install patternomaly | ||
<img src="./assets/example.png" alt="Pattern example" width="650"> | ||
@@ -14,1 +12,24 @@ | ||
This library came about as part of [an issue in Chart.js](https://github.com/chartjs/Chart.js/issues/1323). | ||
## Usage | ||
npm install patternomaly | ||
Generate a single canvas pattern | ||
pattern.draw('square', '#1f77b4'); | ||
Generate an array of canvas patterns | ||
pattern.generate([ | ||
'#1f77b4', | ||
'#ff7f0e', | ||
'#2ca02c', | ||
'#d62728' | ||
]); | ||
## Providing a Pattern Alternative | ||
In order to provide an alternative view for visually impaired viewers it's a good idea to [provide a patterned alternative](http://betweentwobrackets.com/data-graphics-and-colour-vision/#patternstotherescue). | ||
See the [pattern option example page](examples/optional.html) for a simple implementation of a pattern toggle switch for Chart.js. |
import babel from 'rollup-plugin-babel'; | ||
import babelrc from 'babelrc-rollup'; | ||
let pkg = require('./package.json'); | ||
export default { | ||
entry: 'index.js', | ||
dest: 'dist/patterns.js', | ||
format: 'umd', | ||
moduleName: 'pattern', | ||
plugins: [ | ||
babel({ | ||
exclude: 'node_modules/**' | ||
}) | ||
babel(babelrc()) | ||
], | ||
external: Object.keys(pkg.dependencies), | ||
targets: [ | ||
{ | ||
dest: pkg['main'], | ||
format: 'umd', | ||
moduleName: 'pattern', | ||
sourceMap: true | ||
}, | ||
{ | ||
dest: pkg['jsnext:main'], | ||
format: 'es', | ||
sourceMap: true | ||
} | ||
] | ||
}; |
@@ -1,4 +0,4 @@ | ||
import { default as shapes } from './shapes'; | ||
import shapes, { getRandomShape } from './shapes/index'; | ||
export default function draw ( | ||
export function draw ( | ||
shapeType = 'square', | ||
@@ -32,22 +32,21 @@ backgroundColor = 'rgba(100, 100, 100, 0.7)', | ||
export function generate(colorList) { | ||
let previousShapeType = null; | ||
let firstShapeType; | ||
let previousShapeType; | ||
return colorList.map((color) => { | ||
const shapeType = getRandomShape(previousShapeType); | ||
previousShapeType = shapeType; | ||
return colorList.map((color, index, list) => { | ||
let shapeType; | ||
if (index === 0) { | ||
shapeType = getRandomShape(); | ||
previousShapeType = shapeType; | ||
firstShapeType = previousShapeType; | ||
} else if (index === list.length - 1) { | ||
shapeType = getRandomShape([previousShapeType, firstShapeType]); | ||
} else { | ||
shapeType = getRandomShape([previousShapeType]); | ||
previousShapeType = shapeType; | ||
} | ||
return draw(shapeType, color); | ||
}); | ||
} | ||
function getRandomShape(excludedShapeType) { | ||
const shapesList = Object.keys(shapes); | ||
if (excludedShapeType !== null) { | ||
shapesList.splice(shapesList.indexOf(excludedShapeType), 1); | ||
} | ||
const randomIndex = Math.floor(Math.random() * shapesList.length); | ||
return shapesList[randomIndex]; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
376893
40
9408
35
14
1