svg-donuts
v0.0.1
Published
A small, dependency-free micro-library for generating SVG donut charts.
Downloads
5
Maintainers
Readme
SVG Donuts
A small, dependency-free micro-library for generating SVG donut charts.
Features
- ...
- A UMD library that works in the browser or as an AMD/CommonJS module
- Lightweight (4.8k minified + gzipped) and dependency free
Defaults
...
// Root element is a <div> when root.wrapper = true.
// If root.wrapper = false, root element is the generated SVG element.
// A wrapper element is required for fluid SVGs in IE.
root: {
class : null,
description: null,
fixed : false,
id : null,
minHeight : null,
minWidth : null,
style : null,
title : null,
wrapper : true
},
paths: {
// Default values for all items in paths.data
// Use same values on path.data objects to override
animateOpacity : true,
animateStroke : true,
animateStrokeReverse: false,
animateDelay : 0,
animateDuration : 0.5,
animateStagger : 0,
animateTiming : 'ease-in-out',
class : null,
colors : '#808080',
dashArray : null,
diameter : 200,
end : null,
gap : 0,
hoverColors : null,
hoverWidth : 25,
hoverDuration : 0.3,
lineCap : null,
opacity : 1,
start : 0,
style : null,
width : 15,
data: [
// paths.data accepts an integer, an array of integers, or an array of objects
// Ex1: data: 3
// Ex2: data: [1, 2, 3]
// Ex3: data: [
// { text: 'foo' },
// { text: 'bar', color: 'green' },
// { text: 'baz', color: 'blue' },
// ]
// Ex4: data: [
// { size: 1, text: 'foo' },
// { size: 2, text: 'bar', color: 'green' },
// { size: 3, text: 'baz', color: 'blue' },
// ]
]
},
text: {
// Default values for all items in text.data
// Use same values on text.data objects to override
class : null,
colors : 'currentColor',
fontFamily : null,
fontStyle : null,
fontSize : null,
fontVariant : null,
fontWeight : null,
lineHeight : 1.2,
opacity : 1,
style : null,
textAlign : 'center', // left|right|center
textDecoration: null,
textTransform : null,
wordSpacing : null,
width : null,
x : 'center', // left|right|center
y : 'center', // above|top|center|bottom|below
data: [
// text.data accepts a string, an array of strings, or an array of objects
// Ex1: data: 'Foo'
// Ex2: data: ['Foo', 'Bar', 'Baz']
// Ex3: data: [
// { text: 'foo' },
// { text: 'bar', color: 'green' },
// { text: 'baz', color: 'blue' },
// ]
]
}
Usage
...
var myDonut = svgDonut({
root: {
class : 'myclass',
description: 'A description of my SVG donut chart',
fixed : false,
style : 'font-family: sans-serif; font-size: 0.75rem; color: #333',
title : 'The title of my SVG donut chart to display as a tooltip on mouseover',
wrapper : true
},
paths: {
animateDelay : 0,
animateDuration: 1,
animateStagger : 0.5,
animateTiming : 'ease-out',
class : 'my-pathclass',
colors : ['red', 'orange', 'green', 'blue'],
diameter : 300,
gap : 1,
hoverColors : ['darkred', 'darkorange', 'darkgreen', 'darkblue'],
width : 20,
data: [
{ size : 1, title: 'foo'},
{ size : 2, title: 'bar'},
{ size : 3, title: 'baz'}
]
},
text: {
class : 'my-textclass',
colors : ['white', 'gray'],
fontFamily : 'sans-serif',
fontSize : 14,
lineHeight : 1.4,
textAlign : 'center',
x : 'left',
y : 'top',
data: [
{ text : 'Main Title' },
{ text : 'Secondary Title', dy: 10, fontSize: 10 }
]
}
}, document.body);
License
The MIT License (MIT)
Copyright (c) 2016 John Hildenbiddle (@jhildenbiddle)
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.