https://david-desmaisons.github.io/Vue.D3.sunburst/
Vue.D3.Sunburst provides a reusable vue sunburst charts component relying on D3.js.
Sunburst is the main component of this library and display sunburst chart based on data props using children property for hierarchy, name property for naming and size property for arcs size.
Sunburst component provides four optional slots:
legendandtopslots are intended to be used to display additional information such as legendpop-upto create a pop-up for an arcdefault slotis intended to receive renderless component providing behavior: for example, highlighting on mouse over or zoom on click
Components providing standard and reusable features are provided.
- Reactive to data changes
- Responsive to size changes
- Customizable with slot or exposed methods and events
- Zoomable
npm i vue-d3-sunburst
<sunburst :data="data">
<!-- Add behaviors -->
<template slot-scope="{ on, actions }">
<highlightOnHover v-bind="{ on, actions }"/>
<zoomOnClick v-bind="{ on, actions }"/>
<popUpOnHover v-bind="{ on, actions }"/>
</template>
<!-- Add information to be displayed on top the graph -->
<nodeInfoDisplayer slot="top" slot-scope="{ nodes }" :current="nodes.mouseOver" :root="nodes.root" description="of visits begin with this sequence of pages" />
<!-- Add bottom legend -->
<breadcrumbTrail slot="legend" slot-scope="{ nodes, colorGetter, width }" :current="nodes.mouseOver" :root="nodes.root" :colorGetter="colorGetter" :from="nodes.clicked" :width="width" />
<!-- Add pop-up -->
<template slot="pop-up" slot-scope="{ data }">
<div class="pop-up">{{data.name}}</div>
</template>
</sunburst>import {
breadcrumbTrail,
highlightOnHover,
nodeInfoDisplayer,
popUpOnHover,
sunburst,
zoomOnClick
} from 'vue-d3-sunburst';
import "vue-d3-sunburst/dist/vue-d3-sunburst.css";
export default {
components: {
breadcrumbTrail,
highlightOnHover,
nodeInfoDisplayer,
sunburst,
zoomOnClick
},
data() {
return {
tree: {
"name": "flare",
"children": [
{
"name": "analytics",
"children": [
{
"name": "cluster",
"children": [
{ "name": "AgglomerativeCluster", "size": 3938 },
{ "name": "CommunityStructure", "size": 3812 },
{ "name": "HierarchicalCluster", "size": 6714 },
{ "name": "MergeEdge", "size": 743 }
]
},
{
"name": "graph",
"children": [
{ "name": "BetweennessCentrality", "size": 3534 },
{ "name": "LinkDistance", "size": 5731 },
{ "name": "MaxFlowMinCut", "size": 7840 },
{ "name": "ShortestPaths", "size": 5914 },
{ "name": "SpanningTree", "size": 3416 }
]
},
{
"name": "optimization",
"children": [
{ "name": "AspectRatioBanker", "size": 7074 }
]
}
]
}
]
}
}
}
}This component is responsive and will adjust to resizing. In order for this to work properly, you must define for this component or its parent wether:
- a height or a max-height
- or a width or a max-width.
Failing to do so may result in a component whose size that will keep increasing.
-
legendUse this slot to add information on top or bottom of the graph -
topUse this slot to add information on top of the graph -
pop-upUse this slot to create a pop-up for arc: it receives as scopedata,nodeandactionsobjects -
defaultUse this slot to add behaviors to the sunburst
-
dataObject (optional)Sunburst data where children property is a array containing children.
-
color-schemeString (optional)default: provided by injected defaultSchemeColor with a fall back to schemeAccentD3 color scheme to be used.
-
color-scaleFunction (optional)default: undefinedD3 scale of colors (d3-scale). If specified, it overwrites the color-scheme props
-
get-category-for-colorFunction (optional)default: 'useNameForColor'Function used to map an item and its color. (nodeD3: Object) => category: Number | String By default use the node name
-
highlightOpacityNumber (optional)default: '0.3'Opacity to be applied to none highlighted nodes
-
min-angle-displayedNumber (optional)default: 0.005Minimal arc angle to be displayed (in radian).
-
arc-identificationFunction (optional)default: 'recursiveName'Function used to identify an arc, will be used during graph updates. (nodeD3: Object) => id: String
-
in-animation-durationNumber (optional)default: 100Duration for in animation in milliseconds
-
out-animation-durationNumber (optional)default: 1000Duration for out animation in milliseconds
-
show-labelsBoolean or Function (optional)default: false- If true displays the name attributes as arc labels
- If the value is a function, it must return the text that will be display for each arc. The function is called with an object similar to the D3.js node with the addition of a context property:
{ context: {angle: 45, relativeDepth: 1} }where angle is the arc angle in degree and relativeDepth is the arc depth in the current display (taking into account zoom). To display nothing returns null.
-
max-label-textNumber (optional)default: 45Useful to truncate labels: the maximum size of a label is the corresponding arc size + the value of
max-label-textin pixel. Ifmax-label-textis null, the labels will not be truncated. -
central-circle-relative-sizeNumber (optional)default: 0Size in percentage of the total graph, of a central circle
-
mouseLeaveFired when mouse leaves the sunburst node.
-
rootChangedFired when root changed.
arguments:
valueObject - {node, sunburst} The corresponding node and sunburst component
-
mouseOverNodeFired when mouse is over a sunburst node.
arguments:
valueObject - {node, sunburst} The corresponding node and sunburst component
-
clickNodeFired when sunburst node is clicked.
arguments:
valueObject - {node, sunburst} The corresponding node and sunburst component
-
zoomedChangedFired when the zoomed node changed.
arguments:
valueObject - {node, sunburst} The corresponding zoomed node and sunburst component
-
highlightedChangedFired when mouse is over a sunburst node.
arguments:
valueObject - {node, sunburst} The corresponding node and sunburst component
-
resizeFired when component is resizing.
arguments:
valueObject - {radius, height, width} Size information in pixel
-
highlightPath(node, opacity)Highlight the arc path leading to a given node.
parameters:
nodeObject - the D3 node to highlightopacityNumber - opacity of the none highlighted nodes, default to highlightOpacity
-
zoomToNode(node)Zoom to a given node.
parameters:
nodeObject - the D3 node to zoom to.
-
resetHighlight()Reset the highlighted path
Besides sunburst component, Vue.D3.Sunburst provides additional optional components that can be used out of the box as slot implementations. There are two kinds of additional components:
- the "renderfull" components provide visual additional visual information on the nodes. They can be used as
legendortopslots. - the renderless components provide predefined behaviors for the sunburst components. They can be used as default slots. It is possible to combine behavior using a root template slot element as in the example.
Breadcrumb trail component displaying path between root node and current node. Can be used as a legend slot of sunburst component.
-
rootObject (optional)Root node
-
currentObject (optional)Current node
-
fromObject (optional)Reference node, parents nodes of the current will have an opacity below 1
-
color-getterFunction (required)ColorGetter exposed by sunburst
-
widthNumber (optional)Sunburst width
-
orderNumber (optional)default: 1Css Order. If 1 the slot is displayed below the sunburst, if 0 the slot is displayed on top the sunburst
-
item-widthNumber (optional)default: 80Bread crumb item width
-
item-heightNumber (optional)default: 30Bread crumb item height
-
spacingNumber (optional)default: 3Spacing between breadcrumb items
-
tail-widthNumber (optional)default: 10With of tailing element
Component that display the percentage value of the current node relative to root. Can be used as a "top" slot of sunburst component.
-
rootObject (optional)Root node
-
currentObject (optional)Current node
-
clickedObject (optional)Clicked node
-
descriptionString (required)Text to be displayed
-
show-all-numberBoolean (optional)default: trueShow fraction format of size if true
-
percentagedependencies:
current,root,current,base -
displayPercentagedependencies:
percentage -
showdependencies:
percentage
These components can be used as a default slot of the sunburst component which received as attributes:
-
onwhich is the $on method of the sunburst component: -
actionswhich is an object containing the attributes:highlightPath: function that takes a node and highlight the path going from the root to the given nodezoomToNode: function that takes a node and zoom to the corresponding noderesetHighlight: function that resets the highlightingsetContextMenu: function that takes a node and display the corresponding pop-upcloseContextMenu: function that remove the current pop-up if any
Typical usage:
this.on("clickNode", ({node}) =>{
this.actions.zoomToNode(node);
});Renderless component providing the zoom on click behavior. Can be used as a default slot of sunburst component.
-
onFunction (required)Sunburst event listener. Same as component $on method.
-
actionsObject (required)Sunburst actions. Typically provided by sunburst default slot.
Renderless component providing path highlighting on mouse over behavior. Can be used as a default slot of sunburst component.
-
onFunction (required)Sunburst event listener. Same as component $on method.
-
actionsObject (required)Sunburst nodes. Typically provided by sunburst default slot.
Renderless component displaying arc pop-up on mouse over. Can be used as a default slot of sunburst component.
-
onFunction (required)Sunburst event listener. Same as component $on method.
-
actionsObject (required)Sunburst nodes. Typically provided by sunburst default slot.
npm install vue-d3-sunburst
npm install
npm run serve
npm run build
npm run lint
npm run test:unit
npm run doc:build
