-
Notifications
You must be signed in to change notification settings - Fork 3
/
UpStream_DashBoard_EFStudy.html
549 lines (474 loc) · 22.3 KB
/
UpStream_DashBoard_EFStudy.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
<!DOCTYPE html>
<html>
<head>
<style>
.axis {
font-size: 13px;
}
.axis path,
.axis line {
fill: none;
display: none;
}
h1 {
color: #0099FF;
}
p {
color: #000000;
}
tr {
background-color: #000000;
}
td {
background-color: #0099FF;
}
table {
color: #FFFFFF;
}
body {
font-family: 'Helvetica Neue', Helvetica;
font-weight: 300;
padding: 20px;
}
html,
body {
height: 100%;
padding: 0;
margin: 0;
}
div {
width: 50%;
height: 50%;
float: left;
}
#top_left {
background: #DDD;
}
#top_right {
background: #AAA;
}
#Bottom_left {
background: #777;
}
#Bottom_right {
background: #444;
}
</style>
<script type="text/javascript" src="./js/d3.js"></script>
</head>
<body>
<div id="top_left"></div>
<div id="top_right"></div>
<div id="Bottom_left"></div>
<div id="Bottom_right"></div>
<script type="text/javascript">
setTimeout(function() {
var formatComma = d3.format(",")
var margin = {
top: 15,
right: 100,
bottom: 15,
left: 100
};
//--- load the data
d3.csv("./data/EfData.csv", function(EfData) {
d3.json("./data/EF_Counties.geojson", function(json) {
// ------------------------------------------------------------------
// (TOP LEFT VISUALIZATION)
// ------------------------------------------------------------------
var Count_ = d3.nest()
.key(function(d) {
return d.Location_County;
})
.rollup(function(v) {
return v.length;
})
.entries(EfData);
//sort bars based on values
Count_ = Count_.sort(function(a, b) {
return d3.ascending(a.value, b.value);
})
var newCount_ = Count_.filter(function(x) {
return x.value >= 700
});
//set up svg using margin conventions - we'll need plenty of room on the left for labels
var c10 = d3.scaleLinear().domain([1, newCount_.length])
.interpolate(d3.interpolateHcl)
.range([d3.rgb("#5E4FA2"), d3.rgb('#E6F598'), d3.rgb('#9E0142')]);
var TL_Size = document.getElementById("top_left")
var TL_width = TL_Size.clientWidth - margin.left - margin.right
var TL_height = TL_Size.clientHeight - margin.top - margin.bottom
var TL_svg = d3.select("#top_left").append("svg")
.attr("width", TL_width + margin.left + margin.right)
.attr("height", TL_height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var x = d3.scaleLinear()
.range([0, TL_width]);
var y = d3.scaleBand()
.range([TL_height, 0]).padding(0.1);;
x.domain([0, d3.max(newCount_, function(d) {
return d.value;
})]);
y.domain(newCount_.map(function(d) {
return d.key;
}));
var xAxis = d3.axisBottom(x);
//make y axis to show bar keys
var yAxis = d3.axisLeft(y);
var TL_g = TL_svg.append("g")
.attr("class", "y axis")
.call(yAxis)
var TL_bars = TL_svg.selectAll(".bar")
.data(newCount_)
.enter()
.append("g")
//append rects
TL_bars.append("rect")
.attr("class", "bar")
.attr("y", function(d) {
return y(d.key);
})
.attr("height", y.bandwidth())
.attr("x", 0)
.attr("fill", function(d, i) {
return c10(i);
})
.attr("width", function(d) {
return x(d.value);
});
//add a values label to the right of each bar
TL_bars.append("text")
.attr("class", "label")
//y position of the label is halfway down the bar
.attr("y", function(d) {
return y(d.key) + y.bandwidth() / 2 + 4;
})
//x position is 3 pixels to the right of the bar
.attr("x", function(d) {
return x(d.value) + 3;
})
.text(function(d) {
return formatComma(d.value);
});
// add textbox
TL_svg.append("text")
.attr("x", (TL_width / 2))
.attr("y", 0 - (margin.top / 10))
.attr("text-anchor", "middle")
.style("font-size", "18px")
.style("font-weight","bold")
.style("text-decoration", "underline")
.text("Total Number of Wells For Each County ");
// ------------------------------------------------------------------
//(TOP RIGHT VISUALIZATION)
// ------------------------------------------------------------------
var Prod_index = {
0: ["Oil", "#FF0000"],
1: ["Gas Condensate", "#ff9900"],
2: ["Dry Gas", "#ffff00"],
3: ['Wet Gas', '#d9b38c'],
4: ['blank', '#cccccc']
};
var TR_Size = document.getElementById("top_right")
var TR_width = TR_Size.clientWidth
var TR_height = TR_Size.clientHeight
var center = d3.geoCentroid(json)
var scale = [3500];
var offset = [TR_width / 2, TR_height / 2];
var projection = d3.geoMercator().scale(scale).center(center).translate(offset);
var path = d3.geoPath().projection(projection);
var Mapsvg = d3.select("#top_right").append("svg").attr("width", TR_width).attr("height", TR_height)
var TR_g = Mapsvg.append("g");
projection = d3.geoMercator().center(center).scale(scale).translate(offset);
path = path.projection(projection);
TR_g.selectAll("path")
.data(json.features)
.enter()
.append("path")
.attr("d", path)
.style("stroke-width", "1")
.style("stroke", "#ffffff")
.style("fill", "#000000");
TR_g.selectAll("text")
.data(json.features)
.enter()
.append("svg:text")
.style("fill", "white")
.text(function(d) {
return d.properties.NAME;
})
.style("font-size", 8 + "px")
.attr("x", function(d) {
return path.centroid(d)[0];
})
.attr("y", function(d) {
return path.centroid(d)[1];
})
//--- Plot Wells
TR_g.selectAll("circle")
.data(EfData)
.enter()
.append("circle")
.attr("cx", function(d) {
return projection([d.Location_SLongitude, d.Location_SLatitude])[0];
})
.attr("cy", function(d) {
return projection([d.Location_SLongitude, d.Location_SLatitude])[1];
})
.attr("r", "2px")
.style("stroke", "black") // set the line colour
.style("stroke-width", "0.1")
.style("fill", function(d) {
var value = d.Prod_Type;
if (value === 'OIL ') {
return "#FF0000";
} else if (value === 'LIQUIDS RICH GAS ') {
return "#ff9900";
} else if (value === 'DRY GAS ') {
return "#ffff00";
} else if (value === 'WET GAS ') {
return "#d9b38c";
} else {
return "#cccccc";
}
})
//--- Add Legend
var spaceCircles = [20, 40, 60, 80, 100];
var v_ = TR_width * 0.1
var svgContainer = Mapsvg.append("svg")
var circles = svgContainer.selectAll("circle")
.data(spaceCircles)
.enter()
.append("circle");
var circleAttributes = circles
.attr("cx", v_)
.attr("cy", function(d) {
return d;
})
.attr("r", 6)
.style("fill", function(d, i) {
var returnColor = Prod_index[i][1];
return returnColor;
});
svgContainer.selectAll('text')
.data(spaceCircles)
.enter()
.append("text")
.attr("x", v_ + 10)
.attr("y", function(d) {
return d + 5;
})
.text(function(d, i) {
var text = Prod_index[i][0];
return text;
});
//--- zoom
var zoom = d3.zoom().scaleExtent([1, 8]).on("zoom", zoomed);
function zoomed() {
TR_g.style("stroke-width", 1.0 / d3.event.transform.k + "px");
TR_g.attr("transform", d3.event.transform); // updated for d3 v4
TR_g.selectAll("text").style("font-size", 11 - 1 * d3.event.transform.k + "px");
TR_g.selectAll("circle").attr("r", 3 / d3.event.transform.k);
//g.style("stroke-width", 3 / (d3.event.transform.k * 2) + "px");
}
Mapsvg.call(zoom)
// add textbox
Mapsvg.append("text")
.attr("x", (TR_width - TR_width / 5))
.attr("y", TR_height - (margin.top * 2))
.attr("text-anchor", "middle")
.style("font-size", "18px")
.style("font-weight","bold")
.style("text-decoration", "underline")
.text("Well Locations (Texas Counties)");
// ------------------------------------------------------------------
//(BOTTOM LEFT VISUALIZATION)
// ------------------------------------------------------------------
var parseDate = d3.timeParse("%Y-%m-%d");
//EfData.forEach(function(d){ d.Date_StartDate=parseDate(d.Date_StartDate) });
EfData.forEach(function(d) {
var parts = d.Date_StartDate.split('-');
if (parts[0] !== NaN) {
d.Year = parseInt(parts[0])
} else {
d.Year = 0
}
});
var NestedProduction = d3.nest().key(function(d) {
return d.Year > 0
}).key(function(d) {
return d.Year;
}).rollup(function(v) {
return d3.mean(v, function(d) {
return d.Prod_BOE6Month
});
}).entries(EfData);
BOEPerWellPerYear = NestedProduction[0].values
//sort bars based on values
BOEPerWellPerYear = BOEPerWellPerYear.sort(function(a, b) {
return d3.ascending(a.key, b.key);
})
var BL_Size = document.getElementById("Bottom_left")
var BL_width = BL_Size.clientWidth - margin.left - margin.right
var BL_height = BL_Size.clientHeight - margin.top - margin.bottom
var BL_svg = d3.select("#Bottom_left").append("svg")
.attr("width", BL_width + margin.left + margin.right)
.attr("height", BL_height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var x = d3.scaleLinear()
.range([0, BL_width]);
var y = d3.scaleBand()
.range([BL_height, 0]).padding(0.1);;
x.domain([0, d3.max(BOEPerWellPerYear, function(d) {
return d.value;
})]);
y.domain(BOEPerWellPerYear.map(function(d) {
return d.key;
}));
var xAxis = d3.axisBottom(x);
//make y axis to show bar keys
var yAxis = d3.axisLeft(y);
var BL_g = BL_svg.append("g")
.attr("class", "y axis")
.call(yAxis)
var BL_bars = BL_svg.selectAll(".bar")
.data(BOEPerWellPerYear)
.enter()
.append("g")
//append rects
BL_bars.append("rect")
.attr("class", "bar")
.attr("y", function(d) {
return y(d.key);
})
.attr("height", y.bandwidth())
.attr("x", 0)
.attr("fill", function(d, i) {
return c10(i);
})
.attr("width", function(d) {
return x(d.value);
});
//add a values label to the right of each bar
BL_bars.append("text")
.attr("class", "label")
//y position of the label is halfway down the bar
.attr("y", function(d) {
return y(d.key) + y.bandwidth() / 2 + 4;
})
//x position is 3 pixels to the right of the bar
.attr("x", function(d) {
return x(d.value) + 3;
})
.text(function(d) {
return formatComma(Math.round(d.value));
});
// add textbox
BL_svg.append("text")
.attr("x", (BL_width / 2))
.attr("y", 0 - (margin.top / 10))
.attr("text-anchor", "middle")
.style("font-size", "18px")
.style("font-weight","bold")
.style("text-decoration", "underline")
.text("Avg 6 Month BOE per Year (STB)");
// ------------------------------------------------------------------
//(BOTTOM Right VISUALIZATION)
// ------------------------------------------------------------------
var NestedProduction2 = d3.nest()
.key(function(d) {
return d.Year > 0
})
.key(function(d) {
return d.Year;
})
.key(function(d) {
return d.Info_Operator;
})
//.rollup(function(v) { return d3.mean(v,function(d){return d.Prod_BOE6Month}); })
.rollup(function(leaves) {
var AVG = d3.mean(leaves, function(d) {
return d.Prod_BOE6Month
})
var Count = d3.nest().key(function(d) {
return d.length
})
.entries(leaves);
return {
AVG: AVG,
Count: Count[0].values.length
};
})
.entries(EfData);
Nested = NestedProduction2[0].values
OPbyYear = [
[],
[],
[],
[]
]
for (var i = 0; i < Nested.length; i++) {
Ops = new Array()
Values = new Array()
Counts = new Array()
for (var j = 0; j < Nested[i].values.length; j++) {
if (Nested[i].values[j].value.Count >= 20) {
Values.push(parseFloat(Nested[i].values[j].value.AVG))
Ops.push(Nested[i].values[j].key)
Counts.push(Nested[i].values[j].value.Count)
}
}
var Index = Values.indexOf(Math.max.apply(NaN, Values))
if (Index >= 0) {
OPbyYear.push([Nested[i].key, Ops[Index], Math.round(Values[Index]), Counts[Index]])
}
}
OPbyYear = OPbyYear.filter(function(x) {
return x[2] > 0
});
OPbyYear = OPbyYear.sort(function(a, b) {
return a[0] - b[0];
});
for (var i = 0; i < OPbyYear.length; i++) {
OPbyYear[i][2] = formatComma(OPbyYear[i][2])
}
var BR_Size = document.getElementById("Bottom_right")
var BR_width = BR_Size.clientWidth - margin.left - margin.right
var BR_height = BR_Size.clientHeight - margin.top - margin.bottom
var table = d3.select("#Bottom_right").append("table")
.attr("width", BR_width + margin.left + margin.right)
.attr("height", BR_height + margin.top + margin.bottom)
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var header = table.append("thead").append("tr");
header.selectAll("th")
.data(["Year", "Operator", "Avg Production", "#Wells"])
.enter()
.append("th")
.text(function(d) {
return d;
});
var tablebody = table.append("tbody");
rows = tablebody
.selectAll("tr")
.data(OPbyYear)
.enter()
.append("tr");
// We built the rows using the nested array - now each row has its own array.
cells = rows.selectAll("td")
// each row has data associated; we get it and enter it for the cells.
.data(function(d) {
// console.log(d);
return d;
})
.enter()
.append("td")
.text(function(d) {
return d;
});
}); //geoJson
}); //csv
}, 1000); //timeout
</script>
</body>