Package com.storedobject.svg.chart
Class Values
java.lang.Object
com.storedobject.svg.chart.Values
- All Implemented Interfaces:
Serializable
This class represents a collection of data values to be plotted on a chart.
It handles labels, values, units, colors, and basic formatting.
- Author:
- Syam
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a value with associated styles.static classRepresents a single data point in the chart. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(Values.Value value) Add aValues.Valueto the collection.Add a value with a label.buildStyles(Node node) Builds and returns the styles associated with all values in the collection.voidclear()Clear all values.voidcolorize()Automatically assign colors to values that don't have one.get(int index) Get the value at a specific index.getColor(Values.Value value) Get the color for a givenValues.Value.getLabel(Values.Value value) Get the formatted label for a givenValues.Value.Get the label name.Get the color for the label name.doublegetPercentage(Values.Value value) Get the percentage of a givenValues.Valuerelative to the total.getPercentageString(Values.Value value) Get the percentage string for a givenValues.Value.doublegetTotal()Get the total sum of all values.getUnit()Get the unit.getValue(Values.Value value) Get the formatted value for a givenValues.Value.Get the value name.Get the color for the value name.booleanisBuilt()Check if the values are built.list()Get the list of values.voidremove(Values.Value value) Remove aValues.Valuefrom the collection.voidRemove values with a specific label.voidsetDefaultValueColor(String defaultValueColor) Set the default color for values.voidsetLabelFunction(Function<Values.Value, String> labelFunction) Set the function to generate labels forValues.Valueobjects.voidsetLabelName(String labelName) Set the label name (typically used as an X-axis name).voidsetLabelNameColor(String labelNameColor) Set the color for the label name.voidSet the unit for values.voidsetValueFunction(Function<Values.Value, String> valueFunction) Set the function to generate formatted value strings forValues.Valueobjects.voidsetValueName(String valueName) Set the value name (typically used as a Y-axis name).voidsetValueNameColor(String valueNameColor) Set the color for the value name.intsize()Get the number of values.stream()Get a stream of values.static StringConvert a double to string with unit.toUnit(double v) Format a double value with its unit.Format aValues.Valuewith its unit.
-
Constructor Details
-
Values
public Values()Constructor. -
Values
-
-
Method Details
-
setUnit
-
getUnit
-
setLabelName
Set the label name (typically used as an X-axis name).- Parameters:
labelName- Label name.
-
getLabelName
-
setValueNameColor
Set the color for the value name.- Parameters:
valueNameColor- Color to set.
-
getValueNameColor
-
setLabelNameColor
Set the color for the label name.- Parameters:
labelNameColor- Color to set.
-
getLabelNameColor
-
setValueName
Set the value name (typically used as a Y-axis name).- Parameters:
valueName- Value name.
-
getValueName
-
getValue
Get the formatted value for a givenValues.Value.- Parameters:
value- Value object.- Returns:
- Formatted value string.
-
getLabel
Get the formatted label for a givenValues.Value.- Parameters:
value- Value object.- Returns:
- Formatted label string.
-
setDefaultValueColor
Set the default color for values.- Parameters:
defaultValueColor- Color to set.
-
getColor
Get the color for a givenValues.Value.- Parameters:
value- Value object.- Returns:
- Color string.
-
setLabelFunction
Set the function to generate labels forValues.Valueobjects.- Parameters:
labelFunction- Label function.
-
setValueFunction
Set the function to generate formatted value strings forValues.Valueobjects.- Parameters:
valueFunction- Value function.
-
getTotal
public double getTotal()Get the total sum of all values.- Returns:
- Total sum.
-
getPercentage
Get the percentage of a givenValues.Valuerelative to the total.- Parameters:
value- Value object.- Returns:
- Percentage.
-
getPercentageString
Get the percentage string for a givenValues.Value.- Parameters:
value- Value object.- Returns:
- Percentage string (e.g., "50.0%").
-
add
Add aValues.Valueto the collection.Note: The added value object is returned for convenience. However, it could be different from the input value if it needs to be modified to adjust its properties.
- Parameters:
value- Value object to add.- Returns:
- Added value object.
-
add
Add a value with a label.- Parameters:
label- Label for the value.value- Value.- Returns:
- Added value object.
-
remove
Remove aValues.Valuefrom the collection.- Parameters:
value- Value object to remove.
-
remove
Remove values with a specific label.- Parameters:
label- Label of the values to remove.
-
clear
public void clear()Clear all values. -
stream
Get a stream of values.- Returns:
- Stream of
Values.Valueobjects.
-
list
-
get
Get the value at a specific index.- Parameters:
index- Index.- Returns:
- Value at the index.
-
size
public int size()Get the number of values.- Returns:
- Size.
-
toUnit
Format aValues.Valuewith its unit.- Parameters:
v- Value object.- Returns:
- Formatted string.
-
toUnit
Format a double value with its unit.- Parameters:
v- Value.- Returns:
- Formatted string.
-
toString
-
isBuilt
public boolean isBuilt()Check if the values are built.- Returns:
- True if built.
-
colorize
public void colorize()Automatically assign colors to values that don't have one. -
buildStyles
Builds and returns the styles associated with all values in the collection. Only values that are instances ofStyledValueare processed, and their individual styles are appended to the result.- Parameters:
node- The SVG where the styles are being used.- Returns:
- A concatenated string of styles for all
StyledValueobjects in the collection.
-