Skip to content

EN SpeedometerIndicator JSON

roosit edited this page May 12, 2026 · 2 revisions

SpeedometerIndicator JSON

Up | Code | Русский

Purpose

This page describes the JSON that Velitask persists for the SpeedometerIndicator from plugin-example. The indicator class does not write JSON directly: it declares properties in defineProperties(), while runtime layers and SDK properties perform persistence.

The page is meant for plugin authors who need to understand a saved project, a Mixel template, or a .vttp file: where layer placement is stored, where speedometer settings live, and which keys must not be renamed without migration.

Two save modes

An indicator layer has two serialization modes:

Mode Call What is saved
Real Mixel state toJSON(false) Actual size and positionInParent, current properties values.
Template state toJSON(true) maket for future placement in another Mixel, current properties values.

The real state should restore the layer exactly as it existed in the project. A template should be reusable: placement is recalculated, and sensor binding may be selected automatically when inserted.

Common indicator wrapper

The JSON for a concrete indicator is usually the layer payload. A parent container may look like this:

{
  "name": "speedometer",
  "data": {
    "size": { "...": "..." },
    "positionInParent": { "...": "..." },
    "properties": {}
  }
}

This page focuses on the inner data object. The outer name field must match the stable SpeedometerIndicator.NAME, which is speedometer.

Inside data, runtime uses these keys:

Field Mode Meaning
size Real state Absolute layer size in the current Mixel.
positionInParent Real state Absolute layer position inside its parent layer.
maket Template Placement rule used when the layer is added from a template.
properties Both modes SDK indicator settings. For SpeedometerIndicator: speed sensor, scale, font, colors, text template, and arrow stroke width.

Real mixel state

Real state is produced with hasTemplate=false.

Runtime behavior:

  • Unit.toJSON(false) writes size and positionInParent;
  • IndicatorLayer.toJSON(false) adds the properties object;
  • each SDK property writes its own payload through Property.toJSON();
  • DistanceSensorProperty persists concrete sourceId and sensorId.

Shortened form:

{
  "size": { "...": "absolute layer size" },
  "positionInParent": { "...": "absolute layer position" },
  "properties": {
    "Distance": {
      "sourceId": { "...": "source id" },
      "sensorId": { "...": "sensor id" }
    },
    "speedScale": { "...": "selected scale index" },
    "font": {
      "...": "FontProperty fields",
      "color": {
        "r": 255,
        "g": 255,
        "b": 255,
        "a": 255
      }
    },
    "textTemplate": {
      "template": "{curr}",
      "vars": {
        "curr": "%.0f"
      }
    },
    "bgColor": {
      "r": 204,
      "g": 204,
      "b": 204,
      "a": 51
    },
    "scaleColor": {
      "r": 255,
      "g": 255,
      "b": 255,
      "a": 255
    },
    "arrowFillColor": {
      "r": 204,
      "g": 88,
      "b": 84,
      "a": 255
    },
    "arrowStrokeColor": {
      "r": 255,
      "g": 255,
      "b": 255,
      "a": 255
    },
    "arrowStrokeWidth": {
      "...": 2.5
    }
  }
}

The example intentionally shortens parts whose exact shape comes from lower-level State classes (size, positionInParent, sourceId, sensorId, numeric and enum states). For those fields, capture JSON from the current runtime instead of hand-writing the exact form.

Template state

Template state is produced with hasTemplate=true.

Runtime behavior:

  • if the layer has a parent, Unit.toJSON(true) writes maket instead of size and positionInParent;
  • if the layer already has a selected LayerMaket, its preset is saved;
  • if no LayerMaket is selected, runtime captures a proportional layout;
  • IndicatorLayer.toJSON(true) still saves properties;
  • when loading a template, IndicatorLayer.fromJSON(..., true) first applies automatic source selection for all SensorProperty instances;
  • then properties are read by property names.

maket supports three presets:

maket.preset JSON Behavior
auto { "preset": "auto" } Applies layer default parameters. For SpeedometerIndicator, this is defineMaket().
fill { "preset": "fill" } Stretches the layer to fill the parent.
proportional { "preset": "proportional", "x": 0.5, "y": 0.1, "w": 0.25, "h": 0.25 } Stores ratios relative to parent size: x/y position and w/h size.

