Skip to main content

donut

Donut

Reusable Donut Chart API class that renders a simple and configurable donut chart.

Requires: module:d3-dispatch,
Example

const donutChart = donut();

donutChart
.externalRadius(500)
.internalRadius(200);

d3Selection.select('.css-selector')
.datum(dataset)
.call(donutChart);

exports(_selection, _data) ⏏

This function creates the graph using the selection as container

Kind: Exported function

ParamTypeDescription
_selectionD3SelectionA d3 selection that represents the container(s) where the chart(s) will be rendered
_dataDonutChartDataThe data to attach and generate the chart

exports.animationDuration(_x) ⇒ duration | module

Gets or Sets the duration of the animation

Kind: static method of exports
Returns: duration | module - Current animation duration or Chart module to chain calls
Access: public

ParamTypeDefaultDescription
_xNumber1200Desired animation duration for the graph

exports.centeredTextFunction(_x) ⇒ function | module

Gets or Sets the centeredTextFunction of the chart. If function is provided the format will be changed by the custom function's value format. The default format function value is "${d.percentage}% ${d.name}". The callback will provide the data object with id, name, percentage, and quantity. Also provides the component added by the user in each data entry.

Kind: static method of exports
Returns: function | module - Current centeredTextFunction or Chart module to chain calls
Access: public

ParamTypeDescription
_xfunctionCustom function that returns a formatted string

Example

donutChart.centeredTextFunction(d => `${d.id} ${d.quantity}`)

exports.colorMap([_x]) ⇒ number | module

Gets or Sets the colorMap of the chart

Kind: static method of exports
Returns: number | module - Current colorMap or Chart module to chain calls
Access: public

ParamTypeDefaultDescription
[_x]objectColor map

Example

stackedBar.colorMap({groupName: 'colorHex', groupName2: 'colorString'})

exports.colorSchema(_x) ⇒ String | module

Gets or Sets the colorSchema of the chart

Kind: static method of exports
Returns: String | module - Current colorSchema or Chart module to chain calls
Access: public

ParamTypeDescription
_xArray.<String>Desired colorSchema for the graph

exports.emptyDataConfig(_x) ⇒ Object | module

Gets or Sets the emptyDataConfig of the chart. If set and data is empty (quantity adds up to zero or there are no entries), the chart will render an empty slice with a given color (light gray by default)

Kind: static method of exports
Returns: Object | module - Current config for when chart data is an empty array
Access: public

ParamTypeDescription
_xObjectEmptyDataConfig object to get/set

Example

donutChart.emptyDataConfig({showEmptySlice: true, emptySliceColor: '#000000'})

exports.exportChart(filename, title) ⇒ Promise

Chart exported to png and a download action is fired

Kind: static method of exports
Returns: Promise - Promise that resolves if the chart image was loaded and downloaded successfully
Access: public

ParamTypeDescription
filenameStringFile title for the resulting picture
titleStringTitle to add at the top of the exported picture

exports.externalRadius(_x) ⇒ Number | Module

Gets or Sets the externalRadius of the chart

Kind: static method of exports
Returns: Number | Module - Current externalRadius or Donut Chart module to chain calls
Access: public

ParamTypeDescription
_xNumberExternalRadius number to get/set

exports.hasCenterLegend(_x) ⇒ boolean | Module

Gets or Sets the hasCenterLegend property of the chart, making it display legend at the center of the donut.

Kind: static method of exports
Returns: boolean | Module - Current hasCenterLegend flag or Chart module
Access: public

ParamTypeDescription
_xbooleanIf we want to show legent at the center of the donut

exports.hasHoverAnimation(_x) ⇒ boolean | module

Gets or Sets the hasHoverAnimation property of the chart. By default, donut chart highlights the hovered slice. This property explicitly disables this hover behavior.

Kind: static method of exports
Returns: boolean | module - Current hasHoverAnimation flag or Chart module
Access: public

ParamTypeDescription
_xbooleanDecide whether hover slice animation should be enabled

exports.hasFixedHighlightedSlice(_x) ⇒ boolean | module

Gets or Sets the hasFixedHighlightedSlice property of the chart, making it to highlight the selected slice id set with highlightSliceById all the time.

Kind: static method of exports
Returns: boolean | module - Current hasFixedHighlightedSlice flag or Chart module
Access: public

ParamTypeDescription
_xbooleanIf we want to make the highlighted slice permanently highlighted

