-
Notifications
You must be signed in to change notification settings - Fork 0
/
hurricaneWithMenu.html
249 lines (240 loc) · 9.82 KB
/
hurricaneWithMenu.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" >
<meta charset="UTF-8">
<meta http-equiv="Content-Language" content="en-US" >
</head>
<body>
<style>
.axis {
shape-rendering: crispEdges;
}
.x.axis line {
stroke: #ccc;
}
.x.axis .minor {
stroke-opacity: .5;
}
.x.axis path {
display: none;
}
/*
.bar {
fill: steelblue;
}
*/
text {
color: black;
}
</style>
<link href="./nv.d3.css" rel="stylesheet" type="text/css">
<link href="./menu.css" rel="stylesheet" type="text/css">
<style>
svg#main { padding-top: 70px; }
</style>
<script src="./bower_components/d3/d3.js"></script>
<script src="./bower_components/underscore/underscore.js"></script>
<script src="./bower_components/1670507/underscoreAddon.js"></script>
<script src="./bower_components/momentjs/moment.js"></script>
<script src="./../underscore-unchained/underscore-unchained.js"></script>
<script src="./../supergroup/supergroup.js"></script>
<script src="./../sequence-viz/evtData.js"></script>
<script src="./../sequence-viz/lifeflowData.js"></script>
<script src="./../sequence-viz/lifeflow.js"></script>
<script src="./../sequence-viz/timelines.js"></script>
<script src="./../sequence-viz/lifeflowExtras.js"></script>
<script src="./nvd3_tooltip.js"></script>
<script src="./nvd3_utils.js"></script>
<!--
<script src="./timelines.js"></script>
<script src="./lifeflowChart.js"></script>
-->
<!-- nvd3 stuff
<script type="text/javascript" src="./nvd3/nv.d3.js"></script>
<script src="./nvd3/src/utils.js"></script>
<script src="./legend.js"></script>
<script src="./nvd3/src/models/axis.js"></script>
just for contextMenu
<script type="text/javascript" src="./jquery-1.9.1.js"></script>
<script src="./jquery-contextMenu/jquery.contextMenu.js"></script>
<link href="./jquery-contextMenu/jquery.contextMenu.css" rel="stylesheet" type="text/css">
-->
<script>
var eventOrder = [
'Subtropical storm',
'Genesis',
'Disturbance',
'Subtropical Depression',
'Tropical Wave',
'Tropical Depression',
'Tropical Storm',
'Hurricane',
'Landfall',
'Extratropical',
'Low',
'Intensity Peak',
'Maximum wind',
'Status change'];
var filteredOut = _.supergroup([]);
d3.csv('./sampleData/hurricane.csv', function (data) {
var extras = lifeflowExtras();
edata = evtData()
.entityIdProp('hur_id')
.eventNameProp('status')
.startDateProp('date')
.eventOrder(eventOrder)
//if (!eventNames) setEventNames(data);
var timelineData = edata.makeTimelines(data);
timelineData.timelineUnit('hour');
var startRecs = _.chain(timelineData)
.pluck('records')
.map(_.first)
.value();
var startRecs = timelineData
.pluck('records')
.map(_.first);
var eventNodeWidth = 2 * 1000 * 60 * 60 * 24; // ends up in miliseconds!
var lifeflowNodes = lifeflowData()
.eventNameProp('status')
.eventNodeWidth(eventNodeWidth)
.timelines(timelineData)
(startRecs /*, 'noflatten' */);
var menuData = [
{ label: 'Chart type', subs: [
{ label: 'LifeFlow', action: showLifeflow,
refresh: true,
subs: [
{ label: 'Fill gap from previous event',
action:null},
{ label: 'Hide distribution on mouseover',
action:null}
]
},
{ label: 'Timelines', action:showTimelines,
refresh: true, subs: [] },
{ label: 'Icicle', action:null,
refresh: true, subs: [] }
]},
{ label: 'Filter', subs:
_.supergroup(
_(eventOrder).map(function(evtName) {
//var filterThis = filteredOut.contains(evtName);
return { label: evtName,
LIprops: {filtered: false},
action: _.partial(filter, evtName) }
}))
},
{ label: 'Align by', action: null, subs: [ ] },
];
_.supergroup(menuData);
extras.menu(d3.select('body'), menuData);
var container = d3.select('body')
.append('div')
.append('svg')
.attr('id','main')
;
extras.dispatch.on('refresh', function() {
d3.select('svg#main').selectAll('*').remove();
})
function filter(evtName, datum, i, j) {
var item = menuData
.findWhere({label:'Filter'})
.subs.findWhere({label:evtName})
item.LIprops.filtered = !item.LIprops.filtered;
extras.menu(d3.select('body'), menuData);
}
function showLifeflow() {
var chart = lifeflowChart()
//.entityIdProp('hur_id')
//.eventNameProp('status')
//.startDateProp('date')
.eventNodeWidth(10000000)
.height(window.innerHeight - 120)
.width(window.innerWidth - 100)
;
chart.dispatch.on("lifeflowMouseover",
function(lfChart, domNode, lfnode, i) {
var gNode = domNode.parentNode; // event is on the rect now
extras.showEvtDistribution(lfChart, gNode,
lfnode, i);
extras.nodeTooltip(lfChart, gNode, lfnode, i);
});
chart.dispatch.on("lifeflowMouseout", extras.mouseout);
container
.datum(lifeflowNodes)
.call(chart);
extras.dispatch.on('distNodeMouseover', extras.distNodeTooltip);
}
function showTimelines() {
var chart = timelineChart()
.entityIdProp('hur_id')
.eventNameProp('status')
.startDateProp('date')
.unitProp(1000*60*60) // hours
.height(window.innerHeight - 120)
.width(window.innerWidth - 100)
;
//chart.dispatch.on("eventNodeMouseover", extras.gMouseover);
container
.datum(timelineData)
.call(chart)
}
/*
if (chart.alignBy() === 'Start' || !chart.alignBy()) {
var startRecs = _.chain(timelineData)
.pluck('records')
.map(_.first)
.value();
lifeflowNodes = lifeflowData(startRecs,
function(d) { return d.next() });
//lifeflowNodes.shift();
} else if (chart.alignBy() === 'End') {
var startRecs = _.chain(timelineData)
.pluck('records')
.map(_.last)
.value();
lifeflowNodes = lifeflowData(startRecs,
function(d) { return d.prev() });
} else {
var startRecs = _.chain(timelineData.data())
.filter(function(d) {
return d[eventNameProp] === chart.alignBy()
})
.value();
var lifeflowNodesRight = lifeflowData(startRecs,
function(d) { return d.next() });
var lifeflowNodesLeft = lifeflowData(startRecs,
function(d) { return d.prev() }, true);
//lifeflowNodesLeft = [];
lifeflowNodes = lifeflowNodesLeft.concat(lifeflowNodesRight);
}
*/
});
</script>
<!--
<div id='cssmenu'>
<ul>
<li class='active'><a href='index.html'><span>Home</span></a></li>
<li class='has-sub'><a href='#'><span>Products</span></a>
<ul>
<li class='has-sub'><a href='#'><span>Product 1</span></a>
<ul>
<li><a href='#'><span>Sub Item</span></a></li>
<li class='last'><a href='#'><span>Sub Item</span></a></li>
</ul>
</li>
<li class='has-sub'><a href='#'><span>Product 2</span></a>
<ul>
<li><a href='#'><span>Sub Item</span></a></li>
<li class='last'><a href='#'><span>Sub Item</span></a></li>
</ul>
</li>
</ul>
</li>
<li><a href='#'><span>About</span></a></li>
<li class='last'><a href='#'><span>Contact</span></a></li>
</ul>
</div>
-->
</body>
</html>