Repository navigation
EN SpeedometerIndicator JSON
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.
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.
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 state is produced with hasTemplate=false.
Runtime behavior:
-
Unit.toJSON(false)writessizeandpositionInParent; -
IndicatorLayer.toJSON(false)adds thepropertiesobject; - each SDK property writes its own payload through
Property.toJSON(); -
DistanceSensorPropertypersists concretesourceIdandsensorId.
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 is produced with hasTemplate=true.
Runtime behavior:
- if the layer has a parent,
Unit.toJSON(true)writesmaketinstead ofsizeandpositionInParent; - if the layer already has a selected
LayerMaket, its preset is saved; - if no
LayerMaketis selected, runtime captures a proportional layout; -
IndicatorLayer.toJSON(true)still savesproperties; - when loading a template,
IndicatorLayer.fromJSON(..., true)first applies automatic source selection for allSensorPropertyinstances; - then
propertiesare 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"
}
}
}
}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:
-
Distancein a template should not be treated as a hard binding: when the template is inserted, runtime first tries to select a suitable sensor automatically. -
speedScaleis saved asEnumArrayPropertystate; its user meaning is the selected enum item, not the numeric scale value by itself. -
fontis composite: font data and text color are saved together. -
textTemplateuses variable names. The speedometer has onlycurr. - Colors are written through
r,g,b,achannels.
{
"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
}
}
}{
"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.
JSON stability depends on stable identifiers:
-
Plagin.UIDmust stay stable: saved projects reference the plugin. -
SpeedometerIndicator.NAMEandgetName()must remainspeedometer: saved indicator layers reference this name. -
Property.getName()for each property must stay stable: these are keys insideproperties. - 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 usesPropertyBindings.topoSort()so sources are applied before dependent properties.