decodeRenderSpec<D> static method
Decodes the object from a Map-like dynamic structure. This expects the JSON format to be one of the following structures:
{
"axisLineStyle": <LineStyleSpec>,
"type": "none"
}
{
"axisLineStyle": <LineStyleSpec>,
"labelAnchor": <TickLabelAnchor>,
"labelCollisionOffsetFromAxisPx": <int>,
"labelCollisionOffsetFromTickPx": <int>,
"labelCollisionRotation": <int>,
"labelJustification": <TickLabelJustification>,
"labelOffsetFromAxisPx": <int>,
"labelOffsetFromTickPx": <int>,
"labelRotation": <int>,
"labelStyle": <TextStyleSpec>,
"lineStyle": <LineStyleSpec>,
"minimumPaddingBetweenLabelsPx": <int>,
"tickLengthPx": <int>,
"type": <"grid_line" | "small_tick">
}
See also
Implementation
static charts.RenderSpec<D>? decodeRenderSpec<D>(
dynamic map, {
bool validate = false,
}) {
charts.RenderSpec<D>? result;
if (map is charts.RenderSpec<D>) {
result = map;
} else if (map != null) {
assert(SchemaValidator.validate(
schemaId: '$_baseSchemaUrl/render_spec',
value: map,
validate: validate,
));
final type = map['type'];
switch (type) {
case 'gridline':
result = charts.GridlineRendererSpec<D>(
axisLineStyle: decodeLineStyleSpec(
map['axisLineStyle'],
validate: false,
),
labelAnchor: decodeTickLabelAnchor(
map['labelAnchor'],
validate: false,
),
labelCollisionOffsetFromAxisPx: JsonClass.parseInt(
map['labelCollisionOffsetFromAxisPx'],
),
labelCollisionOffsetFromTickPx: JsonClass.parseInt(
map['labelCollisionOffsetFromTickPx'],
),
labelCollisionRotation: JsonClass.parseInt(
map['labelCollisionRotation'],
),
labelJustification: decodeTickLabelJustification(
map['labelJustification'],
validate: false,
),
labelOffsetFromAxisPx: JsonClass.parseInt(
map['labelOffsetFromAxisPx'],
),
labelOffsetFromTickPx: JsonClass.parseInt(
map['labelOffsetFromTickPx'],
),
labelRotation: JsonClass.parseInt(map['labelRotation']),
labelStyle: decodeTextStyleSpec(
map['labelStyle'],
validate: false,
),
lineStyle: decodeLineStyleSpec(
map['lineStyle'],
validate: false,
),
minimumPaddingBetweenLabelsPx: JsonClass.parseInt(
map['minimumPaddingBetweenLabelsPx'],
),
tickLengthPx: JsonClass.parseInt(map['tickLengthPx']),
);
break;
case 'none':
result = charts.NoneRenderSpec<D>(
axisLineStyle: decodeLineStyleSpec(
map['axisLineStyle'],
validate: false,
),
);
break;
case 'small_tick':
result = charts.SmallTickRendererSpec<D>(
axisLineStyle: decodeLineStyleSpec(
map['axisLineStyle'],
validate: false,
),
labelAnchor: decodeTickLabelAnchor(
map['labelAnchor'],
validate: false,
),
labelCollisionOffsetFromAxisPx: JsonClass.parseInt(
map['labelCollisionOffsetFromAxisPx'],
),
labelCollisionOffsetFromTickPx: JsonClass.parseInt(
map['labelCollisionOffsetFromTickPx'],
),
labelCollisionRotation: JsonClass.parseInt(
map['labelCollisionRotation'],
),
labelJustification: decodeTickLabelJustification(
map['labelJustification'],
validate: false,
),
labelOffsetFromAxisPx: JsonClass.parseInt(
map['labelOffsetFromAxisPx'],
),
labelOffsetFromTickPx: JsonClass.parseInt(
map['labelOffsetFromTickPx'],
),
labelRotation: JsonClass.parseInt(map['labelRotation']),
labelStyle: decodeTextStyleSpec(
map['labelStyle'],
validate: false,
),
lineStyle: decodeLineStyleSpec(
map['lineStyle'],
validate: false,
),
minimumPaddingBetweenLabelsPx: JsonClass.parseInt(
map['minimumPaddingBetweenLabelsPx'],
),
tickLengthPx: JsonClass.parseInt(map['tickLengthPx']),
);
break;
default:
throw Exception('[decodeRenderSpec]: unknown type: [$type]');
}
}
return result;
}