Class CanvasChartStyleManager

All Implemented Interfaces:
Lifecycle

public class CanvasChartStyleManager extends NamedResourceHandler<CanvasChartStyleConfig>
Owns the gateway-scoped canvas chart style resources that supply ECharts theme JSON for Perspective canvas charts across every project on the gateway.

Each style is its own named resource (one directory, one config.json), so the platform gives create/rename/duplicate/delete, per-style metadata, and per-style validation for free. The manager registers the resource type — which is what mounts the generic /data/api/v1/resources/... REST API the Gateway web UI edits through — seeds the bundled styles, and resolves a requested name to the JSON that gets served.

Styles reach the front-end through CanvasChartStyleRoutes, keyed off a content hash that rides the project-load response. A running session does not learn about a style edit — the hash, and the style it resolves to, are fixed for the life of the session; a new value is only picked up on the next session load.

Lifecycle: call setup() once from the module hook's setup() phase (it must run before the platform ConfigurationManager mounts the generic resource routes, otherwise the type's REST routes never mount), then AbstractLifecycle.startup() from startup() and AbstractLifecycle.shutdown() on module shutdown.

  • Constructor Details

    • CanvasChartStyleManager

      public CanvasChartStyleManager(PerspectiveContext perspectiveContext)
  • Method Details

    • setup

      public void setup()
      Registers the resource type and seeds the bundled styles. Must run before the platform's ConfigurationManager mounts the generic resource routes in its own onStartup().
    • onResourcesUpdated

      protected void onResourcesUpdated(List<DecodedResource<CanvasChartStyleConfig>> resources)
      Description copied from class: NamedResourceHandler
      Called each time the overall set of resources changes in any way. Called after added, updated, and removed are called.
      Overrides:
      onResourcesUpdated in class NamedResourceHandler<CanvasChartStyleConfig>
    • loggable

      public static String loggable(@Nullable String text)
      Returns text with control characters and line breaks replaced, so text taken from a request or a resource name logs as one line.
      Parameters:
      text - the text to log; null is returned as "null".
      Returns:
      the text, safe to put in a single log line.
    • getStyleJsonByName

      public com.inductiveautomation.ignition.common.gson.JsonObject getStyleJsonByName(@Nullable String styleName)
      Returns the ECharts theme JSON for the style stored under styleName — what a page author's chartStyle property names. The name is matched against resource names only, bundled styles included, so "light" always means the bundled light style, even when an authored style claims the light theme. A name matching no style falls back to the bundled default derived from the name (see ChartStyleUtil.getDefaultStyleJson(String)) and logs a warning once per name, since the style was most likely renamed or deleted and the session would otherwise switch styles with no sign of why.

      The returned object is shared — treat it as read-only and deep-copy before mutating.

    • getStyleJsonForTheme

      public com.inductiveautomation.ignition.common.gson.JsonObject getStyleJsonForTheme(@Nullable String themeName)
      Returns the ECharts theme JSON for the Perspective theme themeName: the first style whose CanvasChartStyleConfig.themes() claims it, or else the bundled default derived from the name (see ChartStyleUtil.getDefaultStyleJson(String)).

      Resource names play no part here. The bundled styles claim every shipped theme of their mode, and resolutionOrder() puts authored styles ahead of them, so "copy a bundled style and assign it the theme" makes the copy win.

      The returned object is shared — treat it as read-only and deep-copy before mutating.

    • getOfflineChartStyles

      public CanvasChartStyleManager.OfflineChartStyles getOfflineChartStyles(Collection<String> themeNames)
    • getStyleNames

      public List<String> getStyleNames()
      Returns:
      the resource name of every style, bundled ones included, sorted alphabetically. These are the values a page author's chartStyle property can name.
    • getChartStylesHash

      public @NonNull String getChartStylesHash()
      Returns:
      a string identifying the current canvas chart styles, used purely to cache-bust the style route. Built from the platform's per-resource content digests, so it changes whenever a style's content changes and whenever one is added or removed.