decodeRangeAnnotation<T> static method

RangeAnnotation<T>? decodeRangeAnnotation<T>(
  1. dynamic map, {
  2. bool validate = true,
})

Decodes the object from a Map-like dynamic structure. This expects the JSON format to be of the following structure:

{
  "annotations": <List<AnnotationSegment>>,
  "defaultColor": <Color>,
  "defaultLabelAnchor": <AnnotationLabelAnchor>,
  "defaultLabelDirection": <AnnotationLabelDirection>,
  "defaultLabelPosition": <AnnotationLabelPosition>,
  "defaultLabelStyleSpec": <TextStyleSpec>,
  "extendAxis": <bool>,
  "labelPadding": <int>,
  "layoutPaintOrder": <int>
}

See also

Implementation

static charts.RangeAnnotation<T>? decodeRangeAnnotation<T>(
  dynamic map, {
  bool validate = true,
}) {
  charts.RangeAnnotation<T>? result;

  if (map is charts.RangeAnnotation<T>) {
    result = map;
  } else if (map != null) {
    assert(SchemaValidator.validate(
      schemaId: '$_baseSchemaUrl/range_annotation',
      value: map,
      validate: validate,
    ));

    result = charts.RangeAnnotation<T>(
      (map['annotations'] as List)
          .map(
            (e) => decodeAnnotationSegment<T>(
              e,
              validate: false,
            )!,
          )
          .toList(),
      defaultColor: decodeColor(
        map['defaultColor'],
        validate: false,
      ),
      defaultLabelAnchor: decodeAnnotationLabelAnchor(
        map['defaultLabelAnchor'],
        validate: false,
      ),
      defaultLabelDirection: decodeAnnotationLabelDirection(
        map['defaultLabelDirection'],
        validate: false,
      ),
      defaultLabelPosition: decodeAnnotationLabelPosition(
        map['defaultLabelPosition'],
        validate: false,
      ),
      defaultLabelStyleSpec: decodeTextStyleSpec(
        map['defaultLabelStyleSpec'],
        validate: false,
      ),
      extendAxis: map['extendAxis'] == null
          ? null
          : JsonClass.parseBool(
              map['extendAxis'],
            ),
      labelPadding: JsonClass.parseInt(map['labelPadding']),
      layoutPaintOrder: JsonClass.parseInt(map['layoutPaintOrder']),
    );
  }

  return result;
}