exports.hasLastHoverSliceHighlighted(_x) ⇒ boolean | module

Gets or sets the hasLastHoverSliceHighlighted property. If property is true, the last hovered slice will be highlighted after 'mouseout` event is triggered. The last hovered slice will remain in highlight state. Note: if both hasFixedHighlightedSlice and hasLastHoverSliceHighlighted are true, the latter property will override the former.

Kind: static method of exports
Returns: boolean | module - Current hasLastHoverSliceHighlighted value or Chart module
Access: public

ParamTypeDescription
_xbooleanDecide whether the last hovered slice should be highlighted

exports.height(_x) ⇒ Number | Module

Gets or Sets the height of the chart

Kind: static method of exports
Returns: Number | Module - Current height or Donut Chart module to chain calls
Access: public

ParamTypeDescription
_xNumberDesired width for the graph

exports.highlightSliceById(_x) ⇒ Number | Module

Gets or Sets the id of the slice to highlight

Kind: static method of exports
Returns: Number | Module - Current highlighted slice id or Donut Chart module to chain calls
Access: public

ParamTypeDescription
_xNumberSlice id

exports.internalRadius(_x) ⇒ Number | Module

Gets or Sets the internalRadius of the chart

Kind: static method of exports
Returns: Number | Module - Current internalRadius or Donut Chart module to chain calls
Access: public

ParamTypeDescription
_xNumberInternalRadius number to get/set

exports.isAnimated(_x) ⇒ Boolean | module

Gets or Sets the isAnimated property of the chart, making it to animate when render. By default this is 'false'

Kind: static method of exports
Returns: Boolean | module - Current isAnimated flag or Chart module
Access: public

ParamTypeDescription
_xBooleanDesired animation flag

exports.isLoading(flag) ⇒ boolean | module

Gets or Sets the loading state of the chart

Kind: static method of exports
Returns: boolean | module - Current loading state flag or Chart module to chain calls
Access: public

ParamTypeDescription
flagbooleanDesired value for the loading state

exports.margin(_x) ⇒ Object | Module

Gets or Sets the margin of the chart

Kind: static method of exports
Returns: Object | Module - Current margin or Donut Chart module to chain calls
Access: public

ParamTypeDescription
_xObjectMargin object to get/set

exports.numberFormat(_x) ⇒ string | module

Gets or Sets the number format of the donut chart

Kind: static method of exports
Returns: string | module - Current numberFormat or Chart module to chain calls
Access: public

ParamTypeDescription
_xstringDesired numberFormat for the chart. See examples here

exports.on() ⇒ module

Exposes an 'on' method that acts as a bridge with the event dispatcher We are going to expose this events: customMouseOver, customMouseMove, customMouseOut and customClick

Kind: static method of exports
Returns: module - Bar Chart
Access: public

exports.orderingFunction(_x) ⇒ function | Module

Changes the order of items given custom function

Kind: static method of exports
Returns: function | Module - Void function with no return
Access: public

ParamTypeDescription
_xfunctionA custom function that sets logic for ordering

exports.percentageFormat(_x) ⇒ Number | Module

Gets or Sets the percentage format for the percentage label

Kind: static method of exports
Returns: Number | Module - Current format or Donut Chart module to chain calls
Access: public

ParamTypeDescription
_xStringFormat for the percentage label (e.g. '.1f')

exports.radiusHoverOffset(_x) ⇒ Number | Module

Gets or Sets the radiusHoverOffset of the chart

Kind: static method of exports
Returns: Number | Module - Current offset or Donut Chart module to chain calls
Access: public

ParamTypeDescription
_xNumberDesired offset for the hovered slice

exports.width(_x) ⇒ Number | Module

Gets or Sets the width of the chart

Kind: static method of exports
Returns: Number | Module - Current width or Donut Chart module to chain calls
Access: public

ParamTypeDescription
_xNumberDesired width for the graph

exports~DonutChartData : Array.<Object>

Kind: inner typedef of exports
Properties

NameTypeDescription
quantityNumberQuantity of the group (required)
percentageNumberPercentage of the total (optional)
nameStringName of the group (required)
idNumberIdentifier for the group required for legend feature (optional)

Example

[
{
quantity: 1,
percentage: 50,
name: 'glittering',
id: 1
},
{
quantity: 1,
percentage: 50,
name: 'luminous',
id: 2
}
]