Package com.storedobject.svg.chart
Class Values
java.lang.Object
com.storedobject.svg.chart.Values
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordRepresents a single data point in the chart. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(Values.Value value) Add aValues.Valueto the collection.voidAdd a value with a label.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 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 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 StringtoString(double v) Convert a double to string with 2 decimal places.static StringConvert a double to string with unit and decimal places.static StringConvert a double to string with unit.toUnit(double v) Format a double value with its unit.toUnit(double v, int decimals) Format a double value with its unit and specified decimals.Format aValues.Valuewith its unit.toUnit(Values.Value v, int decimals) Format aValues.Valuewith its unit and specified decimals.
-
Constructor Details
-
Values
public Values()Constructor. -
Values
-
-
Method Details
-
setUnit
-
getUnit
-
setLabelName
Set the label name (typically used as 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 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.- Parameters:
value- Value object to add.
-
add
Add a value with a label.- Parameters:
label- Label for the value.value- Value.
-
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 and specified decimals.- Parameters:
v- Value object.decimals- Number of decimal places.- Returns:
- Formatted string.
-
toUnit
Format aValues.Valuewith its unit.- Parameters:
v- Value object.- Returns:
- Formatted string.
-
toUnit
Format a double value with its unit and specified decimals.- Parameters:
v- Value.decimals- Number of decimal places.- Returns:
- Formatted string.
-
toUnit
Format a double value with its unit.- Parameters:
v- Value.- Returns:
- Formatted string.
-
toString
Convert a double to string with 2 decimal places.- Parameters:
v- Value.- Returns:
- Formatted string.
-
toString
-
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.
-