Class VisualSet<T>

java.lang.Object
com.amalgamasimulation.charts.visualsets.VisualSet<T>
Type Parameters:
T - visual set data elements type
All Implemented Interfaces:
IUpdatePolicyPropertyOwner, IAbstractChartVisualSet
Direct Known Subclasses:
AbstractGridLineVisualSet, AbstractLineVisualSet, BarLabeledVisualSet, BoxAndWhiskerVisualSet, ConnectionVisualSet, LabeledVisualSet, LineBarVisualSet, PointsVisualSet, TriangleMarkerVisualSet

public abstract class VisualSet<T> extends Object implements IAbstractChartVisualSet, IUpdatePolicyPropertyOwner
Abstract parent class for all visual sets. A visual set is an object that knows how to extract the data from some source and how to present it on a specific chart. Note that visual sets do not store the data. Visual sets provide the information about colors, number formats, line widths of plots, etc.

Typically, a visual set takes a collection of data elements and contains a set of extractor methods that specify how to extract colors, text labels, etc from these data elements.

Author:
Aleksey Kirillov
  • Field Details

  • Constructor Details

    • VisualSet

      public VisualSet(String name, Supplier<List<T>> dataElementsProvider, Function<T,Double> argumentExtractor)
      Constructs a VisualSet with given name, data elements and arguments extractor, i.e. a function that specifies the rule for extracting an argument 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
      argumentExtractor - a function that specifies the rule for extracting an argument from a data element
  • Method Details

    • setTooltipText

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

      public abstract VisualSet<T>.VisualElement createVisualElement(T contents)
      Creates a new instance of VisualSet<T>.VisualElement corresponding to the current VisualSet type.
      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
    • addMouseEnterHandler

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

      public VisualSet<T> removeMouseEnterHandler(BiConsumer<T,javafx.scene.input.MouseEvent> handler)
      Removes the mouse enter action.
      Parameters:
      handler - new mouse enter action
      Returns:
      reference to this object
    • addMouseExitHandler

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

      public VisualSet<T> removeMouseExitHandler(BiConsumer<T,javafx.scene.input.MouseEvent> handler)
      Removes the mouse exit action.
      Parameters:
      handler - removed mouse exit action
      Returns:
      reference to this object
    • addMousePressedHandler

      public VisualSet<T> addMousePressedHandler(BiConsumer<T,javafx.scene.input.MouseEvent> handler)
      Adds the action to be executed every time a mouse button is pressed.
      Parameters:
      handler - new mouse button pressed action
      Returns:
      reference to this object
    • removeMousePressedHandler

      public VisualSet<T> removeMousePressedHandler(BiConsumer<T,javafx.scene.input.MouseEvent> handler)
      Removes the previously added mouse button press action.
      Parameters:
      handler - removed mouse button press action
      Returns:
      reference to this object
    • getMouseEnterHandlers

      public List<BiConsumer<T,javafx.scene.input.MouseEvent>> getMouseEnterHandlers()
      Returns the list of the actions to be executed every time a mouse enters to any visual element borders.
      Returns:
      the list of the actions to be executed every time a mouse enters to any visual element borders
    • getMouseExitHandlers

      public List<BiConsumer<T,javafx.scene.input.MouseEvent>> getMouseExitHandlers()
      Returns the list of the actions to be executed every time the mouse exits the previously entered element's bounds.
      Returns:
      the list of the actions to be executed every time the mouse exits the previously entered element's bounds
    • getMousePressedHandlers

      public List<BiConsumer<T,javafx.scene.input.MouseEvent>> getMousePressedHandlers()
      Return the list of the actions to be executed every time a mouse button is pressed.
      Returns:
      the list of the actions to be executed every time a mouse button is pressed
    • addContextMenuHandler

      public VisualSet<T> addContextMenuHandler(VisualSet.ContextMenuHandler<T> contextMenuHandler)
      Adds the action to be executed every time a context menu for given data element is called.
      Parameters:
      contextMenuHandler - context menu call action
      Returns:
      reference to this object
    • removeContextMenuHandler

      public VisualSet<T> removeContextMenuHandler(VisualSet.ContextMenuHandler<T> contextMenuHandler)
      Removes the action to be executed every time a context menu for given data element is called.
      Parameters:
      contextMenuHandler - context menu call action
      Returns:
      reference to this object
    • getContextMenuHandlers

      public List<VisualSet.ContextMenuHandler<T>> getContextMenuHandlers()
      Return the list of the actions to be executed every time a context menu for given data element is called.
      Returns:
      the list of the actions to be executed every time a context menu for given data element is called
    • isNeedsUpdate

      public boolean isNeedsUpdate()
      Returns true if VisualSet structure needs to be recalculated.

      The recalculation will be done the next time the chart requests data from this VisualSet.

      Returns:
      true if VisualSet structure needs to be recalculated, false otherwise
    • getDataElements

      public List<T> getDataElements()
      Returns the actual list of all data elements.
      Returns:
      the actual list of all data elements
    • getArgument

      public double getArgument(T element)
      Returns the argument for given data element. Argument is a numeric value on X-axis in which the visual element for the given data element is located.
      Parameters:
      element - data element for which the argument for given data element is being checked
      Returns:
      the argument for given data element
    • getTooltipText

      public String getTooltipText(T element)
      Returns the text that is displayed on the popup tooltip above the visual element that represents the given data element.
      Parameters:
      element - data element for which the tooltip text is being checked
      Returns:
      the text that is displayed on the popup tooltip
    • update

      public void update()
      Raises the flag of the need for a recalculation of the structure of this VisualSet.

      The recalculation will be done the next time the chart requests data from this VisualSet.

      Recalculation involves updating the list of elements, their sequence, as well as additional properties of their display.

    • getName

      public String getName()
      Description copied from interface: IAbstractChartVisualSet
      Returns visual set name i.e. the String is used to sort and name the visual sets on the chart.
      Specified by:
      getName in interface IAbstractChartVisualSet
      Returns:
      visual set name
    • 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 IAbstractChartVisualSet
      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 IAbstractChartVisualSet
      Returns:
      the maximum possible value that stored in the current data elements list
    • addVisibilityChangeHandler

      public VisualSet<T> 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
      Parameters:
      visibilityChangeHandler - visibility change action
      Returns:
      reference to this object
    • removeVisibilityChangeHandler

      public VisualSet<T> removeVisibilityChangeHandler(Consumer<VisibilityChangeDescriptor<? extends IAbstractChartVisualSet>> visibilityChangeHandler)
      Description copied from interface: IAbstractChartVisualSet
      Removes the action to be executed every time the visibility of this VisualSet is changed.
      Specified by:
      removeVisibilityChangeHandler in interface IAbstractChartVisualSet
      Parameters:
      visibilityChangeHandler - visibility change action
      Returns:
      reference to this object
    • addVisualSetChangeHandler

      public void addVisualSetChangeHandler(IVisualSetListener handler)
      Description copied from interface: IAbstractChartVisualSet
      Adds the action to be executed every time the elements list of this VisualSet is changed.
      Specified by:
      addVisualSetChangeHandler in interface IAbstractChartVisualSet
      Parameters:
      handler - visibility change action
    • removeVisualSetChangeHandler

      public void removeVisualSetChangeHandler(IVisualSetListener handler)
      Description copied from interface: IAbstractChartVisualSet
      Removes the action to be executed every time the elements list of this VisualSet is changed.
      Specified by:
      removeVisualSetChangeHandler in interface IAbstractChartVisualSet
      Parameters:
      handler - visibility change action
    • getUpdatePolicy

      public VisualSet.UpdatePolicy getUpdatePolicy()
      Description copied from interface: IAbstractChartVisualSet
      Return the current VisualSet.UpdatePolicy.
      Specified by:
      getUpdatePolicy in interface IAbstractChartVisualSet
      Specified by:
      getUpdatePolicy in interface IUpdatePolicyPropertyOwner
      Returns:
      the current VisualSet.UpdatePolicy
    • setUpdatePolicy

      public VisualSet<T> 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
      Parameters:
      updatePolicy - new VisualSet.UpdatePolicy i.e. the VisualSet update control rule
      Returns:
      reference to this object
    • getVisibilityChangeHandlers

      public List<Consumer<VisibilityChangeDescriptor<? extends IAbstractChartVisualSet>>> getVisibilityChangeHandlers()
      Description copied from interface: IAbstractChartVisualSet
      Return the list of the actions to be executed every time the visibility of this VisualSet is changed.
      Specified by:
      getVisibilityChangeHandlers in interface IAbstractChartVisualSet
      Returns:
      the list of the actions to be executed every time the visibility of this VisualSet is changed
    • setMouseTransparent

      public IAbstractChartVisualSet 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
      Parameters:
      mouseTransparent - new value of property mouseTransparent
      Returns:
      reference to this object
    • isMouseTransparent

      public boolean isMouseTransparent()
      Description copied from interface: IAbstractChartVisualSet
      Returns 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:
      isMouseTransparent in interface IAbstractChartVisualSet
      Returns:
      the value of the property mouseTransparent
    • recalculateVisualElements

      protected void recalculateVisualElements()
    • addVisualElement

      protected void addVisualElement(int injectionIndex, VisualSet<T>.VisualElement visualElement)
    • addVisualElement

      protected void addVisualElement(VisualSet<T>.VisualElement visualElement)
    • removeVisualElement

      protected void removeVisualElement(VisualSet<T>.VisualElement visualElement)
    • clearDependencies

      protected void clearDependencies(VisualSet<T>.VisualElement visualElement)
    • sortVisualElements

      protected void sortVisualElements()
    • getVisibleVisualElementsCount

      public int getVisibleVisualElementsCount(double beginArgument, double endArgument)
      Description copied from interface: IAbstractChartVisualSet
      Returns the number of VisualElements drawn within the bounds of the specified begin and end X-axis arguments.
      Specified by:
      getVisibleVisualElementsCount in interface IAbstractChartVisualSet
      Parameters:
      beginArgument - begin bounds X-axis argument
      endArgument - end bounds X-axis argument
      Returns:
      the number of VisualElements drawn within the bounds of the specified begin and end X-axis arguments
    • getVisibleVisualElementIndex

      protected int getVisibleVisualElementIndex(double argument, List<? extends VisualSet<T>.VisualElement> visualElements, boolean searchByEndArgument)
    • getVisualElements

      public List<? extends VisualSet<T>.VisualElement> 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 IAbstractChartVisualSet
      Parameters:
      recalculationRequired - flag of the need to recalculate the visual elements
      Returns:
      the list of visual elements corresponding to current data elements
    • updateMinMaxArgumentsValues

      protected void updateMinMaxArgumentsValues(List<VisualSet<T>.VisualElement> visualElements)
    • getContents

      public List<T> getContents()
      Description copied from interface: IAbstractChartVisualSet
      Returns the list of visual set contents.
      Specified by:
      getContents in interface IAbstractChartVisualSet
      Returns:
      the list of visual set contents
    • getInjectionIndex

      protected int getInjectionIndex(List<VisualSet<T>.VisualElement> list, VisualSet<T>.VisualElement element, T contents, int contentsIndex, Map<VisualSet<T>.VisualElement,Double> beginArgumentsCache)
    • toString

      public String toString()
      Overrides:
      toString in class Object