Построение диаграмм с накоплением в Vega - PullRequest
0 голосов
/ 05 апреля 2019

У меня проблемы с отображением этих данных в диаграмме с накоплением. Есть дополнительные вычисления, которые я должен сделать на агрегированном поле Duration. Сначала мне нужно сгруппировать Task.ID по оси x, а затем поместить Duration по оси Y. Разделяется Current.BotState.

Расчет, который мне нужен для построения графика: TotalDuration-TargetTime (TBD) -TotalBlockedTime / TargetTime by TaskID

  "$schema": "https://vega.github.io/schema/vega/v3.3.1.json",
  "padding": 5,

  "data": [
    {
      "name": "table",
      "values": [
        {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "7FKj6GkBcbTp5jzWhwT-",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "8195"
          },
          "Duration" : 11.954,
          "Current" : {
            "BotState" : "Working"
          }
        }
      },
      {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "9FKj6GkBcbTp5jzWhwT-",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "8195"
          },
          "Duration" : 11.703,
          "Current" : {
            "BotState" : "Blocked"
          }
        }
      },
      {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "-FKj6GkBcbTp5jzWhwT-",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "0"
          },
          "Duration" : 7.469,
          "Current" : {
            "BotState" : "Unscheduled"
          }
        }
      },
      {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "CVKj6GkBcbTp5jzWohqo",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "1673"
          },
          "Duration" : 4.172,
          "Current" : {
            "BotState" : "Blocked"
          }
        }
      },
      {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "ClKj6GkBcbTp5jzWohqo",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "1673"
          },
          "Duration" : 0.516,
          "Current" : {
            "BotState" : "Starved"
          }
        }
      },
      {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "D1Kj6GkBcbTp5jzWohqo",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "2551"
          },
          "Duration" : 28.846,
          "Current" : {
            "BotState" : "Working"
          }
        }
      },
      {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "GVKj6GkBcbTp5jzWohqo",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "2287"
          },
          "Duration" : 10.772,
          "Current" : {
            "BotState" : "Working"
          }
        }
      },
      {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "0lKj6GkBcbTp5jzWmhN6",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "8721"
          },
          "Duration" : 11.689,
          "Current" : {
            "BotState" : "Working"
          }
        }
      },
      {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "1VKj6GkBcbTp5jzWmhN6",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "8721"
          },
          "Duration" : 1.11,
          "Current" : {
            "BotState" : "Blocked"
          }
        }
      },
      {
        "_index" : "index-002a5",
        "_type" : "doc",
        "_id" : "H1Kj6GkBcbTp5jzWriXC",
        "_score" : 8.259495,
        "_source" : {
          "Task" : {
            "Id" : "8584"
          },
          "Duration" : 9.801,
          "Current" : {
            "BotState" : "Working"
            }
        }
      }
      ],
      "transform": [
        {
          "type": "stack",
          "groupby": ["_source.Task.Id"],
          "sort": {"field": "_source.Current.BotState"},
          "field": "_source.Duration"
        }
      ]
    }
  ],

  "scales": [
    {
      "name": "x",
      "type": "band",
      "range": "width",
      "domain": {"data": "table", "field": "_source.Task.Id"}
    },
    {
      "name": "y",
      "type": "linear",
      "range": "height",
      "nice": true, "zero": true,
      "domain": {"data": "table", "field": "_source.Duration"}
    },
    {
      "name": "color",
      "type": "ordinal",
      "range": "category",
      "domain": {"data": "table", "field": "_source.Current.BotState"}
    }
  ],

  "axes": [
    {"orient": "bottom", "scale": "x", "zindex": 1},
    {"orient": "left", "scale": "y", "zindex": 1}
  ],

  "marks": [
    {
      "type": "rect",
      "from": {"data": "table"},
      "encode": {
        "enter": {
          "x": {"scale": "x", "field": "_source.Task.Id"},
          "width": {"scale": "x", "band": 1, "offset": -1},
          "y": {"scale": "y", "field": "_source.Duration0"},
          "y2": {"scale": "y", "field": "_source.Duration1"},
          "fill": {"scale": "color", "field": "_source.Current.BotState"}
        },
        "update": {
          "fillOpacity": {"value": 1}
        },
        "hover": {
          "fillOpacity": {"value": 0.5}
        }
      }
    }
  ]
}
...