For SpeedometerIndicator, the initial auto layout is defined in defineMaket():

  • vertical alignment: TOP;
  • horizontal alignment: RIGHT;
  • right/top margins: 50, 50;
  • layer size: 500 x 500.

If the template is exported from an already placed layer, the final JSON may contain captured proportional ratios instead of auto.

Shortened template form:

{
  "maket": {
    "preset": "proportional",
    "x": 0.65,
    "y": 0.05,
    "w": 0.30,
    "h": 0.30
  },
  "properties": {
    "Distance": {
      "sourceId": { "...": "may be replaced by automatic selection" },
      "sensorId": { "...": "may be replaced by automatic selection" }
    },
    "speedScale": { "...": "selected scale" },
    "font": { "...": "font and text color" },
    "textTemplate": {
      "template": "{curr}",
      "vars": {
        "curr": "%.0f"
      }
    }
  }
}

Properties

All settings live inside properties. The object key equals Property.getName(), so these strings are part of the persisted format.

JSON key Java property Type Meaning and default
Distance mDistance DistanceSensorProperty Speed source. Saves sourceId and sensorId. Default binding appears only after source selection or template auto-selection.
speedScale mSpeedScale EnumArrayProperty<SpeedScale> Scale range: 40, 80, 160, or 320 km/h. Code default: SCALE_160.
font mText FontColorProperty Font and color of the centered number. SDK font defaults are defined by FontProperty; text color is stored under nested color.
textTemplate mTemplate TextTemplateProperty Text in the speedometer center. Localization default template: {curr}; variable curr is formatted as %.0f.
bgColor mBgColor ColorProperty Background circle color. Default: rgba(204, 204, 204, 51).
scaleColor mScaleColor ColorProperty Tick and numeric scale color. Default: white rgba(255, 255, 255, 255).
arrowFillColor mArrowFillColor ColorProperty Arrow fill color. Default: rgba(204, 88, 84, 255).
arrowStrokeColor mArrowStrokeColor ColorProperty Arrow outline and center hub color. Default: white rgba(255, 255, 255, 255).
arrowStrokeWidth mArrowStrokeWidth DoubleProperty SVG arrow stroke width. Default: 2.5.

Practical rules:

  • Distance in a template should not be treated as a hard binding: when the template is inserted, runtime first tries to select a suitable sensor automatically.
  • speedScale is saved as EnumArrayProperty state; its user meaning is the selected enum item, not the numeric scale value by itself.
  • font is composite: font data and text color are saved together.
  • textTemplate uses variable names. The speedometer has only curr.
  • Colors are written through r, g, b, a channels.

Examples

Real state

{
  "size": { "...": "real size" },
  "positionInParent": { "...": "real position" },
  "properties": {
    "Distance": {
      "sourceId": { "...": "source id state" },
      "sensorId": { "...": "sensor id state" }
    },
    "speedScale": { "...": "SCALE_160 or another selected index" },
    "textTemplate": {
      "template": "{curr}",
      "vars": {
        "curr": "%.0f"
      }
    },
    "bgColor": {
      "r": 204,
      "g": 204,
      "b": 204,
      "a": 51
    }
  }
}

Template

{
  "maket": {
    "preset": "auto"
  },
  "properties": {
    "Distance": {
      "sourceId": { "...": "may be replaced by auto-selection" },
      "sensorId": { "...": "may be replaced by auto-selection" }
    },
    "speedScale": { "...": "SCALE_160 or another selected index" },
    "arrowStrokeWidth": {
      "...": 2.5
    }
  }
}

These examples show key shape and meaning. For migration tests or exact low-level state documentation, use JSON captured from the current runtime.

Compatibility

JSON stability depends on stable identifiers:

  • Plagin.UID must stay stable: saved projects reference the plugin.
  • SpeedometerIndicator.NAME and getName() must remain speedometer: saved indicator layers reference this name.
  • Property.getName() for each property must stay stable: these are keys inside properties.
  • Renaming speedScale, bgColor, textTemplate, or other property keys without migration means old settings will not be applied.
  • Removing a property is only visually safer: JSON may still contain the old key, but new code will not read it.
  • Property order in defineProperties() is less dangerous than renaming. Loading is name-based and uses PropertyBindings.topoSort() so sources are applied before dependent properties.

Clone this wiki locally