Git Product home page Git Product logo

polygon.js's Introduction

polygon.js

Create polygons with text label. They are suitable for data visualization.

Examples

<canvas id="example"></canvas>
<script src="polygon.min.js"></script>
<script>
	let p = new Polygon({
		edges: 5,
		r: [40, 50, 60, 70, 80],
		bg: '#eef'
	});
	p.render({
		canvas: document.querySelector('#example'),
		animation: 800
	});
</script>

Click DEMO to try it!

Init options

let p = new Polygon(options);
  • options (type: Object)

    • edges (required, type: Number): edges of polygon

    • r (required, type: Number / Array of Number): pixels from origin to each vertex

    • rotate (type: Number, default: 0): clockwise rotation angle

    • bg (type: String / Array of String): color for each background

    • axis (type: String / Array of String): color for each axis

    • border (type: String / Array of String): color for each border

    • label (type: Array of Object): label on each vertex, example: [{text: 'text1', size: 20, color: 'red'}, ...]

Methods

  • render({canvas, merge, animation})

    • canvas (required, type: HTMLElement): polygon will render on this canvas

    • merge (type: Array of Polygon): draw multi polygon simultaneously

    • aniamtion (type: Number, default: 0): ms of animation

Tips

  • First axis is set on 12 o'clock direction, the rests would be set follow by clockwise. We can use parameter rotate to change it.

  • Parameter's type Number / Array or String / Array means we can set each item by Array or set single value to all items by Number / String.

  • If we don't need label for some vertices, use {} to skip them.

    for example:

      let p = new Polygon({
      	edges: 3,
      	...
      	label: [
      		{text: 'text1', size: 20, color: 'red'},
      		{},
      		{text: text3', size: 20, color: 'blue'},
      	]
      }) ;
    
  • render with parameter merge would draw multi concentric polygons simultaneously on one canvas. The render order is based on Array.

    for example:

      let p_bg = new Polygon({...});
      let p1 = new Polygon({...});
      let p2 = new Polygon({...});
      let p3 = new Polygon({...});
      p_bg.render({
      	...
      	merge: [p1, p2, p3]
      });
    

polygon.js's People

Contributors

nossika avatar

Watchers

 avatar  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.