File size: 3,000 Bytes
e29e51c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
{
    "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
    "data": {
        "values": "<DVC_METRIC_DATA>"
    },
    "title": "<DVC_METRIC_TITLE>",
    "facet": {
        "field": "rev",
        "type": "nominal"
    },
    "spec": {
        "transform": [
            {
                "aggregate": [
                    {
                        "op": "count",
                        "as": "xy_count"
                    }
                ],
                "groupby": [
                    "<DVC_METRIC_Y>",
                    "<DVC_METRIC_X>"
                ]
            },
            {
                "impute": "xy_count",
                "groupby": [
                    "rev",
                    "<DVC_METRIC_Y>"
                ],
                "key": "<DVC_METRIC_X>",
                "value": 0
            },
            {
                "impute": "xy_count",
                "groupby": [
                    "rev",
                    "<DVC_METRIC_X>"
                ],
                "key": "<DVC_METRIC_Y>",
                "value": 0
            },
            {
                "joinaggregate": [
                    {
                        "op": "max",
                        "field": "xy_count",
                        "as": "max_count"
                    }
                ],
                "groupby": []
            },
            {
                "calculate": "datum.xy_count / datum.max_count",
                "as": "percent_of_max"
            }
        ],
        "encoding": {
            "x": {
                "field": "<DVC_METRIC_X>",
                "type": "nominal",
                "sort": "ascending",
                "title": "<DVC_METRIC_X_LABEL>"
            },
            "y": {
                "field": "<DVC_METRIC_Y>",
                "type": "nominal",
                "sort": "ascending",
                "title": "<DVC_METRIC_Y_LABEL>"
            }
        },
        "layer": [
            {
                "mark": "rect",
                "width": 300,
                "height": 300,
                "encoding": {
                    "color": {
                        "field": "xy_count",
                        "type": "quantitative",
                        "title": "",
                        "scale": {
                            "domainMin": 0,
                            "nice": true
                        }
                    }
                }
            },
            {
                "mark": "text",
                "encoding": {
                    "text": {
                        "field": "xy_count",
                        "type": "quantitative"
                    },
                    "color": {
                        "condition": {
                            "test": "datum.percent_of_max > 0.5",
                            "value": "white"
                        },
                        "value": "black"
                    }
                }
            }
        ]
    }
}