Guest User

Untitled

a guest
Oct 9th, 2019
1,517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 9.89 KB | None | 0 0
  1. {
  2.   "$schema": "https://vega.github.io/schema/vega/v3.0.json",
  3.   "data": [
  4.     {
  5.       "name": "rawData",
  6.       "url": {
  7.         "%context%": true,
  8.         "%timefield%": "@timestamp",
  9.         "index": "logstash-*",
  10.         "body": {
  11.           "size": 0,
  12.           "aggs": {
  13.             "table": {
  14.               "composite": {
  15.                 "size": 10000,
  16.                 "sources": [
  17.                   {"stk1": {"terms": {"field": "field1"}}},
  18.                   {"stk2": {"terms": {"field": "field2"}}},
  19.                   {"stk3": {"terms": {"field": "field3"}}}
  20.                 ]
  21.               }
  22.             }
  23.           }
  24.         }
  25.       },
  26.       "format": {"property": "aggregations.table.buckets"},
  27.       "transform": [
  28.         {"type": "formula", "expr": "datum.key.stk1", "as": "stk1"},
  29.         {"type": "formula", "expr": "datum.key.stk2", "as": "stk2"},
  30.         {"type": "formula", "expr": "datum.key.stk3", "as": "stk3"},
  31.         {"type": "formula", "expr": "datum.doc_count", "as": "size"}
  32.       ]
  33.     },
  34.     {
  35.       "name": "nodes",
  36.       "source": "rawData",
  37.       "transform": [
  38.         {"type": "filter", "expr": "!groupSelector || groupSelector.stk1 == datum.stk1 || groupSelector.stk2 == datum.stk2 || groupSelector.stk3 == datum.stk3"},
  39.         {"type": "formula", "expr": "datum.stk1+datum.stk2+datum.stk3", "as": "key"},
  40.         {"type": "fold", "fields": ["stk1", "stk2", "stk3"], "as": ["stack", "grpId"]},
  41.         {"type": "formula", "expr": "datum.stack == 'stk1' ? datum.stk1+datum.stk2+datum.stk3 : datum.stk3+datum.stk2+datum.stk1", "as": "sortField"},
  42.         {"type": "stack", "groupby": ["stack"], "sort": {"field": "sortField", "order": "descending"}, "field": "size"},
  43.         {"type": "formula", "expr": "(datum.y0+datum.y1)/2", "as": "yc"}
  44.       ]
  45.     },
  46.     {
  47.       "name": "groups",
  48.       "source": "nodes",
  49.       "transform": [
  50.         {"type": "aggregate", "groupby": ["stack", "grpId"], "fields": ["size"], "ops": ["sum"], "as": ["total"]},
  51.         {"type": "stack", "groupby": ["stack"], "sort": {"field": "grpId", "order": "descending"}, "field": "total"},
  52.         {"type": "formula", "expr": "scale('y', datum.y0)", "as": "scaledY0"},
  53.         {"type": "formula", "expr": "scale('y', datum.y1)", "as": "scaledY1"},
  54.         {"type": "formula", "expr": "scale('y', datum.y2)", "as": "scaledY2"},
  55.         {"type": "formula", "expr": "datum.stack == 'stk1'", "as": "rightLabel"},
  56.         {"type": "formula", "expr": "datum.total/domain('y')[1]", "as": "percentage"}
  57.       ]
  58.     },
  59.     {"name": "midNodes", "source": "nodes", "transform": [{"type": "filter", "expr": "datum.stack == 'stk2'"}]},
  60.     {"name": "rightNodes", "source": "nodes", "transform": [{"type": "filter", "expr": "datum.stack == 'stk3'"}]},
  61.     {
  62.       "name": "leftnode",
  63.       "source": "nodes",
  64.       "transform": [
  65.         {"type": "filter", "expr": "datum.stack == 'stk1'"},
  66.         {"type": "lookup", "from": "midNodes", "key": "key", "fields": ["key"], "as": ["target"]},
  67.         {
  68.           "type": "linkpath",
  69.           "orient": "horizontal",
  70.           "shape": "diagonal",
  71.           "sourceY": {"expr": "scale('y', datum.yc)"},
  72.           "sourceX": {"expr": "scale('x', 'stk1') + bandwidth('x')"},
  73.           "targetY": {"expr": "scale('y', datum.target.yc)"},
  74.           "targetX": {"expr": "scale('x', 'stk2')"}
  75.         },
  76.         {"type": "formula", "expr": "range('y')[0]-scale('y', datum.size)", "as": "strokeWidth"},
  77.         {"type": "formula", "expr": "datum.size/domain('y')[1]", "as": "percentage"}
  78.       ]
  79.     }
  80.     {
  81.       "name": "midnode",
  82.       "source": "nodes",
  83.       "transform": [
  84.         {"type": "filter", "expr": "datum.stack == 'stk2'"},
  85.         {"type": "lookup", "from": "rightNodes", "key": "key", "fields": ["key"], "as": ["target"]},
  86.         {
  87.           "type": "linkpath",
  88.           "orient": "horizontal",
  89.           "shape": "diagonal",
  90.           "sourceY": {"expr": "scale('y', datum.yc)"},
  91.           "sourceX": {"expr": "scale('x', 'stk2') + bandwidth('x')"},
  92.           "targetY": {"expr": "scale('y', datum.target.yc)"},
  93.           "targetX": {"expr": "scale('x', 'stk3')"}
  94.         },
  95.         {"type": "formula", "expr": "range('y')[0]-scale('y', datum.size)", "as": "strokeWidth"},
  96.         {"type": "formula", "expr": "datum.size/domain('y')[1]", "as": "percentage"}
  97.       ]
  98.     }
  99.   ],
  100.   "scales": [
  101.     {"name": "x", "type": "band", "range": "width", "domain": ["stk1", "stk2", "stk3"], "paddingOuter": 0.01, "paddingInner": 0.98},
  102.     {"name": "y", "type": "linear", "range": "height", "domain": {"data": "nodes", "field": "y1"}},
  103.     {"name": "color", "type": "ordinal", "range": "category", "domain": {"data": "rawData", "fields": ["stk1", "stk2", "stk3"]}},
  104.     {"name": "stackNames", "type": "ordinal", "range": ["IP", "Host Request", "Cache Status"], "domain": ["stk1", "stk2", "stk3"]}
  105.   ],
  106.   "marks": [
  107.     {
  108.       "type": "path",
  109.       "name": "leftMark",
  110.       "from": {"data": "leftnode"},
  111.       "clip": true,
  112.       "encode": {
  113.         "update": {
  114.           "stroke": [{"test": "groupSelector && groupSelector.stack=='stk1'", "scale": "color", "field": "stk2"}, {"scale": "color", "field": "stk1"}],
  115.           "strokeWidth": {"field": "strokeWidth"},
  116.           "path": {"field": "path"},
  117.           "strokeOpacity": {"signal": "!groupSelector && (groupHover.stk1 == datum.stk1 || groupHover.stk2 == datum.stk2) ? 0.75 : 0.3"},
  118.           "zindex": {"signal": "!groupSelector && (groupHover.stk1 == datum.stk1 || groupHover.stk2 == datum.stk2) ? 1 : 0"},
  119.           "tooltip": {"signal": "datum.stk1 + ' → ' + datum.stk2 + '    ' + format(datum.size, ',.0f') + '   (' + format(datum.percentage, '.1%') + ')'"}
  120.         },
  121.         "hover": {"strokeOpacity": {"value": 0.75}}
  122.       }
  123.     },
  124.     {
  125.       "type": "path",
  126.       "name": "rightMark",
  127.       "from": {"data": "midnode"},
  128.       "clip": true,
  129.       "encode": {
  130.         "update": {
  131.           "stroke": [{"test": "groupSelector && groupSelector.stack=='stk1'", "scale": "color", "field": "stk2"}, {"scale": "color", "field": "stk1"}],
  132.           "strokeWidth": {"field": "strokeWidth"},
  133.           "path": {"field": "path"},
  134.           "strokeOpacity": {"signal": "!groupSelector && (groupHover.stk1 == datum.stk1 || groupHover.stk2 == datum.stk2) ? 0.75 : 0.3"},
  135.           "zindex": {"signal": "!groupSelector && (groupHover.stk1 == datum.stk1 || groupHover.stk2 == datum.stk2) ? 1 : 0"},
  136.           "tooltip": {"signal": "datum.stk1 + ' → ' + datum.stk2 + '    ' + format(datum.size, ',.0f') + '   (' + format(datum.percentage, '.1%') + ')'"}
  137.         },
  138.         "hover": {"strokeOpacity": {"value": 0.75}}
  139.       }
  140.     },
  141.     {
  142.       "type": "rect",
  143.       "name": "groupMark",
  144.       "from": {"data": "groups"},
  145.       "encode": {
  146.         "enter": {"fill": {"scale": "color", "field": "grpId"}, "width": {"scale": "x", "band": 1}},
  147.         "update": {
  148.           "x": {"scale": "x", "field": "stack"},
  149.           "y": {"field": "scaledY0"},
  150.           "y2": {"field": "scaledY1"},
  151.           "fillOpacity": {"value": 1},
  152.           "tooltip": {"signal": "datum.grpId + ': ' + format(datum.total, ',.0f') + '   (' + format(datum.percentage, '.1%') + ')'"}
  153.         },
  154.         "hover": {"fillOpacity": {"value": 1}}
  155.       }
  156.     },
  157.     {
  158.       "type": "text",
  159.       "from": {"data": "groups"},
  160.       "interactive": false,
  161.       "encode": {
  162.         "update": {
  163.           "x": {"signal": "scale('x', datum.stack) + (datum.rightLabel ? bandwidth('x') + 8 : -8)"},
  164.           "yc": {"signal": "(datum.scaledY0 + datum.scaledY1)/2"},
  165.           "align": {"signal": "datum.rightLabel ? 'left' : 'right'"},
  166.           "baseline": {"value": "middle"},
  167.           "fontWeight": {"value": "bold"},
  168.           "fontSize": {"value": 12},
  169.           "text": {"signal": "abs(datum.scaledY0-datum.scaledY1) > 11 ? datum.grpId : ''"}
  170.         }
  171.       }
  172.     },
  173.     {
  174.       "type": "group",
  175.       "data": [{"name": "dataForShowAll", "values": [{}], "transform": [{"type": "filter", "expr": "groupSelector"}]}],
  176.       "encode": {"enter": {"xc": {"signal": "width/1.85"}, "y": {"value": 0}, "width": {"value": 65}, "height": {"value": 25}}},
  177.       "marks": [
  178.         {
  179.           "type": "group",
  180.           "name": "groupReset",
  181.           "from": {"data": "dataForShowAll"},
  182.           "encode": {
  183.             "enter": {"cornerRadius": {"value": 3.5}, "fill": {"value": "#666666"}, "height": {"field": {"group": "height"}}, "width": {"field": {"group": "width"}}},
  184.             "update": {"opacity": {"value": 1}},
  185.             "hover": {"fill": {"value": "#444444"}}
  186.           },
  187.           "marks": [
  188.             {
  189.               "type": "text",
  190.               "interactive": false,
  191.               "encode": {
  192.                 "enter": {
  193.                   "xc": {"field": {"group": "width"}, "mult": 0.5},
  194.                   "yc": {"field": {"group": "height"}, "mult": 0.5, "offset": 1},
  195.                   "align": {"value": "center"},
  196.                   "baseline": {"value": "middle"},
  197.                   "text": {"value": "Show All"},
  198.                   "fontSize": {"value": 14},
  199.                   "stroke": {"value": "#ecf0f1"}
  200.                 }
  201.               }
  202.             }
  203.           ]
  204.         }
  205.       ]
  206.     }
  207.   ],
  208.   "signals": [
  209.     {
  210.       "name": "groupHover",
  211.       "value": {},
  212.       "on": [
  213.         {"events": "@groupMark:mouseover", "update": "{stk1:datum.stack=='stk1' && datum.grpId, stk2:datum.stack=='stk2' && datum.grpId, stk3:datum.stack=='stk3' && datum.grpId}"},
  214.         {"events": "mouseout", "update": "{}"}
  215.       ]
  216.     },
  217.     {
  218.       "name": "groupSelector",
  219.       "value": false,
  220.       "on": [
  221.         {"events": "@groupMark:click!", "update": "{stack:datum.stack, stk1:datum.stack=='stk1' && datum.grpId, stk2:datum.stack=='stk2' && datum.grpId, stk3:datum.stack=='stk3' && datum.grpId}"},
  222.         {"events": [{"type": "click", "markname": "groupReset"}, {"type": "dblclick"}], "update": "false"}
  223.       ]
  224.     }
  225.   ]
  226. }
Advertisement
Add Comment
Please, Sign In to add comment