-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlognps.html
141 lines (118 loc) · 3.59 KB
/
lognps.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
<!DOCTYPE html>
<style>
svg {
top: 10px;
left: 10px;
}
</style>
<svg width="960" height="270"></svg>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
const svg = d3.select("svg"),
margin = {top: 60, right: 60, bottom: 50, left: 70},
width = +svg.attr("width") - margin.left - margin.right,
height = +svg.attr("height") - margin.top - margin.bottom,
g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
const colors = {
nps: 'blue',
server: 'red',
mobile: 'green',
};
const xScale = d3.scaleTime().range([0, width]),
yScale = d3.scaleLinear().range([height, 0]),
xAxis = d3.axisBottom().scale(xScale).ticks(d3.timeSecond, 5).tickFormat(d3.timeFormat('%Ss')),
yAxis = d3.axisLeft().scale(yScale),
colorScale = (d) => colors[d],
y = (d) => d.y,
x = (d) => new Date(d.x),
color = (d) => d[0].from;
g.append('circle')
.attr('cx', -margin.left)
.attr('r', 1)
.attr('cy', -margin.top)
.attr('fill', 'black');
g.append('text')
.attr('transform', `translate(${width/2}, ${-margin.top/2})`)
.style('text-anchor', 'middle')
.text('Species Mapper Performance on Phone AR');
// text label for the x axis
g.append("text")
.attr("transform",
"translate(" + (width/2) + " ," +
(height + margin.bottom) + ")")
.style("text-anchor", "middle")
.text("Time");
// text label for the y axis
g.append("text")
.attr("transform", "rotate(-90)")
.attr("y", 0 - margin.left)
.attr("x",0 - (height / 2))
.attr("dy", "1em")
.style("text-anchor", "middle")
.text("Render Time");
g.append('circle')
.attr('cx', width+margin.right)
.attr('r', 1)
.attr('cy', height+margin.bottom)
.attr('fill', 'black');
const theline = g.append('line');
const start = Date.now();
fetch('/js/nps.json').then((res) => res.json()).then((dataset) => render(dataset));
function render(dataset) {
let data = Object.values(dataset.data.entries).map((d) => {
const y = d.from === 'mobile' ? d.ms
: d.from === 'browser' ? d.cpu
: d.from === 'server' ? d.cpu
: null;
return { y, x: d.now, from: d.from };
}).filter((d) => {
return x(d).getTime() > 1534360860000 + 12*1000;
}).filter((d) => {
return x(d).getTime() < 1534360860000 + 12*1000 + 35*1000;
});
xScale.domain(d3.extent(data, x));
yScale.domain(d3.extent(data, y));
data = data.map((d) => {
return { y: d.y, from: d.from, x: d.x - xScale.domain()[0].getTime() };
});
xScale.domain(d3.extent(data, x));
const split = { server: [], mobile: [], browser: [] };
for (i=0; i<data.length; ++i) {
const d = data[i];
split[d.from].push(d);
}
Object.values(split).forEach((data) => data.sort((a, b) => x(a) - x(b)));
//delete split.mobile;
delete split.server;
delete split.browser;
const line = d3.line()
.x((d) => xScale(x(d)))
.y((d) => yScale(y(d)));
g.append('g')
.attr('transform', `translate(0, ${height})`)
.call(xAxis);
g.append('g')
.call(yAxis);
g.append('g')
.selectAll('path')
.data(Object.values(split))
.enter()
.append('path')
.attr('fill', 'none')
.attr('stroke', (d) => colorScale(color(d)))
.attr('d', (data) => line(data));
rerender(0);
}
function rerender(timestamp) {
requestAnimationFrame(() => {
rerender(Date.now() - start);
});
const scale = d3.scaleLinear().domain([0, 35*1000]).range([0, width]);
theline
.attr('x1', scale(timestamp))
.attr('x2', scale(timestamp))
.attr('y1', yScale.range()[0])
.attr('y2', yScale.range()[1])
.attr('stroke', 'black');
}
</script>