e4
v0.3.3
Published
Donut chart library
Downloads
8
Readme
e4
Donut chart library
Installation
npm install e4
Add node_modules/e4/main.css
to you're HTML, or import node_modules/e4/main.scss
Usage
let donut = [
{
text: 'Example 1',
size: 10,
backgroundColor: 'red',
},
...
];
new SingleDonut(donut)
.draw('#svg1');
let multipartDonut = [
[
{
text: 'Example 1',
size: 10,
backgroundColor: 'red',
},
...
],
...
]
new MultipartDonut(multipartDonut)
.draw('#svg2');
let sunburstDonut = [
[
{
text: 'Example 1',
size: 10,
backgroundColor: 'red',
},
...
],
...
]
new MultipartDonut(multipartDonut)
.draw('#svg3');
DonutItem structure
DonutItem = {
textId?: string,
arcId?: string,
text?: string,
textColor?: string,
textClass?: string
backgroundColor?: string,
strokeColor?: string,
strokeWidth?: string,
arcClass?: string,
size?: number,
textLabelsAngle?: number,
textLabelsRelative?: RelativeType,
textLabelsSymmetric?: boolean,
textLabelsMargin?: number,
children?: DonutItem[] //Only for sunburst donut
}
Constructor params
SingleDonut
- array of DonutItem
MultipartDonut
- array of arrays of DonutItem
SunburstDonut
- array of DonutItem
width children field
Methods
setDonatRatio(ratio: number)
- set ration between layer width and empty space radius. ratio
should be between 0 and 1
setWidth(width: number)
- set base svg element widthsetHeight(height: number)
- set base svg element heightsetTextLabelsMargin(margin: number
- set default text margins
setTextLabelsAngle(angle: number)
- set default angle of textsetTextLabelsPosition(type: RelativeType)
- set type of position rotation. Possible types - ABSOLUTE
,
RELATIVE_TO_BISECTOR
, RELATIVE_TO_BISECTOR_WITH_GRAVITY
setTextLabelsSymmetric(symmetric: boolean)
- set if text symmetric ot center of the donutsetTooltipClasses(classes: string | string[])
- set classes that will be added to tooltip
setTooltipPosition(position: string)
- set tooltip position. Possible variants - LEFT
, TOP
, RIGHT
, BOTTOM
,
LEFT_TOP
, LEFT_BOTTOM
, RIGHT_TOP
, RIGHT_BOTTOM
setTooltipOffset(offset: number)
- set tooltip offset from pointersetTooltipOverflow(overflow: boolean)
- set if tooltip can go out of screen. Default false
setTextFunction(fn: DonutTextFunction)
- set function that will be called to get arc text. Receive DonutItem
and
total elements size as param. Must return text stringsetTextInnerHTMLFunction(fn: DonutTextFunction)
- set function that will be called to get arc text. Receive
DonutItem
and total elements size as param. Must return inner html stringsetTextWidthSizeFunction(fn: DonutTextWithSizeFunction)
- set function that will be called to get arc text, after
text placeholder drew. Receive DonutItem
, total elements size, text field width and height as param. Must return text stringsetTextWidthSizeInnerHTMLFunction(fn: DonutTextWithSizeFunction)
- set function that will be called to get arc text, after
text placeholder drew. Receive DonutItem
, total elements size, text field width and height as param. Must return inner html stringsetTextWidthSizeElementFunction(fn: DonutTextWithSizeFunction)
- set function that will be called to get arc text, after
text placeholder drew. Receive DonutItem
, total elements size, text field width and height as param. Must return
HTML Element that will be appended to text containersetTooltipTextFunction(fn: DonutTextFunction)
- set function that will be called to tooltip text. Receive DonutItem
and total elements size as param. Must return text stringsetTooltipInnerHTMLFunction(fn: DonutTextFunction)
- set function that will be called to get tooltip text. Receive
DonutItem
and total elements size as param. Must return inner html stringsetTooltipElementFunction(fn: DonutTextFunction)
- set function that will be called to get tooltip text. Receive
DonutItem
and total elements size as param. Must return HTML Element that will be appended to text containeraddEventListener(event: string, listener: DonutEventListener)
- add event listener to donutgetItemById(id: string)
- get DonutItem
by donut item idgetIdForItem(item: DonutItem)
- get item id for DonutItem
getIdForTextId(id: string)
- get item id by text idgetIdForArcId(id: string)
- get item id by arc iddraw(taget: string|HTMLElement)
- draw svg inside given container