decodeBarRendererDecorator<T> static method

BarRendererDecorator<T>? decodeBarRendererDecorator<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:

{
  "insideLabelStyleSpec": <TextStyleSpec>,
  "labelAnchor": <BarLabelAnchor>,
  "labelPlacement": <BarLabelPlacement>,
  "labelPosition": <BarLabelPosition>,
  "labelVerticalPosition": <BarLabelVerticalPosition>,
  "outsideLabelStyleSpec": <TextStyleSpec>
}

See also

Implementation

static common.BarRendererDecorator<T>? decodeBarRendererDecorator<T>(
  dynamic map, {
  bool validate = true,
}) {
  common.BarRendererDecorator<T>? result;

  if (map is common.BarRendererDecorator<T>) {
    result = map;
  } else if (map != null) {
    assert(SchemaValidator.validate(
      schemaId: '$_baseSchemaUrl/bar_renderer_decorator',
      value: map,
      validate: validate,
    ));
    final type = map['type'];

    switch (type) {
      case 'label':
        result = charts.BarLabelDecorator<T>(
          insideLabelStyleSpec: decodeTextStyleSpec(
                map['insideLabelStyleSpec'],
                validate: false,
              ) ??
              const common.TextStyleSpec(
                  fontSize: 12, color: common.Color.white),
          labelAnchor: decodeBarLabelAnchor(
            map['labelAnchor'],
            validate: false,
          ),
          labelPadding: JsonClass.parseInt(map['labelPadding']) ?? 5,
          labelPlacement: decodeBarLabelPlacement(
                map['labelPlacement'],
                validate: false,
              ) ??
              common.BarLabelPlacement.followMeasureAxis,
          labelPosition: decodeBarLabelPosition(
                map['labelPosition'],
                validate: false,
              ) ??
              common.BarLabelPosition.auto,
          labelVerticalPosition: decodeBarLabelVerticalPosition(
                map['labelVerticalPosition'],
                validate: false,
              ) ??
              common.BarLabelVerticalPosition.middle,
          outsideLabelStyleSpec: decodeTextStyleSpec(
                map['outsideLabelStyleSpec'],
                validate: false,
              ) ??
              const common.TextStyleSpec(
                  fontSize: 12, color: common.Color.black),
        );
        break;

      default:
        throw Exception(
          '[decodeBarRendererDecorator]: unknown type: [$type]',
        );
    }
  }

  return result;
}