private def readGraphDef()

in atlas-chart/src/main/scala/com/netflix/atlas/chart/JsonCodec.scala [360:405]


  private def readGraphDef(parser: JsonParser): GraphDef = {
    var gdef: GraphDef = null
    val plots = Map.newBuilder[Int, PlotDef]
    val heatmaps = Map.newBuilder[Int, HeatmapDef]
    val data = List.newBuilder[(Int, DataDef)]
    foreachItem(parser) {
      val node = mapper.readTree[JsonNode](parser)
      node.get("type").asText() match {
        case "graph-image" =>
        // ignored for right now
        case "graph-metadata" =>
          if (gdef != null)
            throw new IllegalStateException("multiple graph-metadata blocks")
          gdef = toGraphDef(node)
        case "plot-metadata" =>
          plots += node.get("id").asInt(0) -> toPlotDef(node)
        case "heatmap" =>
          val plot = node.get("plot").asInt(0)
          heatmaps += plot -> toHeatmapDef(node)
        case "timeseries" =>
          val plot = node.get("plot").asInt(0)
          data += plot -> toLineDef(gdef, node)
        case "hspan" =>
          val plot = node.get("plot").asInt(0)
          data += plot -> toHSpanDef(node)
        case "vspan" =>
          val plot = node.get("plot").asInt(0)
          data += plot -> toVSpanDef(node)
        case "message" =>
          val plot = node.get("plot").asInt(0)
          data += plot -> toMessageDef(node)
      }
    }

    val heatmapData = heatmaps.result()
    val groupedData = data.result().groupBy(_._1)

    val sortedPlots = plots.result().toList.sortWith(_._1 < _._1)
    val plotList = sortedPlots.map {
      case (id, plot) =>
        val plotLines = groupedData.get(id).map(_.map(_._2)).getOrElse(Nil)
        plot.copy(data = plotLines, heatmap = heatmapData.get(id))
    }

    gdef.copy(plots = plotList)
  }