Code Monkey home page Code Monkey logo

patternomaly's Introduction

Patternomaly

Easily generate patterns for use in data graphics.

Pattern example

But why?

Color-blindness, that's why.

This library came about as part of an issue in Chart.js.

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'
]);

Available Patterns

There are currently 21 pattern variants available. When using the generate method (above) patterns will be 'randomly' assigned.

It is however possible to provide specific patterns using the draw method.

datasets: [{
  data: [
    300, 50, 100, 210, 140
  ],
  backgroundColor: [
    pattern.draw('square', '#1f77b4'),
    pattern.draw('circle', '#ff7f0e'),
    pattern.draw('diamond', '#2ca02c'),
    pattern.draw('zigzag-horizontal', '#17becf'),
    pattern.draw('triangle', 'rgb(255, 99, 132, 0.4)') // with opacity
  ]
}]

Pattern Keys

  • plus
  • cross
  • dash
  • cross-dash
  • dot
  • dot-dash
  • disc
  • ring
  • line
  • line-vertical
  • weave
  • zigzag
  • zigzag-vertical
  • diagonal
  • diagonal-right-left
  • square
  • box
  • triangle
  • triangle-inverted
  • diamond
  • diamond-box

Pattern example

Thanks to obedm503 for generating the example pattern image.

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.

See the pattern option example page for a simple implementation of a pattern toggle switch for Chart.js.

Typescript / Angular

A typings file is included in this package. Just insert import {draw, generate} from 'patternomaly' in the header of your .ts file. Still you have to add the javascript file to your build e.g. in the scripts array in angular.cli.json e.g. "scripts": ["node_modules/patternomaly/dist/patternomaly.js"].

patternomaly's People

Contributors

ashiguruma avatar miller45 avatar mcelotti avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.