GraphMarkSpec.fromJson constructor

GraphMarkSpec.fromJson(
  1. Json j, {
  2. Color? colorOf(
    1. String field
    )?,
  3. List<Color> palette = const [],
})

colorOf gives the color of a mark that writes none (by the mark's field, so an area and the line along its top share one), and palette an arc's colors row by row when it writes none.

Implementation

factory GraphMarkSpec.fromJson(Json j, {Color? Function(String field)? colorOf, List<Color> palette = const []}) {
  final type = _s(j['type'], 'line');
  final written = j['color'] != null;
  final own = written || type == 'candle' || type == 'arc' ? null : colorOf?.call(_s(j['y'], ''));
  return GraphMarkSpec(
      type: type,
      y: _s(j['y'], ''),
      open: _s(j['open'], ''),
      high: _s(j['high'], ''),
      low: _s(j['low'], ''),
      close: _s(j['close'], ''),
      color: graphColor(j['color'], own ?? const Color(0xFF2962FF)),
      colored: written,
      dots: _d(j['dots'], 0),
      center: _s(j['center'], ''),
      centerLabel: _s(j['centerLabel'], ''),
      upColor: graphColor(j['upColor'], const Color(0xFF26A69A)),
      downColor: graphColor(j['downColor'], const Color(0xFFEF5350)),
      width: _d(j['width'], 1.5),
      fillOpacity: _d(j['fillOpacity'], 0.18),
      fade: _b(j['fade'], false),
      curved: _b(j['curved'], false),
      overlay: _dn(j['overlay']),
      segmentBy: _s(j['segmentBy'], ''),
      dimInactive: _d(j['dimInactive'], 1),
      endDot: _d(j['endDot'], 0),
      endDotColor: j['endDotColor'] == null ? null : graphColor(j['endDotColor'], const Color(0xFF2962FF)),
      pulse: _b(j['pulse'], false),
      name: _s(j['name'], ''),
      stack: j['stack'] is String ? j['stack']! as String : null,
      radius: _d(j['radius'], 0),
      colorField: _s(j['colorField'], ''),
      colors: type == 'arc' && _l(j['colors']).isEmpty && !written
          ? palette
          : [for (final c in _l(j['colors'])) graphColor(c, const Color(0xFF2962FF))],
      inner: _d(j['inner'], 0),
      gap: _d(j['gap'], 0),
      startAngle: _d(j['startAngle'], 0),
      labels: _b(j['labels'], false),
      fillTo: j['fillTo'] == null ? null : graphColor(j['fillTo'], const Color(0x00000000)),
    );
}