-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimeline.js
145 lines (135 loc) · 4.43 KB
/
timeline.js
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
// Parse all dates into Date objects
if (window.JSON && !window.JSON.dateParser) {
var reDate = /^(\d{4})-(\d{2})-(\d{2})$/;
JSON.dateParser = function (key, value) {
if (typeof value === 'string') {
var a = reDate.exec(value);
if (a)
return new Date(value);
}
return value;
};
}
function loadTimeline() {
fetch('region_timeline.json', {cache: "force-cache"})
.then(
function(response) {
if (response.status !== 200) {
console.log('Looks like there was a problem. Status Code: ' +
response.status);
return;
}
response.text().then(function(respBody) {
let timelineData = JSON.parse(respBody, JSON.dateParser);
let select = document.getElementById('slice');
let slice = select.options[select.selectedIndex].text;
let regionTimeline = timelineData['ByRegion'];
let serviceLaunchDates = timelineData['ServiceLaunchDates'];
let regionLaunchDates = timelineData['RegionLaunchDates'];
populateGraph(slice, regionTimeline, serviceLaunchDates, regionLaunchDates);
});
}
)
.catch(function(err) {
console.log('Fetch Error', err);
});
}
function populateGraph(slice, regionTimeline, serviceLaunchDates, regionLaunchDates) {
let services = Object.keys(serviceLaunchDates).sort();
let regions = Object.keys(regionLaunchDates).sort();
let data = [];
switch (slice) {
case 'Region':
services.forEach(function (service) {
let serviceLaunchDate = serviceLaunchDates[service];
let trace = {
y: regions,
name: service,
orientation: 'h',
marker: {
width: 1
},
type: 'bar'
};
let x = [];
regions.forEach(function (region) {
let regionLaunchDate = regionLaunchDates[region];
if (service in regionTimeline[region]) {
// We want the difference between the date the region or service was launched (whichever is greater)
// and the date the service was expanded into this region
let regionServiceLaunchDate = Math.max.apply(null, [regionLaunchDate, serviceLaunchDate]);
let regionServiceExpansionDate = regionTimeline[region][service]["date"];
let delayWeeks = Math.floor((regionServiceExpansionDate - regionServiceLaunchDate) / 1000 / 60 / 60 / 24);
x.push(delayWeeks);
} else {
// The service hasnt been expanded into this region yet
// TODO: handle this better
x.push(-1);
}
});
trace["x"] = x;
if (x.length > 0) {
data.push(trace);
}
})
break
case 'Service':
regions.forEach(function (region) {
let regionLaunchDate = regionLaunchDates[region];
let trace = {
y: services,
name: region,
orientation: 'h',
marker: {
width: 1
},
type: 'bar'
};
let x = [];
services.forEach(function (service){
let serviceLaunchDate = serviceLaunchDates[service];
if (service in regionTimeline[region]) {
// We want the difference between the date the region or service was launched (whichever is greater)
// and the date the service was expanded into this region
let regionServiceLaunchDate = Math.max.apply(null, [regionLaunchDate, serviceLaunchDate]);
let regionServiceExpansionDate = regionTimeline[region][service]["date"];
let delayWeeks = Math.floor((regionServiceExpansionDate - regionServiceLaunchDate) / 1000 / 60 / 60 / 24);
x.push(delayWeeks);
} else {
// The service hasnt been expanded into this region yet
// TODO: handle this better
x.push(-1);
}
});
trace["x"] = x;
if (x.length > 0) {
data.push(trace);
}
});
break
}
let layout = {
title: {
text: "AWS Regional Service Expansion Delay"
},
legend: {
title: {
text: "Regions"
}
},
xaxis: {
title: {
text: "Delay (days)"
},
dtick: 365
},
showSendToCloud:false,
yaxis: {
categoryorder: "category descending"
}
};
Plotly.newPlot('graph', data, layout, {displaylogo: false});
}
document.addEventListener('DOMContentLoaded', function() {
loadTimeline();
})