Class DonutChart
setInnerRadius(float) at 0.
The chart draws its first visible series as the ring: one slice per value, named by the chart's labels and colored by palette slot, because in a donut it is the slices that are the categories. A second series is left undrawn rather than drawn as a second ring; two rings on one chart is a chart nobody can read.
The hole is a real widget slot. setCenter(Widget) puts a widget in the
middle (a total, an icon, a button), laid out in the largest square that fits inside the
ring, and it takes input like any other widget: a button in the hole is clickable, and the
chart's own hover stops at the ring.
Negative values are ignored: they have no share of a whole. Hiding a slice from the legend animates it closed and gives its angle back to the others, because the shares are recomputed from what is still shown.
DonutChart chart = new DonutChart();
chart.setLabels("Direct", "Search", "Social", "Mail");
chart.addSeries(ChartSeries.of("Traffic", 42, 31, 18, 9));
chart.setCenter(new Label("100%").setRole(Label.Role.TITLE));
-
Nested Class Summary
Nested classes/interfaces inherited from class limn.components.chart.Chart
Chart.LegendEntry, Chart.LegendPosition, Chart.TooltipMode -
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@Nullable Widget<?> center()The widget in the hole, ornull.protected @Nullable RecthoverRegion(ChartPoint point) The ring, grown by the distance a slice pops out of it.floatThe hole's diameter as a fraction of the ring's.booleanisSliceVisible(int index) Whether sliceindexis currently drawn.protected List<Chart.LegendEntry> One entry per series, in palette order.static DonutChartA donut overlabelsshowingvalues.protected voidOne chart node, named by the title and described by the ring's series name, or named by the series when there is no title, with one toggleable series node per legend entry.protected voidonHoverChanged(@Nullable ChartPoint picked) Called when the datum under the pointer changes,nullwhen there is none: the hook for a chart that animates something on hover.protected voidonLayout()Recomputes the regions whenever the box is laid out, so that the legend's boxes are current for the tree published between this pass and the paint.protected booleanonSyntheticAction(long key, Accessible.Action action, Accessible.Argument arg) A toggle on a slice node reaches the same path a click on its legend entry reaches, so a reader's toggle and a pointer's are one and the same to the chart; refused when the legend is not interactive, not drawn, or the key names no category.protected voidpaintContent(Canvas canvas, float x, float y, float w, float h) Paints the marks inside the region left after the title and the legend, in the chart's own coordinates.protected @Nullable ChartPointpickAt(float localX, float localY) The datum under a point in the chart's local coordinates, ornullwhen the pointer is not over the marks.Puts a widget in the hole.setInnerRadius(float fraction) Sets the hole as a fraction of the outer radius, in[0, 0.95].setSliceColors(Color @Nullable ... colors) Pins the slice colors, in slice order; a shorter array leaves the rest to the palette, andnullhands all of them back to it.setSliceGap(float points) Sets the gap between slices in logical points (0makes them touch).setSliceVisible(int index, boolean visible) Hides or shows one slice; the rest of the ring closes over it, or opens for it.setStartAngle(float degrees) Sets the first slice's starting angle in degrees;-90(the default) is noon.sliceColor(int index) The color of sliceindex: its own, or its palette slot.floatsliceGap()Points of surface between two slices.floatWhere the first slice starts, in degrees clockwise from three o'clock.protected voidtoggleLegendEntry(int index) Hides or shows what legend entryindexstands for.protected ColorThe swatch color for a tooltip row.protected StringtooltipRowName(ChartPoint row) The name a tooltip row carries where reading starts, the series name by default.protected List<ChartPoint> tooltipRows(ChartPoint picked) The rows a tooltip shows forpicked.protected StringThe value a tooltip row carries where reading ends.protected StringtooltipTitle(ChartPoint picked) The series names the ring as a whole ("Traffic"); the row names the slice.Methods inherited from class limn.components.chart.Chart
addSeries, animationBaseline, animationDuration, background, categoryCount, clearSeries, clearTitle, contentBoxHeight, contentBoxWidth, contentLeft, contentTop, damageHoverInPlace, dataGeneration, drawnValue, elementProgress, ellipsize, handleUserChange, hoveredPoint, isLegendInteractive, isTooltipEnabled, label, labels, labelSource, legendChanged, legendEntryBounds, legendEntryCount, legendPosition, measure, onAttached, onMeasure, onMouseEvent, onPaint, onPaintOverlay, onPointClick, onPointHover, onSeriesAdded, palette, pointFor, progress, removeSeries, replayAnimation, series, series, seriesAlpha, seriesColor, seriesCount, setAnimationDuration, setAnimationEasing, setBackground, setLabels, setLabels, setLabels, setLegendInteractive, setLegendPosition, setPalette, setPreferredSize, setSeries, setTitle, setTitle, setTooltipEnabled, setTooltipFormat, setTooltipMode, setValueFormat, staggerFraction, stateFadeSeconds, title, titleSource, tokens, tooltipMode, updateRegions, valueFormatMethods inherited from class limn.scene.Widget
acceptsTextInput, accessibleLabelAccessKey, accessibleLabelTarget, accessibleLabelText, add, add, announceChange, backdropReach, baselineOffset, baselineOffsetOf, caretRect, children, clipboard, clipHeight, clipsChildren, clipWidth, clipX, clipY, controlSize, cursor, declaredControlSize, declaredLayoutDirection, declaredLocale, focusArrivedBackward, focusArrivedByTraversal, height, hitTest, hitTestChild, id, imageCursor, inheritanceHost, invalidate, invalidate, invalidateAccessible, isEnabled, isFocusable, isFocused, isRightToLeft, isSelfEnabled, isShowing, isVisible, isVisibleByItsOwnFlag, layoutBox, layoutDirection, locale, localToScene, localToSceneBounds, markNeedsContainedLayout, markNeedsLayout, markNeedsLayoutInPlace, maxHeight, maxWidth, measure, minHeight, minWidth, moveChild, moveChild, moveChild, neutralBase, notifyChange, notifyTextEdit, observeChanges, onAccessibilityAction, onAccessibilityChild, onAccessibilityChildAction, onAccessibilityChildIdentity, onCanEdit, onCharTyped, onDetached, onDragExit, onDragOver, onDragStart, onDrop, onEdit, onFocusGained, onFocusLost, onHitTest, onKeyEvent, onPreedit, overlayPassesPointer, paintChildren, paintOutset, paintsDecoration, paintsFromBackdrop, paintWidget, parent, remove, remove, requestFocus, requestFocus, revealInView, revealInView, runHandler, scene, sceneNanos, sceneToLocal, self, setAccessibleDescribedBy, setAccessibleDescription, setAccessibleDescription, setAccessibleIgnored, setAccessibleLabelledBy, setAccessibleName, setAccessibleName, setAccessibleRole, setControlSize, setCursor, setEnabled, setFocusable, setId, setImageCursor, setInheritanceHost, setLayoutDirection, setLocale, setMaxHeight, setMaxWidth, setMinHeight, setMinWidth, setPresentedElsewhere, setTooltip, setTooltip, setVisible, shapeText, textRuler, tooltip, tooltipSource, width, x, y
-
Constructor Details
-
DonutChart
public DonutChart()
-
-
Method Details
-
of
A donut overlabelsshowingvalues. -
innerRadius
public float innerRadius()The hole's diameter as a fraction of the ring's. -
setInnerRadius
Sets the hole as a fraction of the outer radius, in[0, 0.95].0draws a pie; the default0.62leaves a hole big enough for a headline number. -
startAngle
public float startAngle()Where the first slice starts, in degrees clockwise from three o'clock. -
setStartAngle
Sets the first slice's starting angle in degrees;-90(the default) is noon. -
sliceGap
public float sliceGap()Points of surface between two slices. -
setSliceGap
Sets the gap between slices in logical points (0makes them touch). -
setSliceColors
Pins the slice colors, in slice order; a shorter array leaves the rest to the palette, andnullhands all of them back to it. -
sliceColor
The color of sliceindex: its own, or its palette slot. -
center
The widget in the hole, ornull. -
setCenter
Puts a widget in the hole. It is laid out centred in the largest square that fits inside the ring and is a normal child in every other way: it takes input, it can be a button, and it is measured against that square rather than against the chart.nullempties the hole. -
isSliceVisible
public boolean isSliceVisible(int index) Whether sliceindexis currently drawn. -
setSliceVisible
Hides or shows one slice; the rest of the ring closes over it, or opens for it. -
onLayout
protected void onLayout()Description copied from class:ChartRecomputes the regions whenever the box is laid out, so that the legend's boxes are current for the tree published between this pass and the paint. A subclass that lays out a child of its own calls this first.- Overrides:
onLayoutin classChart<DonutChart>
-
paintContent
Description copied from class:ChartPaints the marks inside the region left after the title and the legend, in the chart's own coordinates. Grid, axes and everything data-shaped belong here.- Specified by:
paintContentin classChart<DonutChart>
-
pickAt
Description copied from class:ChartThe datum under a point in the chart's local coordinates, ornullwhen the pointer is not over the marks. Called for hover and for clicks, so it decides both.- Specified by:
pickAtin classChart<DonutChart>
-
hoverRegion
The ring, grown by the distance a slice pops out of it.The whole ring rather than the hovered sector: a sector's bounding box is an arc problem with four cases for which quadrants it spans, and the ring is a square that is already much smaller than this widget, which also carries a title and a legend.
- Overrides:
hoverRegionin classChart<DonutChart>- Parameters:
point- the hovered datum, nevernull- Returns:
- the region in widget coordinates, or
nullfor "all of it"
-
onHoverChanged
Description copied from class:ChartCalled when the datum under the pointer changes,nullwhen there is none: the hook for a chart that animates something on hover. The application-facing callback isChart.onPointHover(Consumer); this is for subclasses.- Overrides:
onHoverChangedin classChart<DonutChart>
-
onAccessibility
One chart node, named by the title and described by the ring's series name, or named by the series when there is no title, with one toggleable series node per legend entry.What is published is what is drawn. The ring is the first visible series and any other is undrawn on purpose, so there is no node per series; the things the legend names and a click operates are the slices, one per category, and those are the children — only while the legend is drawn, because without it no slice has a box or an operation of its own, and the arcs are not nodes in this cut. Each child's box is the legend box a click is tested against and never the arc, which moves on every frame of an animation and on the hover pop. Its toggle state is the hidden-slice bit and never the eased weight, for the same reason. Every string is handed over by reference, so a damaged frame that changes nothing a reader hears allocates nothing.
- Overrides:
onAccessibilityin classWidget<DonutChart>- Parameters:
a- the node being described; write into it, and never keep it
-
onSyntheticAction
A toggle on a slice node reaches the same path a click on its legend entry reaches, so a reader's toggle and a pointer's are one and the same to the chart; refused when the legend is not interactive, not drawn, or the key names no category.- Overrides:
onSyntheticActionin classWidget<DonutChart>- Parameters:
key- the key this widget gave that child when it declared itaction- what was askedarg- the argument, orAccessible.Argument.NONE- Returns:
- whether this widget did it
-
tooltipRows
Description copied from class:ChartThe rows a tooltip shows forpicked. The default isChart.TooltipMode.INDEX-aware: every visible series at the same index, or just the picked datum inChart.TooltipMode.POINT.- Overrides:
tooltipRowsin classChart<DonutChart>
-
tooltipTitle
The series names the ring as a whole ("Traffic"); the row names the slice.- Overrides:
tooltipTitlein classChart<DonutChart>
-
tooltipRowName
Description copied from class:ChartThe name a tooltip row carries where reading starts, the series name by default.- Overrides:
tooltipRowNamein classChart<DonutChart>
-
tooltipRowValue
Description copied from class:ChartThe value a tooltip row carries where reading ends.- Overrides:
tooltipRowValuein classChart<DonutChart>
-
tooltipRowColor
Description copied from class:ChartThe swatch color for a tooltip row.- Overrides:
tooltipRowColorin classChart<DonutChart>
-
legendEntries
Description copied from class:ChartOne entry per series, in palette order. Overridden by charts whose legend is not that.- Overrides:
legendEntriesin classChart<DonutChart>
-
toggleLegendEntry
protected void toggleLegendEntry(int index) Description copied from class:ChartHides or shows what legend entryindexstands for.- Overrides:
toggleLegendEntryin classChart<DonutChart>
-