com.vaadin.flow.component.charts.model.PlotOptionsSankey Maven / Gradle / Ivy
/**
* Copyright 2000-2024 Vaadin Ltd.
*
* This program is available under Vaadin Commercial License and Service Terms.
*
* See {@literal } for the full
* license.
*/
package com.vaadin.flow.component.charts.model;
import java.util.ArrayList;
import java.util.List;
import java.util.function.IntFunction;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.vaadin.flow.component.charts.model.style.Color;
/**
* Plot options for {@link ChartType#SANKEY} charts.
*/
public class PlotOptionsSankey extends AbstractPlotOptions {
private Boolean allowPointSelect;
private Boolean animation;
private Color borderColor;
private Number borderRadius;
private Number borderWidth;
private Boolean centerInCategory;
private String className;
private Boolean clip;
private Color color;
private Boolean colorByPoint;
private Number colorIndex;
private List colors;
private String cursor;
private Number curveFactor;
private DashStyle dashStyle;
private DataLabels dataLabels;
private String description;
private Boolean enableMouseTracking;
private Boolean getExtremesFromAll;
private Boolean inactiveOtherPoints;
private Label label;
private List levels;
private String linkedTo;
private Number linkOpacity;
private Number minLinkWidth;
private Number nodePadding;
private Number nodeWidth;
private Number opacity;
private Boolean selected;
private Boolean showCheckbox;
private Boolean showInLegend;
private Boolean skipKeyboardNavigation;
private States states;
private Boolean stickyTracking;
private Tooltip tooltip;
private Number turboThreshold;
private Boolean visible;
/**
* @see #setAllowPointSelect(Boolean)
*/
public Boolean getAllowPointSelect() {
return allowPointSelect;
}
/**
* Allow this series' points to be selected by clicking on the markers, bars
* or pie slices.
*
* Defaults to: false
*/
public void setAllowPointSelect(Boolean allowPointSelect) {
this.allowPointSelect = allowPointSelect;
}
/**
* @see #setAnimation(Boolean)
*/
public Boolean getAnimation() {
return animation;
}
/**
* Enable or disable the initial animation when a series is displayed.
* Please note that this option only applies to the initial animation of the
* series itself. For other animations, see
* {@link ChartModel#setAnimation(Boolean)}
*/
public void setAnimation(Boolean animation) {
this.animation = animation;
}
/**
* @see #setBorderColor(Color)
*/
public Color getBorderColor() {
return borderColor;
}
/**
* The color of the border surrounding each column or bar. Defaults to
* #ffffff.
*/
public void setBorderColor(Color borderColor) {
this.borderColor = borderColor;
}
/**
* @see #setBorderWidth(Number)
*/
public Number getBorderWidth() {
return borderWidth;
}
/**
*
* The width of the border surrounding each column or bar. Defaults to
* 1
when there is room for a border, but to 0
* when the columns are so dense that a border would cover the next column.
*
*
* In styled
* mode, the stroke width can be set with the
* .highcharts-point
rule.
*
*/
public void setBorderWidth(Number borderWidth) {
this.borderWidth = borderWidth;
}
/**
* @see #setCenterInCategory(Boolean)
*/
public Boolean getCenterInCategory() {
return centerInCategory;
}
/**
*
* When true
, the columns will center in the category, ignoring
* null or missing points. When false
, space will be reserved
* for null or missing points.
*
*/
public void setCenterInCategory(Boolean centerInCategory) {
this.centerInCategory = centerInCategory;
}
/**
* @see #setClassName(String)
*/
public String getClassName() {
return className;
}
/**
*
* An additional class name to apply to the series' graphical elements. This
* option does not replace default class names of the graphical element.
*
*/
public void setClassName(String className) {
this.className = className;
}
/**
* @see #setClip(Boolean)
*/
public Boolean getClip() {
return clip;
}
/**
*
* Disable this option to allow series rendering in the whole plotting area.
*
*
* Note: Clipping should be always enabled when
* chart.zoomType is set
*
*/
public void setClip(Boolean clip) {
this.clip = clip;
}
/**
* @see #setColor(Color)
*/
public Color getColor() {
return color;
}
/**
*
* The main color of the series. In line type series it applies to the line
* and the point markers unless otherwise specified. In bar type series it
* applies to the bars unless a color is specified per point. The default
* value is pulled from the options.colors array.
*
*
*
* In styled mode, the color can be defined by the colorIndex option. Also,
* the series color can be set with the .highcharts-series,
* .highcharts-color-{n}, .highcharts-{type}-series or
* .highcharts-series-{n} class, or individual classes given by the
* className option.
*
*/
public void setColor(Color color) {
this.color = color;
}
/**
* @see #setColorByPoint(Boolean)
*/
public Boolean getColorByPoint() {
return colorByPoint;
}
/**
* When using automatic point colors pulled from the
* options.colors
collection, this option determines whether
* the chart should receive one color per series or one color per point.
*
* Defaults to: true
*/
public void setColorByPoint(Boolean colorByPoint) {
this.colorByPoint = colorByPoint;
}
/**
* @see #setColorIndex(Number)
*/
public Number getColorIndex() {
return colorIndex;
}
/**
*
* Styled
* mode only. A specific color index to use for the series, so its
* graphic representations are given the class name
* highcharts-color-{n}
.
*
*/
public void setColorIndex(Number colorIndex) {
this.colorIndex = colorIndex;
}
/**
* @see #setColors(Color...)
*/
public Color[] getColors() {
return toArray(colors, Color[]::new);
}
/**
*
* A series specific or series type specific color set to apply instead of
* the global colors when
* colorByPoint
* is true.
*
*/
public void setColors(Color... colors) {
this.colors = toList(colors);
}
/**
* Adds color to the colors array
*
* @param color
* to add
* @see #setColors(Color...)
*/
public void addColor(Color color) {
if (this.colors == null) {
this.colors = new ArrayList<>();
}
this.colors.add(color);
}
/**
* Removes first occurrence of color in colors array
*
* @param color
* to remove
* @see #setColors(Color...)
*/
public void removeColor(Color color) {
safeRemove(this.colors, color);
}
/**
* @see #setCursor(String)
*/
public String getCursor() {
return cursor;
}
/**
*
* You can set the cursor to "pointer" if you have click events attached to
* the series, to signal to the user that the points and lines can be
* clicked.
*
*
* In styled
* mode, the series cursor can be set with the same classes * as listed
* under series.color.
*
*/
public void setCursor(String cursor) {
this.cursor = cursor;
}
/**
* @see #setCurveFactor(Number)
*/
public Number getCurveFactor() {
return curveFactor;
}
/**
*
* Higher numbers makes the links in a sankey diagram more curved. A
* curveFactor of 0 makes the lines straight.
*
*
* Defaults to 0.33.
*
*/
public void setCurveFactor(Number curveFactor) {
this.curveFactor = curveFactor;
}
/**
* @see #setDashStyle(DashStyle)
*/
public DashStyle getDashStyle() {
return dashStyle;
}
/**
*
* Name of the dash style to use for the graph, or for some series types the
* outline of each shape.
*
*
* In styled
* mode, the stroke
* dash-array can be set with the same classes as listed under
* series.color.
*
*/
public void setDashStyle(DashStyle dashStyle) {
this.dashStyle = dashStyle;
}
/**
* @see #setDataLabels(DataLabels)
*/
public DataLabels getDataLabels() {
if (dataLabels == null) {
dataLabels = new DataLabels();
}
return dataLabels;
}
/**
* Options for the data labels appearing on top of the nodes and links. For
* sankey charts, data labels are visible for the nodes by default, but
* hidden for links. This is controlled by modifying the nodeFormat, and the
* format that applies to links and is an empty string by default.
*/
public void setDataLabels(DataLabels dataLabels) {
this.dataLabels = dataLabels;
}
/**
* @see #setDescription(String)
*/
public String getDescription() {
return description;
}
/**
*
* A description of the series to add to the screen reader information about
* the series.
*
*/
public void setDescription(String description) {
this.description = description;
}
/**
* @see #setEnableMouseTracking(Boolean)
*/
public Boolean getEnableMouseTracking() {
return enableMouseTracking;
}
/**
*
* Enable or disable the mouse tracking for a specific series. This includes
* point tooltips and click events on graphs and points. For large datasets
* it improves performance.
*
*/
public void setEnableMouseTracking(Boolean enableMouseTracking) {
this.enableMouseTracking = enableMouseTracking;
}
/**
* @see #setGetExtremesFromAll(Boolean)
*/
public Boolean getGetExtremesFromAll() {
return getExtremesFromAll;
}
/**
*
* Whether to use the Y extremes of the total chart width or only the zoomed
* area when zooming in on parts of the X axis. By default, the Y axis
* adjusts to the min and max of the visible data. Cartesian series only.
*
*/
public void setGetExtremesFromAll(Boolean getExtremesFromAll) {
this.getExtremesFromAll = getExtremesFromAll;
}
/**
* @see #setInactiveOtherPoints(Boolean)
*/
public Boolean getInactiveOtherPoints() {
return inactiveOtherPoints;
}
/**
* Highlight only the hovered point and fade the remaining points. Defaults
* to true.
*/
public void setInactiveOtherPoints(Boolean inactiveOtherPoints) {
this.inactiveOtherPoints = inactiveOtherPoints;
}
/**
* @see #setLabel(Label)
*/
public Label getLabel() {
return label;
}
/**
*
* Series labels are placed as close to the series as possible in a natural
* way, seeking to avoid other series. The goal of this feature is to make
* the chart more easily readable, like if a human designer placed the
* labels in the optimal position.
*
*
* The series labels currently work with series types having a
* graph
or an area
.
*
*/
public void setLabel(Label label) {
this.label = label;
}
/**
* @see #setLevels(Level...)
*/
public Level[] getLevels() {
return toArray(levels, Level[]::new);
}
/**
* Set options on specific levels. Takes precedence over series options, but
* not point options.
*/
public void setLevels(Level... levels) {
this.levels = toList(levels);
}
private T[] toArray(List list, IntFunction generator) {
return list != null ? list.stream().toArray(generator)
: generator.apply(0);
}
private List toList(T... items) {
return Stream.of(items)
.collect(Collectors.toCollection(ArrayList::new));
}
/**
* Adds level to the levels array
*
* @param level
* to add
* @see #setLevels(Level...)
*/
public void addLevel(Level level) {
if (this.levels == null) {
this.levels = new ArrayList<>();
}
this.levels.add(level);
}
/**
* Removes first occurrence of level in levels array
*
* @param level
* to remove
* @see #setLevels(Level...)
*/
public void removeLevel(Level level) {
safeRemove(this.levels, level);
}
private void safeRemove(List list, T item) {
if (list != null) {
list.remove(item);
}
}
/**
* @see #setLinkedTo(String)
*/
public String getLinkedTo() {
return linkedTo;
}
/**
*
* The id of another series to link
* to. Additionally, the value can be ":previous" to link to the previous
* series. When two series are linked, only the first one appears in the
* legend. Toggling the visibility of this also toggles the linked series.
*
*
* If master series uses data sorting and linked series does not have its
* own sorting definition, the linked series will be sorted in the same
* order as the master one.
*
*/
public void setLinkedTo(String linkedTo) {
this.linkedTo = linkedTo;
}
/**
* @see #setLinkOpacity(Number)
*/
public Number getLinkOpacity() {
return linkOpacity;
}
/**
*
* Opacity for the links between nodes in the sankey diagram.
*
*
* Defaults to 0.5
*
*/
public void setLinkOpacity(Number linkOpacity) {
this.linkOpacity = linkOpacity;
}
/**
* @see #setMinLinkWidth(Number)
*/
public Number getMinLinkWidth() {
return minLinkWidth;
}
/**
* The minimal width for a line of a sankey. By default, 0 values are not
* shown.
*/
public void setMinLinkWidth(Number minLinkWidth) {
this.minLinkWidth = minLinkWidth;
}
/**
* @see #setNodePadding(Number)
*/
public Number getNodePadding() {
return nodePadding;
}
/**
*
* The padding between nodes in a sankey diagram or dependency wheel, in
* pixels.
*
*
* If the number of nodes is so great that it is possible to lay them out
* within the plot area with the given nodePadding
, they will
* be rendered with a smaller padding as a strategy to avoid overflow.
*
*/
public void setNodePadding(Number nodePadding) {
this.nodePadding = nodePadding;
}
/**
* @see #setNodeWidth(Number)
*/
public Number getNodeWidth() {
return nodeWidth;
}
/**
* The pixel width of each node in a sankey diagram or dependency wheel, or
* the height in case the chart is inverted. Defaults to 20.
*/
public void setNodeWidth(Number nodeWidth) {
this.nodeWidth = nodeWidth;
}
/**
* @see #setOpacity(Number)
*/
public Number getOpacity() {
return opacity;
}
/**
* Opacity for the nodes in the sankey diagram.
*/
public void setOpacity(Number opacity) {
this.opacity = opacity;
}
/**
* @see #setSelected(Boolean)
*/
public Boolean getSelected() {
return selected;
}
/**
*
* Whether to select the series initially. If showCheckbox
is
* true, the checkbox next to the series name in the legend will be checked
* for a selected series.
*
*/
public void setSelected(Boolean selected) {
this.selected = selected;
}
/**
* @see #setShowCheckbox(Boolean)
*/
public Boolean getShowCheckbox() {
return showCheckbox;
}
/**
*
* If true, a checkbox is displayed next to the legend item to allow
* selecting the series. The state of the checkbox is determined by the
* selected
option.
*
*/
public void setShowCheckbox(Boolean showCheckbox) {
this.showCheckbox = showCheckbox;
}
/**
* @see #setShowInLegend(Boolean)
*/
public Boolean getShowInLegend() {
return showInLegend;
}
/**
*
* Whether to display this particular series or series type in the legend.
* Standalone series are shown in legend by default, and linked series are
* not. Since v7.2.0 it is possible to show series that use colorAxis by
* setting this option to true
.
*
*/
public void setShowInLegend(Boolean showInLegend) {
this.showInLegend = showInLegend;
}
/**
* @see #setSkipKeyboardNavigation(Boolean)
*/
public Boolean getSkipKeyboardNavigation() {
return skipKeyboardNavigation;
}
/**
*
* If set to true
, the accessibility module will skip past the
* points in this series for keyboard navigation.
*
*/
public void setSkipKeyboardNavigation(Boolean skipKeyboardNavigation) {
this.skipKeyboardNavigation = skipKeyboardNavigation;
}
/**
* @see #setStates(States)
*/
public States getStates() {
return states;
}
/**
* @see States
*/
public void setStates(States states) {
this.states = states;
}
/**
* @see #setStickyTracking(Boolean)
*/
public Boolean getStickyTracking() {
return stickyTracking;
}
/**
*
* Sticky tracking of mouse events. When true, the mouseOut
* event on a series isn't triggered until the mouse moves over another
* series, or out of the plot area. When false, the mouseOut
* event on a series is triggered when the mouse leaves the area around the
* series' graph or markers. This also implies the tooltip when not shared.
* When stickyTracking
is false and tooltip.shared
* is false, the tooltip will be hidden when moving the mouse between
* series. Defaults to true for line and area type series, but to false for
* columns, pies etc.
*
*
* Note: The boost module will force this option because of
* technical limitations.
*
*/
public void setStickyTracking(Boolean stickyTracking) {
this.stickyTracking = stickyTracking;
}
/**
* @see #setTooltip(Tooltip)
*/
public Tooltip getTooltip() {
return tooltip;
}
/**
*
* A configuration object for the tooltip rendering of each single series.
* Properties are inherited from
* tooltip, but only the following
* properties can be defined on a series level.
*
*/
public void setTooltip(Tooltip tooltip) {
this.tooltip = tooltip;
}
/**
* @see #setTurboThreshold(Number)
*/
public Number getTurboThreshold() {
return turboThreshold;
}
/**
*
* When a series contains a data array that is longer than this, only one
* dimensional arrays of numbers, or two dimensional arrays with x and y
* values are allowed. Also, only the first point is tested, and the rest
* are assumed to be the same format. This saves expensive data checking and
* indexing in long series. Set it to 0
disable.
*
*
* Note: In boost mode turbo threshold is forced. Only array of numbers or
* two dimensional arrays are allowed.
*
*/
public void setTurboThreshold(Number turboThreshold) {
this.turboThreshold = turboThreshold;
}
/**
* @see #setVisible(Boolean)
*/
public Boolean getVisible() {
return visible;
}
/**
* Set the initial visibility of the series.
*/
public void setVisible(Boolean visible) {
this.visible = visible;
}
@Override
public ChartType getChartType() {
return ChartType.SANKEY;
}
}