forked from speced/respec
-
Notifications
You must be signed in to change notification settings - Fork 1
/
data.html
212 lines (191 loc) · 7.77 KB
/
data.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<div class='row trunk-section'>
<div class='col-lg-7 text-center'>
<div class='row'>
<div class='col-lg-12 text-center' id='missing-y'></div>
</div>
</div>
<div class='col-lg-5'>
<div class='data-column'>
<a href='data/missing-y.json'>data</a>
</div>
<pre><code class='javascript'>d3.json('data/missing-y.json', function(data) {
data = MG.convert.date(data, 'date');
MG.data_graphic({
title: "Few Observations",
description: "We sometimes have only a few observations. By setting <i>missing_is_zero: true</i>, missing values for a time-series will be interpreted as zeros. In this example, we've overridden the rollover callback to show 'no data' for missing observations and have set the <i>min_x</i> and <i>max_x</i> options in order to expand the date range.",
data: data,
interpolate: 'basic',
missing_is_zero: true,
width: 600,
height: 200,
right: 40,
min_x: new Date('2014-01-01'),
max_x: new Date('2014-06-01'),
target: '#missing-y',
mouseover: function(d, i) {
var df = d3.time.format('%b %d, %Y');
var date = df(d.date);
var y_val = (d.value === 0) ? 'no data' : d.value;
d3.select('#missing-y svg .mg-active-datapoint')
.text(date + ' ' + y_val);
}
});
});</code></pre>
</div>
</div>
<div class='row trunk-section'>
<div class='col-lg-7 text-center' id='missing_is_hidden'></div>
<div class='col-lg-5'>
<div class='data-column'><a href='data/missing-is-hidden.json'>data</a></div>
<pre><code class='javascript'>d3.json('data/missing-is-hidden.json', function(data) {
data = MG.convert.date(data, 'date');
MG.data_graphic({
title: 'Broken Lines',
description: 'Setting <i>missing_is_hidden</i> to true will hide missing ranges rather than considering them to be zeros or interpolating between the two points on either side.',
data: data,
missing_is_hidden: true,
width: 600,
height: 200,
right: 40,
target: '#missing_is_hidden',
area: false,
show_secondary_x_label: false
});
});</code></pre>
</div>
</div>
<div class='row trunk-section'>
<div class='col-lg-7 text-center'>
<div class='row'>
<div class='col-lg-12 text-center' id='glorious_chart'></div>
</div>
</div>
<div class='col-lg-5'>
<pre><code class='javascript'>MG.data_graphic({
title: "Glorious Graphic",
description: "This is an example of a graphic whose data is currently missing. We've also set the <i>error</i> option, which appends an error icon to the title and logs an error to the browser's console.",
error: 'This data is blocked by Lorem Ipsum. Get your **** together, Ipsum.',
chart_type: 'missing-data',
missing_text: 'This is an example of a missing chart',
target: '#glorious_chart',
width: 600,
height: 200
});</code></pre>
</div>
</div>
<div class='row trunk-section'>
<div class='col-lg-7 text-center'>
<div class='row'>
<div class='col-lg-12 text-center' id='missing1'></div>
</div>
</div>
<div class='col-lg-5'>
<div class='data-column'>
<a href='data/fake_users2.json'>data</a>
</div>
<pre><code class='javascript'>d3.json('data/fake_users2.json', function(data) {
for (var i = 0; i < data.length; i++) {
data[i] = MG.convert.date(data[i], 'date');
}
var all_the_data = MG.clone(data[0]);
for (i = 1; i < data.length; i++){
for (var j=0; j < data[i].length; j++){
if (i === 2 && all_the_data[j].date < new Date('2014-02-01')) {
} else {
all_the_data[j]['value' + (i + 1)] = data[i][j].value;
}
}
}
MG.data_graphic({
title: "Handling Different Sized Lines in a Single Array",
description: "How do you handle data with multiple implied time series lengths?",
data: all_the_data,
width: 600,
height: 200,
right: 40,
target: '#missing1',
linked: true,
y_extended_ticks: true,
x_accessor: 'date',
y_accessor: ['value', 'value2', 'value3']
});
});</code></pre>
</div>
</div>
<script>
d3.json('data/missing-y.json', function(data) {
data = MG.convert.date(data, 'date');
MG.data_graphic({
title: "Few Observations",
description: "We sometimes have only a few observations. By setting <i>missing_is_zero: true</i>, missing values for a time-series will be interpreted as zeros. In this example, we've overridden the rollover callback to show 'no data' for missing observations and have set the <i>min_x</i> and <i>max_x</i> options in order to expand the date range.",
data: data,
interpolate: 'basic',
missing_is_zero: true,
width: 600,
height: 200,
right: 40,
min_x: new Date('2014-01-01'),
max_x: new Date('2014-06-01'),
target: '#missing-y',
mouseover: function(d, i) {
var df = d3.time.format('%b %d, %Y');
var date = df(d.date);
var y_val = (d.value === 0) ? 'no data' : d.value;
d3.select('#missing-y svg .mg-active-datapoint')
.text(date + ' ' + y_val);
}
});
});
d3.json('data/missing-is-hidden.json', function(data) {
data = MG.convert.date(data, 'date');
MG.data_graphic({
title: 'Broken Lines',
description: 'Setting <i>missing_is_hidden</i> to true will hide missing ranges rather than considering them to be zeros or interpolating between the two points on either side.',
data: data,
missing_is_hidden: true,
width: 600,
height: 200,
right: 40,
target: '#missing_is_hidden',
area: false,
show_secondary_x_label: false
});
});
MG.data_graphic({
title: "Glorious Graphic",
chart_type: 'missing-data',
description: "This is an example of a graphic whose data is currently missing. We've also set the <i>error</i> option, which appends an error icon to the title and logs an error to the browser's console.",
error: 'This data is blocked by Lorem Ipsum. Get your **** together, Ipsum.',
missing_text: 'This is an example of a missing chart',
target: '#glorious_chart',
width: 600,
height: 200
});
d3.json('data/fake_users2.json', function(data) {
for (var i = 0; i < data.length; i++) {
data[i] = MG.convert.date(data[i], 'date');
}
var all_the_data = MG.clone(data[0]);
for (i = 1; i < data.length; i++){
for (var j=0; j < data[i].length; j++){
if (i === 2 && all_the_data[j].date < new Date('2014-02-01')) {
} else {
all_the_data[j]['value' + (i + 1)] = data[i][j].value;
}
}
}
MG.data_graphic({
title: "Handling Different Sized Lines in a Single Array",
description: "How do you handle data with multiple implied time series lengths?",
data: all_the_data,
width: 600,
height: 200,
right: 40,
target: '#missing1',
linked: true,
y_extended_ticks: true,
x_accessor: 'date',
y_accessor: ['value', 'value2', 'value3']
});
});
</script>