Class BarVisualSet<T,C>

Type Parameters:
T - visual set data elements type
C - data categories type
All Implemented Interfaces:
IAbstractBarVisualSet<T,C>, IUpdatePolicyPropertyOwner, IAbstractChartVisualSet, IBarChartVisualSet
Direct Known Subclasses:
WaterfallVisualSet

public class BarVisualSet<T,C> extends BarLabeledVisualSet<T,C> implements IAbstractBarVisualSet<T,C>, IBarChartVisualSet
Visual set for drawing bars.

Can be drawn on AbstractBarChart.

Used to draw the statistical data by categories.

Author:
Aleksey Kirillov
  • Constructor Details

    • BarVisualSet

      public BarVisualSet(String name, Supplier<List<T>> dataElementsProvider, BiFunction<T,C,Double> valueExtractor, List<C> categories)
      Constructs a BarVisualSet with given name, data elements, categories and value extractor, i.e. a function that specifies the rule for extracting a value from a data element.
      Parameters:
      name - visual set name is used to sort and name the visual sets on the chart
      dataElementsProvider - data elements list provider. The provider is invalidated every time the chart is beging redrawn
      categories - the list of data categories
  • Method Details

    • setColumnWidthFraction

      public BarVisualSet<T,C> setColumnWidthFraction(double columnWidthFraction)
      Sets the width fraction to region allocated for each individual category-bar. Note than depending on the type of BarsLayout, the visual can be drawn with category-bars stacked on top of each other or a series of category-bars in a row. The fraction is applied to the region calculation results for each data element with respect to summary bars width fraction, set by the call setVisualWidthFraction(double). The resulting region is divided by the number of category-bars arranged in a row horizontally and then the width of each bar is multiplied by columnWidthFraction.

      The value must be greater than zero and not greater than 1.

      The default value is 0.8.

      Parameters:
      columnWidthFraction -
      Returns:
      reference to this object
    • setVisualWidthFraction

      public BarVisualSet<T,C> setVisualWidthFraction(double visualWidthFraction)
      Sets the fraction width of the region in which bars are drawn. Fraction is calculated relative to the width of the region allocated for each data element. By controlling this parameter, the total width of the bars region is configured, in which bars can be drawn. As a result the width of the bars themselves can be adjusted.

      The value must be greater than zero and not greater than 1.

      The default value is 0.8.

      Parameters:
      visualWidthFraction - the fraction width of the region in which bars are drawn
      Returns:
      reference to this object
    • setCategoriesComparator

      public BarVisualSet<T,C> setCategoriesComparator(Comparator<C> categoriesComparator)
      Specifies the comparator used to sort the categories. Sorting affects the display order of the bars and the order of the legend elements.
      Parameters:
      categoriesComparator - the comparator used to sort the categories
      Returns:
      reference to this object
    • getVisualWidthFraction

      public double getVisualWidthFraction()
      Returns the fraction width of the region in which category-bars are drawn.
      Returns:
      the fraction width of the region in which category-bars are drawn
    • getColumnWidthFraction

      public double getColumnWidthFraction()
      Description copied from interface: IAbstractBarVisualSet
      Returns the width fraction to region allocated for each individual category-bar.
      Specified by:
      getColumnWidthFraction in interface IAbstractBarVisualSet<T,C>
      Returns:
      the width fraction to region allocated for each individual category-bar
    • setElementText

      public BarVisualSet<T,C> setElementText(Function<T,String> elementTextExtractor)
      Description copied from interface: IAbstractBarVisualSet
      Sets the label text for each data element. This label is displayed on the ticks of the X-axis, below the corresponding bars.
      Specified by:
      setElementText in interface IAbstractBarVisualSet<T,C>
      Parameters:
      elementTextExtractor - the text of the bar label
      Returns:
      reference to this object
    • getElementText

      public String getElementText(T element)
      Description copied from interface: IAbstractBarVisualSet
      Returns the label text for each data element.
      Specified by:
      getElementText in interface IAbstractBarVisualSet<T,C>
      Parameters:
      element - data element for which the label text is being checked
      Returns:
      the label text for each data element
    • setLegendLabelText

      public BarVisualSet<T,C> setLegendLabelText(Function<C,String> legendLabelTextExtractor)
      Description copied from interface: IAbstractBarVisualSet
      Sets the legend label text for each category.
      Specified by:
      setLegendLabelText in interface IAbstractBarVisualSet<T,C>
      Parameters:
      legendLabelTextExtractor - the legend label text extractor, i.e. method returning text depending on the category
      Returns:
      reference to this object
    • setBackgroundColor

      public BarVisualSet<T,C> setBackgroundColor(Function<C,Color> backgroundColorExtractor)
      Description copied from interface: IAbstractBarVisualSet
      Sets the background color for each category. The color may be different for different categories and it does not depend on different data elements. Also used to display a color icon in the Legend.
      Specified by:
      setBackgroundColor in interface IAbstractBarVisualSet<T,C>
      Parameters:
      backgroundColorExtractor - the background color extractor, i.e. method returning color depending on the category
      Returns:
      reference to this object
    • setBorderColor

      public BarVisualSet<T,C> setBorderColor(Function<C,Color> borderColorExtractor)
      Description copied from interface: IAbstractBarVisualSet
      Sets the border color for each category. The color may be different for different categories and it does not depend on different data elements.
      Specified by:
      setBorderColor in interface IAbstractBarVisualSet<T,C>
      Parameters:
      borderColorExtractor - the border color extractor, i.e. method returning color depending on the category
      Returns:
      reference to this object
    • setBorderWidth

      public BarVisualSet<T,C> setBorderWidth(Function<C,Double> borderWidthExtractor)
      Description copied from interface: IAbstractBarVisualSet
      Sets the border width in pixels for each category. The width may be different for different categories and it does not depend on different data elements.
      Specified by:
      setBorderWidth in interface IAbstractBarVisualSet<T,C>
      Parameters:
      borderWidthExtractor - the border width extractor, i.e. method returning the width depending on the category
      Returns:
      reference to this object
    • setTooltipText

      public BarVisualSet<T,C> setTooltipText(Function<T,String> tooltipTextExtractor)
      Description copied from class: VisualSet
      Adds tooltip text to display when the mouse is hovered over a visual element representing given data element.
      Specified by:
      setTooltipText in class VisualSet<T>
      Parameters:
      tooltipTextExtractor - a function that specifies the rule for extracting a tooltip text from a data element
      Returns:
      reference to this object
    • setUpdatePolicy

      public BarVisualSet<T,C> setUpdatePolicy(VisualSet.UpdatePolicy updatePolicy)
      Description copied from interface: IAbstractChartVisualSet
      Sets the new VisualSet.UpdatePolicy i.e. the VisualSet update control rule.
      Specified by:
      setUpdatePolicy in interface IAbstractChartVisualSet
      Specified by:
      setUpdatePolicy in interface IUpdatePolicyPropertyOwner
      Overrides:
      setUpdatePolicy in class VisualSet<T>
      Parameters:
      updatePolicy - new VisualSet.UpdatePolicy i.e. the VisualSet update control rule
      Returns:
      reference to this object
    • getCategories

      public List<C> getCategories()
      Description copied from interface: IAbstractBarVisualSet
      Returns the list of data categories.
      Specified by:
      getCategories in interface IAbstractBarVisualSet<T,C>
      Returns:
      the list of data categories
    • getBackgroundColor

      public Color getBackgroundColor(C category)
      Description copied from interface: IAbstractBarVisualSet
      Returns the background color for given category.
      Specified by:
      getBackgroundColor in interface IAbstractBarVisualSet<T,C>
      Parameters:
      category - category for which the background color is being checked
      Returns:
      the background color for given category
    • getBorderColor

      public Color getBorderColor(C category)
      Description copied from interface: IAbstractBarVisualSet
      Returns the border color for given category.
      Specified by:
      getBorderColor in interface IAbstractBarVisualSet<T,C>
      Parameters:
      category - category for which the border color is being checked
      Returns:
      the border color for given category
    • getBorderWidth

      public double getBorderWidth(C category)
      Description copied from interface: IAbstractBarVisualSet
      Returns the border width in pixels for given category.
      Specified by:
      getBorderWidth in interface IAbstractBarVisualSet<T,C>
      Parameters:
      category - category for which the border width in pixels is being checked
      Returns:
      the border width in pixels for given category
    • getLegendLabelText

      public String getLegendLabelText(C category)
      Description copied from interface: IAbstractBarVisualSet
      Returns the legend label text for given category.
      Specified by:
      getLegendLabelText in interface IAbstractBarVisualSet<T,C>
      Parameters:
      category - category for which the legend label text is being checked
      Returns:
      the legend label text for given category
    • setBarLabelText

      public BarVisualSet<T,C> setBarLabelText(Function<T,String> barLabelTextExtractor)
      Description copied from class: BarLabeledVisualSet
      Sets the label text for each visual element. This label is displayed above the corresponding bars.
      Overrides:
      setBarLabelText in class BarLabeledVisualSet<T,C>
      Parameters:
      barLabelTextExtractor - the text of the bar label
      Returns:
      reference to this object
    • setBarLabelFontSize

      public BarVisualSet<T,C> setBarLabelFontSize(Function<T,Double> barLabelFontSizeExtractor)
      Description copied from class: BarLabeledVisualSet
      Sets the label font size for each visual element. This label is displayed above the corresponding bars.
      Overrides:
      setBarLabelFontSize in class BarLabeledVisualSet<T,C>
      Parameters:
      barLabelFontSizeExtractor - the font size of the bar label
      Returns:
      reference to this object
    • setBarLabelColor

      public BarVisualSet<T,C> setBarLabelColor(Function<T,Color> barLabelColorExtractor)
      Description copied from class: BarLabeledVisualSet
      Sets the label color for each visual element. This label is displayed above the corresponding bars.
      Overrides:
      setBarLabelColor in class BarLabeledVisualSet<T,C>
      Parameters:
      barLabelColorExtractor - the color of the bar label
      Returns:
      reference to this object
    • setMouseTransparent

      public BarVisualSet<T,C> setMouseTransparent(boolean mouseTransparent)
      Description copied from interface: IAbstractChartVisualSet
      Sets the value of the property mouseTransparent. If true, this VisualSet is completely transparent to mouse events. When choosing target for mouse event, VisualSets with mouseTransparent set to true won't be taken into account.
      Specified by:
      setMouseTransparent in interface IAbstractChartVisualSet
      Overrides:
      setMouseTransparent in class VisualSet<T>
      Parameters:
      mouseTransparent - new value of property mouseTransparent
      Returns:
      reference to this object
    • getMinArgument

      public double getMinArgument()
      Description copied from interface: IAbstractChartVisualSet
      Returns the minimum possible value that stored in the current data elements list.
      Specified by:
      getMinArgument in interface IAbstractBarVisualSet<T,C>
      Specified by:
      getMinArgument in interface IAbstractChartVisualSet
      Overrides:
      getMinArgument in class VisualSet<T>
      Returns:
      the minimum possible value that stored in the current data elements list
    • getMaxArgument

      public double getMaxArgument()
      Description copied from interface: IAbstractChartVisualSet
      Returns the maximum possible value that stored in the current data elements list.
      Specified by:
      getMaxArgument in interface IAbstractBarVisualSet<T,C>
      Specified by:
      getMaxArgument in interface IAbstractChartVisualSet
      Overrides:
      getMaxArgument in class VisualSet<T>
      Returns:
      the maximum possible value that stored in the current data elements list
    • getPercentOfMaxValue

      public double getPercentOfMaxValue()
      Description copied from interface: IAbstractBarVisualSet
      Returns the ratio of the value for the maximum group to the total sum of the all values across the entire statistics.
      Specified by:
      getPercentOfMaxValue in interface IAbstractBarVisualSet<T,C>
      Returns:
      the ratio of the value for the maximum group to the total sum of the all values across the entire statistics
    • getPercentOfMaxValue

      public double getPercentOfMaxValue(Predicate<C> categoryPredicate)
      Description copied from interface: IAbstractBarVisualSet
      Returns the ratio of the value for the maximum group to the total sum of the all values across the entire statistics.

      Considers only the categories filtered by the corresponding predicate.

      Specified by:
      getPercentOfMaxValue in interface IAbstractBarVisualSet<T,C>
      Parameters:
      categoryPredicate - filter for categories for which the ratio is calculated
      Returns:
      the ratio of the value for the maximum group to the total sum of the all values across the entire statistics
    • getValue

      public double getValue(T element, C category)
      Description copied from interface: IAbstractBarVisualSet
      Returns the value for given category within the given data element.
      Specified by:
      getValue in interface IAbstractBarVisualSet<T,C>
      Parameters:
      element - data element for which the total value is being checked
      category - category for which the total value is being checked
      Returns:
      the value for given category within the given data element
    • getSummaryValue

      public double getSummaryValue(T element)
      Description copied from interface: IAbstractBarVisualSet
      Returns the total value for all categories within the given data element.
      Specified by:
      getSummaryValue in interface IAbstractBarVisualSet<T,C>
      Parameters:
      element - data element for which the total value is being checked
      Returns:
      the total value for all categories within the given date element
    • getSummaryValue

      public double getSummaryValue(T element, Predicate<C> categoryPredicate)
      Description copied from interface: IAbstractBarVisualSet
      Returns the total value for specified categories within the specified data element.
      Specified by:
      getSummaryValue in interface IAbstractBarVisualSet<T,C>
      Parameters:
      element - data element for which the total value is being checked
      categoryPredicate - filter for categories for which the amount is calculated
      Returns:
      the total value for specified categories within the specified data element
    • getMaxGroupValue

      public double getMaxGroupValue()
      Description copied from interface: IAbstractBarVisualSet
      Returns the maximum value for any data group within all existed data elements. The data group in the case of a histogram is the range of the X-axis arguments, and in the case of a bar chart, each individual data element.
      Specified by:
      getMaxGroupValue in interface IAbstractBarVisualSet<T,C>
      Returns:
      the maximum value for any data group within all existed data elements
    • getMaxGroupValue

      public double getMaxGroupValue(Predicate<C> categoryPredicate)
      Description copied from interface: IAbstractBarVisualSet
      Returns the maximum value for any data group within all existed data elements.

      The data group in the case of a histogram is the range of the X-axis arguments, and in the case of a bar chart, each individual data element.

      Considers only the categories filtered by the corresponding predicate.

      Specified by:
      getMaxGroupValue in interface IAbstractBarVisualSet<T,C>
      Parameters:
      categoryPredicate - filter for categories for which the maximum value is calculated
      Returns:
      the maximum value for any data group within all existed data elements
    • getMaxValueByAnyCategory

      public double getMaxValueByAnyCategory()
      Description copied from interface: IAbstractBarVisualSet
      Returns the maximum value for any category within all existed data elements.
      Specified by:
      getMaxValueByAnyCategory in interface IAbstractBarVisualSet<T,C>
      Returns:
      the maximum value for any category within all existed data elements
    • getMaxValueByAnyCategory

      public double getMaxValueByAnyCategory(Predicate<C> categoryPredicate)
      Description copied from interface: IAbstractBarVisualSet
      Returns the maximum value between given filtered categories within all existed data elements.
      Specified by:
      getMaxValueByAnyCategory in interface IAbstractBarVisualSet<T,C>
      Parameters:
      categoryPredicate - filter for categories for which the maximum value is calculated
      Returns:
      the maximum value between given filtered categories within all existed data elements
    • setLabelText

      public BarVisualSet<T,C> setLabelText(LabelSide labelSide, BiFunction<T,C,String> labelText, BiFunction<T,C,Double> labelTextSize, BiFunction<T,C,Color> labelTextColor)
      Description copied from class: BarLabeledVisualSet
      Sets the labels of the bars representing plot data elements. The label of each bar is set independently of the labels on other sides of this bar or the labels on other bars. The label will not be displayed if the specified text is empty.
      Overrides:
      setLabelText in class BarLabeledVisualSet<T,C>
      Parameters:
      labelSide - the LabelSide of bar where the corresponding label will be drawn
      labelText - the text of the label
      labelTextSize - the font size of the label
      labelTextColor - the color of the label
      Returns:
      reference to this object
    • addContextMenuHandler

      public BarVisualSet<T,C> addContextMenuHandler(VisualSet.ContextMenuHandler<T> contextMenuHandler)
      Description copied from class: VisualSet
      Adds the action to be executed every time a context menu for given data element is called.
      Overrides:
      addContextMenuHandler in class VisualSet<T>
      Parameters:
      contextMenuHandler - context menu call action
      Returns:
      reference to this object
    • addMouseEnterHandler

      public BarVisualSet<T,C> addMouseEnterHandler(BiConsumer<T,javafx.scene.input.MouseEvent> handler)
      Description copied from class: VisualSet
      Adds the action to be executed every time mouse enters to any visual element borders.
      Overrides:
      addMouseEnterHandler in class VisualSet<T>
      Parameters:
      handler - new mouse enter action
      Returns:
      reference to this object
    • addMouseExitHandler

      public BarVisualSet<T,C> addMouseExitHandler(BiConsumer<T,javafx.scene.input.MouseEvent> handler)
      Description copied from class: VisualSet
      Adds the action to be executed every time the mouse exits the previously entered element's bounds.
      Overrides:
      addMouseExitHandler in class VisualSet<T>
      Parameters:
      handler - new mouse exit action
      Returns:
      reference to this object
    • addMousePressedHandler

      public BarVisualSet<T,C> addMousePressedHandler(BiConsumer<T,javafx.scene.input.MouseEvent> handler)
      Description copied from class: VisualSet
      Adds the action to be executed every time a mouse button is pressed.
      Overrides:
      addMousePressedHandler in class VisualSet<T>
      Parameters:
      handler - new mouse button pressed action
      Returns:
      reference to this object
    • addVisibilityChangeHandler

      public BarVisualSet<T,C> addVisibilityChangeHandler(Consumer<VisibilityChangeDescriptor<? extends IAbstractChartVisualSet>> visibilityChangeHandler)
      Description copied from interface: IAbstractChartVisualSet
      Adds the action to be executed every time the visibility of this VisualSet is changed.
      Specified by:
      addVisibilityChangeHandler in interface IAbstractChartVisualSet
      Overrides:
      addVisibilityChangeHandler in class VisualSet<T>
      Parameters:
      visibilityChangeHandler - visibility change action
      Returns:
      reference to this object
    • getVisualElements

      public List<BarVisualSet<T,C>.BarVisualElement> getVisualElements(boolean recalculationRequired)
      Description copied from interface: IAbstractChartVisualSet
      Returns the list of visual elements corresponding to current data elements. Cannot be changed by the user.
      Specified by:
      getVisualElements in interface IAbstractBarVisualSet<T,C>
      Specified by:
      getVisualElements in interface IAbstractChartVisualSet
      Specified by:
      getVisualElements in interface IBarChartVisualSet
      Overrides:
      getVisualElements in class VisualSet<T>
      Parameters:
      recalculationRequired - flag of the need to recalculate the visual elements
      Returns:
      the list of visual elements corresponding to current data elements
    • createVisualElement

      public BarVisualSet<T,C>.BarVisualElement createVisualElement(T contents)
      Description copied from class: VisualSet
      Creates a new instance of VisualSet<T>.VisualElement corresponding to the current VisualSet type.
      Specified by:
      createVisualElement in class VisualSet<T>
      Parameters:
      contents - data element for which the VisualSet<T>.VisualElement is being checked
      Returns:
      a new instance of VisualSet<T>.VisualElement corresponding to the current VisualSet type