forked from ampproject/amphtml
-
Notifications
You must be signed in to change notification settings - Fork 1
/
viz-vega.amp.html
111 lines (105 loc) · 4.47 KB
/
viz-vega.amp.html
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
109
110
111
<!doctype html>
<html ⚡>
<head>
<meta charset="utf-8">
<title>Vega Visualization examples</title>
<link rel="canonical" href="amps.html">
<meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Questrial" rel="stylesheet" type="text/css">
<script async custom-element="amp-lightbox" src="https://cdn.ampproject.org/v0/amp-lightbox-0.1.js"></script>
<script async custom-element="amp-viz-vega" src="https://cdn.ampproject.org/v0/amp-viz-vega-0.1.js"></script>
<style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
<script async src="https://cdn.ampproject.org/v0.js"></script>
<style amp-custom>
amp-lightbox amp-viz-vega {
background-color: yellow;
}
</style>
</head>
<body>
<h1>Vega Visualization</h1>
<h2>Responsive size with remote data</h2>
<amp-viz-vega width="400" height="200" layout="responsive" src="vega-data/bar.json">
</amp-viz-vega>
<h2>Responsive size with inline data</h2>
<amp-viz-vega width="400" height="400" layout="responsive">
<!-- https://github.com/vega/vega/blob/master/examples/arc.json -->
<script type="application/json">
{
"width": 400,
"height": 400,
"data": [
{
"name": "table",
"values": [12, 23, 47, 6, 52, 19],
"transform": [{"type": "pie", "field": "data"}]
}
],
"scales": [
{
"name": "r",
"type": "sqrt",
"domain": {"data": "table", "field": "data"},
"range": [20, 100]
}
],
"marks": [
{
"type": "arc",
"from": {"data": "table"},
"properties": {
"enter": {
"x": {"field": {"group": "width"}, "mult": 0.5},
"y": {"field": {"group": "height"}, "mult": 0.5},
"startAngle": {"field": "layout_start"},
"endAngle": {"field": "layout_end"},
"innerRadius": {"value": 20},
"outerRadius": {"scale": "r", "field": "data"},
"stroke": {"value": "#fff"}
},
"update": {
"fill": {"value": "#ccc"}
},
"hover": {
"fill": {"value": "pink"}
}
}
},
{
"type": "text",
"from": {"data": "table"},
"properties": {
"enter": {
"x": {"field": {"group": "width"}, "mult": 0.5},
"y": {"field": {"group": "height"}, "mult": 0.5},
"radius": {"scale": "r", "field": "data", "offset": 8},
"theta": {"field": "layout_mid"},
"fill": {"value": "#000"},
"align": {"value": "center"},
"baseline": {"value": "middle"},
"text": {"field": "data"}
}
}
}
]
}
</script>
</amp-viz-vega>
<h2>fixed-height size world map with remote data pointing to remote data using topojson</h2>
<amp-viz-vega use-data-width height="500" layout="fixed-height" src="vega-data/map.json">
<amp-img placeholder height="500" layout="fixed-height" src="https://placehold.it/400x200?text=Custom Placeholder">
</amp-img>
</amp-viz-vega>
<h2>Responsive size interactive graph with remote data</h2>
<amp-viz-vega width="2" height="1.5" layout="responsive" src="vega-data/nodes.json">
</amp-viz-vega>
<h2>Responsive size inside lightbox</h2>
<button on="tap:vega-lightbox.activate">
Open Lightbox
</button>
<amp-lightbox id="vega-lightbox" layout="nodisplay">
<amp-viz-vega width="400" height="200" layout="responsive" src="vega-data/bar.json">
</amp-viz-vega>
</amp-lightbox>
</body>
</html>