GraphSpec.fromJson constructor

GraphSpec.fromJson(
  1. Json j
)

Implementation

factory GraphSpec.fromJson(Json j) {
  final style = GraphStyleSpec.fromJson(_m(j['style']));
  // A mark that writes no color takes the palette's next: the first
  // such field the first color, and every mark of that field the same.
  final byField = <String, Color>{};
  Color? colorOf(String field) =>
      style.palette.isEmpty ? null : byField[field] ??= style.palette[byField.length % style.palette.length];
  return GraphSpec(
    key: _s(j['key'], 't'),
    x: GraphXSpec.fromJson(_m(j['x'])),
    panes: [for (final p in _l(j['panes'])) GraphPaneSpec.fromJson(_m(p), colorOf: colorOf, palette: style.palette)],
    transforms: [for (final t in _l(j['transforms'])) GraphTransformSpec.fromJson(_m(t))],
    crosshair: GraphCrosshairSpec.fromJson(_m(j['crosshair'])),
    interactions: GraphInteractionsSpec.fromJson(_m(j['interactions'])),
    style: style,
    selection: GraphSelectionSpec.fromJson(_m(j['selection'])),
    animate: _d(j['animate'], 0),
    animateIn: _b(j['animateIn'], false),
    legend: GraphLegendSpec.fromJson(j['legend']),
  );
}