java.lang.Object
com.amalgamasimulation.desktop.html.HTMLTag
com.amalgamasimulation.desktop.html.charts.HTMLChart
All Implemented Interfaces:
HTMLConvertable
Direct Known Subclasses:
HTMLBarChart, HTMLHistogramChart, HTMLLineChart

public class HTMLChart extends HTMLTag
The HTMLChart class provides base functionality for creating HTML-based charts using the ApexCharts library (https://apexcharts.com/). Handles chart container initialization, visual set processing, and JavaScript rendering configuration.
Author:
Alexey Glazyrin
  • Field Details

    • options

      protected com.amalgamasimulation.desktop.html.charts.ApexOptions options
    • processor

      protected final com.amalgamasimulation.desktop.html.charts.ApexConfigProcessor processor
  • Constructor Details

    • HTMLChart

      public HTMLChart(AbstractVisualSetContainer<?> visualSetContrainer)
      Constructs a new HTMLChart instance with the specified chart.
      Parameters:
      visualSetContrainer - the visualSetContrainer to render
    • HTMLChart

      public HTMLChart(IAbstractChartVisualSet... visualSets)
      Constructs a new HTMLChart instance from individual visual sets.
      Parameters:
      visualSets - array of visual sets to display in the chart
    • HTMLChart

      public HTMLChart(List<IAbstractChartVisualSet> listVS)
      Constructs a new HTMLChart instance from a list of visual sets.
      Parameters:
      listVS - list of visual sets to configure chart data and appearance
    • HTMLChart

      protected HTMLChart()
      Constructs a new HTMLChart instance. Initializes the chart container and script tag.
  • Method Details

    • toHTML

      public String toHTML(Set<String> outStrings)
      Generates the HTML representation of the chart, including the script to render it.
      Specified by:
      toHTML in interface HTMLConvertable
      Overrides:
      toHTML in class HTMLTag
      Parameters:
      outStrings - set of unique strings of text content
      Returns:
      the HTML string representation of the chart
    • preRenderJS

      protected void preRenderJS(Set<String> outStrings)
    • copy

      public HTMLChart copy(Map<String,String> stringsSubstitutionMap)
      Description copied from interface: HTMLConvertable
      Creates a deep copy of this HTMLConvertable element, preserving the element's structure while substituting text content using the provided translation mapping.
      Specified by:
      copy in interface HTMLConvertable
      Overrides:
      copy in class HTMLTag
      Parameters:
      stringsSubstitutionMap - a map where keys are original text strings (as collected by HTMLConvertable.toHTML(Set)) and values are their translations. During copying, any encountered text content present in this map will be replaced with its translated version.
      Returns:
      a new independent copy of this HTMLConvertable instance with translated content
    • relativeWidth

      public HTMLChart relativeWidth(double width)
      Sets the relative width of the chart container as a percentage.
      Overrides:
      relativeWidth in class HTMLTag
      Parameters:
      width - the width as a percentage (e.g., 0.5 for 50%)
      Returns:
      this HTMLChart instance for method chaining
    • relativeHeight

      public HTMLChart relativeHeight(double height)
      Sets the relative height of the chart container as a percentage.
      Overrides:
      relativeHeight in class HTMLTag
      Parameters:
      height - the height as a percentage (e.g., 0.5 for 50%)
      Returns:
      this HTMLChart instance for method chaining
    • title

      public HTMLChart title(String title)
      Sets the title of the chart.
      Parameters:
      title - the title text
      Returns:
      this HTMLChart instance for method chaining
    • titleColor

      public HTMLChart titleColor(Color color)
      Sets the color of the chart title.
      Parameters:
      color - the color of the title
      Returns:
      this HTMLChart instance for method chaining
    • titleFont

      public HTMLChart titleFont(FontDescriptor fontDescriptor)
      Sets the font of the chart title.
      Parameters:
      fontDescriptor - the font descriptor to use for the title
      Returns:
      this HTMLChart instance for method chaining
    • xAxisValueConverter

      public HTMLChart xAxisValueConverter(Function<Object,String> xAxisValueConverter)
      Sets a converter function for X-axis values formatting.
      Parameters:
      xAxisValueConverter - function to convert raw X-values to display strings
      Returns:
      this HTMLChart instance for method chaining
    • xAxisTitle

      public HTMLChart xAxisTitle(String title)
      Sets the title for the X-axis.
      Parameters:
      title - axis label text
      Returns:
      this HTMLChart instance for method chaining
    • yAxisTitle

      public HTMLChart yAxisTitle(String title)
      Sets the title for the Y-axis.
      Parameters:
      title - axis label text
      Returns:
      this HTMLChart instance for method chaining
    • yAxisLabelsDecimalSigns

      public HTMLChart yAxisLabelsDecimalSigns(int decimalSignsCount)
      Configures the number of decimal places to display on Y-axis labels.
      Parameters:
      decimalSignsCount - the number of decimal digits to display on Y-axis labels. Must be a non-negative integer
      Returns:
      this HTMLChart instance for method chaining
    • titleAlignment

      public HTMLChart titleAlignment(com.amalgamasimulation.desktop.html.charts.ApexOptions.ApexAlign alignment)
      Sets the alignment of the chart title.
      Parameters:
      alignment - the alignment of the title
      Returns:
      this HTMLChart instance for method chaining
    • font

      public HTMLChart font(FontDescriptor fontDescriptor)
      Sets the font of the chart.
      Overrides:
      font in class HTMLTag
      Parameters:
      fontDescriptor - the font descriptor to use for the chart
      Returns:
      this HTMLChart instance for method chaining
    • stacked

      public HTMLChart stacked(boolean stacked)
      Configures stacked display mode for chart elements.
      Parameters:
      stacked - true to enable stacked visualization, false for grouped
      Returns:
      this HTMLChart instance for method chaining
    • generateScript

      protected String generateScript(List<IAbstractChartVisualSet> listVS, String id, Set<String> outStrings)
      Generates the JavaScript code required to render the chart. Processes visual sets and converts configuration to ApexCharts format.
      Parameters:
      listVS - list of visual sets defining chart data and styles
      id - unique DOM element ID for chart container
      Returns:
      JavaScript code that initializes and renders the chart