Projekt

Obecné

Profil

Stáhnout (6.11 KB) Statistiky
| Větev: | Tag: | Revize:
1 c2c2ce48 Štěpán Červenka
{
2
  "$schema": "https://vega.github.io/schema/vega/v5.json",
3
  "width": 800,
4
  "height": 200,
5
  "padding": 5,
6
7
  "data": [
8
    {
9
      "name": "table",
10
      "values": null,
11
      "transform": [
12
        {
13
          "type": "formula",
14
          "expr": "toDate(datum[\"timestamp\"])",
15
          "as": "dateTime"
16
        },
17
        {
18
          "type": "timeunit",
19
          "field": "dateTime",
20
          "units": ["year","month", "date", "hours", "minutes", "seconds"],
21
          "step": {"signal": "timeStep"}
22
        },
23
        {
24
          "type": "formula",
25
          "expr": "time(datum[\"unit0\"] + (timeStep * 100))",
26
          "as": "barStart"
27
        },
28
        {
29
          "type": "formula",
30
          "expr": "time(datum[\"unit1\"] - (timeStep * 100))",
31
          "as": "barEnd"
32
        }
33
      ]
34
    }
35
36
      ],
37
38
39
40
  "signals": [
41
    {
42
      "name": "timeStep",
43
      "value": null
44
    },
45
    {
46
      "name": "detailDomain"
47
    }
48
49
  ],
50
51
  "marks": [
52
    {
53
      "type": "group",
54
      "name": "detail",
55
      "encode": {
56
        "enter": {
57
          "height": {"value": 390},
58
          "width": {"value": 800}
59
        }
60
      },
61
      "scales": [
62
        {
63
          "name": "xDetail",
64
          "type": "time",
65
          "range": "width",
66
          "domain": {"data": "table", "field": "dateTime"},
67
          "domainRaw": {"signal": "detailDomain"}
68
        },
69
        {
70
          "name": "yDetail",
71
          "type": "linear",
72
          "range": [390, 0],
73
          "domain": {"data": "table", "field": "avg"},
74
          "nice": true, "zero": true
75
        }
76
      ],
77
      "axes": [
78
        {"orient": "bottom", "scale": "xDetail"},
79
        {"orient": "left", "scale": "yDetail"}
80
      ],
81
      "marks": [
82
        {
83
          "type": "group",
84
          "encode": {
85
            "enter": {
86
              "height": {"field": {"group": "height"}},
87
              "width": {"field": {"group": "width"}},
88
              "clip": {"value": true}
89
            }
90
          },
91
          "marks": [
92
            {
93
              "type": "rect",
94
              "from": {"data":"table"},
95
              "encode": {
96
                "enter": {
97
                  "tooltip": {
98
                    "signal": "{title: timeFormat(datum.dateTime, '%A,%e.%B %Y, %X')  ,  'avg': datum.avg, 'sum': datum.sum, 'max': datum.max, 'min': datum.min }"
99
                  }},
100
                "update": {
101
                  "x": {"scale": "xDetail", "field": "barStart"},
102
                  "x2": {"scale": "xDetail", "field": "barEnd"},
103
                  "y": {"scale": "yDetail", "field": "avg"},
104
                  "y2": {"scale": "yDetail", "value": 0},
105
                  "color": {"value": "both"},
106
                  "fill": {"value": "steelBlue"}
107
                },
108
                "hover": {
109
                  "fill": {"value": "red"},
110
                  "size": {"value": 60}
111
                }
112
              }
113
            }
114
115
116
117
          ]
118
        }
119
      ]
120
    },
121
122
    {
123
      "type": "group",
124
      "name": "overview",
125
      "encode": {
126
        "enter": {
127
          "x": {"value": 0},
128
          "y": {"value": 430},
129
          "height": {"value": 70},
130
          "width": {"value": 720},
131
          "fill": {"value": "transparent"}
132
        }
133
      },
134
      "signals": [
135
        {
136
          "name": "brush", "value": 0,
137
          "on": [
138
            {
139
              "events": "@overview:mousedown",
140
              "update": "[x(), x()]"
141
            },
142
            {
143
              "events": "[@overview:mousedown, window:mouseup] > window:mousemove!",
144
              "update": "[brush[0], clamp(x(), 0, width)]"
145
            },
146
            {
147
              "events": {"signal": "delta"},
148
              "update": "clampRange([anchor[0] + delta, anchor[1] + delta], 0, width)"
149
            }
150
          ]
151
        },
152
        {
153
          "name": "anchor", "value": null,
154
          "on": [{"events": "@brush:mousedown", "update": "slice(brush)"}]
155
        },
156
        {
157
          "name": "xdown", "value": 0,
158
          "on": [{"events": "@brush:mousedown", "update": "x()"}]
159
        },
160
        {
161
          "name": "delta", "value": 0,
162
          "on": [
163
            {
164
              "events": "[@brush:mousedown, window:mouseup] > window:mousemove!",
165
              "update": "x() - xdown"
166
            }
167
          ]
168
        },
169
        {
170
          "name": "detailDomain",
171
          "push": "outer",
172
          "on": [
173
            {
174
              "events": {"signal": "brush"},
175
              "update": "span(brush) ? invert('xOverview', brush) : null"
176
            }
177
          ]
178
        }
179
      ],
180
      "scales": [
181
        {
182
          "name": "xOverview",
183
          "type": "time",
184
          "range": "width",
185
          "domain": {"data": "table", "field": "dateTime"}
186
        },
187
        {
188
          "name": "yOverview",
189
          "type": "linear",
190
          "range": [70, 0],
191
          "domain": {"data": "table", "field": "value"},
192
          "nice": true, "zero": true
193
        }
194
      ],
195
      "axes": [
196
        {"orient": "bottom", "scale": "xOverview"}
197
      ],
198
      "marks": [
199
200
201
        {
202
          "type": "rect",
203
          "name": "brush",
204
          "encode": {
205
            "enter": {
206
              "y": {"value": 0},
207
              "height": {"value": 70},
208
              "fill": {"value": "#333"},
209
              "fillOpacity": {"value": 0.2}
210
            },
211
            "update": {
212
              "x": {"signal": "brush[0]"},
213
              "x2": {"signal": "brush[1]"}
214
            }
215
          }
216
        },
217
        {
218
          "type": "rect",
219
          "interactive": false,
220
          "encode": {
221
            "enter": {
222
              "y": {"value": 0},
223
              "height": {"value": 70},
224
              "width": {"value": 1},
225
              "fill": {"value": "firebrick"}
226
            },
227
            "update": {
228
              "x": {"signal": "brush[0]"}
229
            }
230
          }
231
        },
232
        {
233
          "type": "rect",
234
          "interactive": false,
235
          "encode": {
236
            "enter": {
237
              "y": {"value": 0},
238
              "height": {"value": 70},
239
              "width": {"value": 1},
240
              "fill": {"value": "firebrick"}
241
            },
242
            "update": {
243
              "x": {"signal": "brush[1]"}
244
            }
245
          }
246
        }
247
      ]
248
    }
249
  ]
250
}
251
252