我正在尝试创建一个简单的事件状态树。在这棵树中,我分为2个级别:操作,主要操作和事件状态。我想统计每个节点级别的事件总数,并将其分类为“ New-10”,“ In Progress -5”,“ closed-7”等。这将显示为“ Operation-22”(New-10,In Progress) -5,关闭-7)。我能够获得每个级别的总数。但是现在我面临的问题是对它们进行分类。有人可以帮助我确定应该采取哪些措施以获得正确的计数吗?我将在此处附上代码片段和示例数据。
{
"$schema": "https://vega.github.io/schema/vega/v3.0.json",
"title": {
"text": "Note - Please mouseover the node to get the complete text"
},
"signals": [
{"name": "labels", "value": true, "bind": {"input": "checkbox"}},
{
"name": "aspectRatio",
"value": 1.6,
"bind": {"input": "range", "min": 0.2, "max": 5, "step": 0.1}
},
{
"name": "layout",
"value": "tidy",
"bind": {"input": "radio", "options": ["tidy", "cluster"]}
},
{
"name": "links",
"value": "diagonal",
"bind": {
"input": "select",
"options": ["line", "curve", "diagonal", "orthogonal"]
}
},
{
"name": "limit",
"value": 75,
"bind": {"input": "range", "min": 0, "max": 150, "step": 1}
}
],
"data": [
{
"name": "query",
"values": {
"took": 781,
"timed_out": false,
"_shards": {"total": 5, "successful": 5, "skipped": 0, "failed": 0},
"hits": {"total": 414696, "max_score": 0, "hits": []},
"aggregations": {
"business": {
"after_key": {
"busn_competency_name": "Operation",
"busn_component_name": "MAIN Operation",
"busn_srvc_name": "MAIN Operation",
"srvc_prc_name": "MAIN Operation",
"incident_status": "Closed",
"incident_id": "INC0870280"
},
"buckets": [
{
"key": {
"busn_competency_name": "Operation",
"busn_component_name": "MAIN Operation",
"busn_srvc_name": "MAIN Operation",
"srvc_prc_name": "MAIN Operation",
"incident_status": "Closed",
"incident_id": "INC0855912"
},
"doc_count": 1,
"new": {"doc_count": 0},
"onhold": {"doc_count": 0},
"progress": {"doc_count": 0},
"closed": {"doc_count": 1}
},
{
"key": {
"busn_competency_name": "Operation",
"busn_component_name": "MAIN Operation",
"busn_srvc_name": "MAIN Operation",
"srvc_prc_name": "MAIN Operation",
"incident_status": "Closed",
"incident_id": "INC0856149"
},
"doc_count": 1,
"new": {"doc_count": 0},
"onhold": {"doc_count": 0},
"progress": {"doc_count": 0},
"closed": {"doc_count": 1}
},
{
"key": {
"busn_competency_name": "Operation",
"busn_component_name": "MAIN Operation",
"busn_srvc_name": "MAIN Operation",
"srvc_prc_name": "MAIN Operation",
"incident_status": "Closed",
"incident_id": "INC0856543"
},
"doc_count": 1,
"new": {"doc_count": 0},
"onhold": {"doc_count": 0},
"progress": {"doc_count": 0},
"closed": {"doc_count": 1}
},
{
"key": {
"busn_competency_name": "Operation",
"busn_component_name": "MAIN Operation",
"busn_srvc_name": "MAIN Operation",
"srvc_prc_name": "MAIN Operation",
"incident_status": "In Progress",
"incident_id": "INC0856570"
},
"doc_count": 1,
"new": {"doc_count": 0},
"onhold": {"doc_count": 0},
"progress": {"doc_count": 1},
"closed": {"doc_count": 0}
},
{
"key": {
"busn_competency_name": "Operation",
"busn_component_name": "MAIN Operation",
"busn_srvc_name": "MAIN Operation",
"srvc_prc_name": "MAIN Operation",
"incident_status": "New",
"incident_id": "INC0856618"
},
"doc_count": 1,
"new": {"doc_count": 1},
"onhold": {"doc_count": 0},
"progress": {"doc_count": 0},
"closed": {"doc_count": 0}
},
{
"key": {
"busn_competency_name": "Operation",
"busn_component_name": "MAIN Operation",
"busn_srvc_name": "MAIN Operation",
"srvc_prc_name": "MAIN Operation",
"incident_status": "New",
"incident_id": "INC0856644"
},
"doc_count": 1,
"new": {"doc_count": 1},
"onhold": {"doc_count": 0},
"progress": {"doc_count": 0},
"closed": {"doc_count": 0}
},
{
"key": {
"busn_competency_name": "Operation",
"busn_component_name": "MAIN Operation",
"busn_srvc_name": "MAIN Operation",
"srvc_prc_name": "MAIN Operation",
"incident_status": "Closed",
"incident_id": "INC0858028"
},
"doc_count": 1,
"new": {"doc_count": 0},
"onhold": {"doc_count": 0},
"progress": {"doc_count": 0},
"closed": {"doc_count": 1}
},
{
"key": {
"busn_competency_name": "Operation",
"busn_component_name": "MAIN Operation",
"busn_srvc_name": "MAIN Operation",
"srvc_prc_name": "MAIN Operation",
"incident_status": "Closed",
"incident_id": "INC0869880"
},
"doc_count": 1,
"new": {"doc_count": 0},
"onhold": {"doc_count": 0},
"progress": {"doc_count": 0},
"closed": {"doc_count": 1}
},
{
"key": {
"busn_competency_name": "Operation",
"busn_component_name": "MAIN Operation",
"busn_srvc_name": "MAIN Operation",
"srvc_prc_name": "MAIN Operation",
"incident_status": "Closed",
"incident_id": "INC0870094"
},
"doc_count": 1,
"new": {"doc_count": 0},
"onhold": {"doc_count": 0},
"progress": {"doc_count": 0},
"closed": {"doc_count": 1}
},
{
"key": {
"busn_competency_name": "Operation",
"busn_component_name": "MAIN Operation",
"busn_srvc_name": "MAIN Operation",
"srvc_prc_name": "MAIN Operation",
"incident_status": "Closed",
"incident_id": "INC0870280"
},
"doc_count": 1,
"new": {"doc_count": 0},
"onhold": {"doc_count": 0},
"progress": {"doc_count": 0},
"closed": {"doc_count": 1}
}
]
}
}
},
"format": {"type": "json", "property": "aggregations.business.buckets"},
"transform": [
{
"type": "joinaggregate",
"ops": ["count"],
"fields": ["incident_id.doc_count"],
"as": ["busn_competency_sum"],
"groupby": ["key.busn_competency_name"]
},
{
"type": "joinaggregate",
"ops": ["count"],
"fields": ["incident_id.doc_count"],
"as": ["busn_component_sum"],
"groupby": ["key.busn_component_name"]
},
{
"type": "joinaggregate",
"ops": ["count"],
"fields": ["incident_id.doc_count"],
"as": ["busn_srvc_sum"],
"groupby": ["key.busn_srvc_name"]
},
{
"type": "joinaggregate",
"ops": ["count"],
"fields": ["incident_id.doc_count"],
"as": ["srvc_prc_sum"],
"groupby": ["key.srvc_prc_name"]
},
{
"type": "joinaggregate",
"ops": ["count"],
"fields": ["incident_id.doc_count"],
"as": ["incident_status_sum"],
"groupby": ["key.incident_status"]
},
{
"type": "joinaggregate",
"ops": ["count"],
"fields": ["new.doc_count"],
"as": ["new_sum"],
"groupby": ["key.incident_status"]
},
{
"type": "joinaggregate",
"ops": ["sum"],
"fields": ["onhold.doc_count"],
"as": ["onhold_sum"],
"groupby": ["key.incident_status"]
},
{
"type": "joinaggregate",
"ops": ["sum"],
"fields": ["progress.doc_count"],
"as": ["progress_sum"],
"groupby": ["key.incident_status"]
},
{
"type": "joinaggregate",
"ops": ["sum"],
"fields": ["closed.doc_count"],
"as": ["closed_sum"],
"groupby": ["key.incident_status"]
},
{
"type": "formula",
"as": "competency",
"expr": "datum.key.busn_competency_name +' -- '+datum.busn_competency_sum + ' ( New - ' + datum.new_sum + ', In Progress -' + datum.progress_sum + ', Closed - ' +datum.closed_sum+ ', Onhold - ' +datum.onhold_sum+ ' )'"
},
{
"type": "formula",
"as": "component",
"expr": "datum.key.busn_component_name +' -- '+ datum.busn_component_sum + ' ( New - ' +datum.new_sum+ ', In Progress -' + datum.progress_sum + ', Closed - ' +datum.closed_sum+ ', Onhold - ' +datum.onhold_sum+ ' )'"
},
{
"type": "formula",
"as": "srvc",
"expr": "datum.key.busn_srvc_name +' -- '+datum.busn_srvc_sum + ' ( New - ' +datum.new_sum+ ', In Progress -' + datum.progress_sum + ', Closed - ' +datum.closed_sum+ ', Onhold - ' +datum.onhold_sum+ ' )'"
},
{
"type": "formula",
"as": "prc",
"expr": "datum.key.srvc_prc_name +' -- '+ datum.srvc_prc_sum + ' ( New - ' +datum.new_sum+ ', In Progress -' + datum.progress_sum + ', Closed - ' +datum.closed_sum+ ', Onhold - ' +datum.onhold_sum+ ' )'"
},
{
"type": "formula",
"as": "status",
"expr": "datum.key.incident_status +' -- '+ datum.incident_status_sum"
}
]
},
{
"name": "tree",
"source": "query",
"transform": [
{
"type": "nest",
"keys": ["competency", "component", "srvc", "prc", "status"],
"generate": true
},
{"type": "filter", "expr": "!datum.doc_count"},
{
"type": "tree",
"method": {"signal": "layout"},
"size": [{"signal": "height - 100"}, {"signal": "width - 100"}],
"as": ["y", "x", "depth", "children"]
}
]
},
{
"name": "links",
"source": "tree",
"transform": [
{"type": "treelinks"},
{
"type": "linkpath",
"orient": "horizontal",
"shape": {"signal": "links"}
}
]
}
],
"scales": [
{
"name": "color",
"type": "sequential",
"range": {"scheme": "yelloworangebrown"},
"domain": {"data": "tree", "field": "depth"},
"zero": true
}
],
"marks": [
{
"type": "path",
"from": {"data": "links"},
"encode": {
"update": {"path": {"field": "path"}, "stroke": {"value": "#105bdd"}}
}
},
{
"type": "symbol",
"from": {"data": "tree"},
"encode": {
"enter": {"size": {"value": 200}, "stroke": {"value": "black"}},
"update": {
"x": {"field": "x"},
"y": {"field": "y"},
"fill": {"scale": "color", "field": "depth"}
}
}
},
{
"type": "text",
"from": {"data": "tree"},
"encode": {
"enter": {
"text": {"field": "key"},
"fontSize": {"value": 12},
"baseline": {"value": "top"},
"fill": {"value": "#C0C0C0"}
},
"update": {
"x": {"field": "x"},
"y": {"field": "y"},
"dx": {"signal": "datum.children ? -7 : 7"},
"align": {"signal": "datum.children ? 'right' : 'left'"},
"opacity": {"signal": "labels ? 1 : 0"},
"limit": {"signal": "limit"},
"tooltip": {"signal": "datum.key"}
}
}
}
]
}