forked from lancedb/lance-benchmark-results
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
221 lines (182 loc) · 7.29 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Timeseries plot for lanceDB benchmarks </title>
<script src="https://cdn.jsdelivr.net/npm/d3@7"></script>
<link rel="stylesheet" href="chart-style.css">
</head>
<body>
<div class="main-container">
<div id="chart-area">
<div id="chart"></div>
<div id="legend">
</div>
</div>
<script>
// Load the data
d3.json("rust/results.json").then(function(data) {
// Process the data
data.forEach(function(d) {
d.datetime = new Date(d.datetime); // Convert datetime to Date object
d.mean_duration_ms = d.mean_duration_ns / 1000000; // Convert to milliseconds
});
// Set the dimensions and margins of the graph
const margin = {top: 100, right: 150, bottom: 250, left: 200},
width = 1600 - margin.left - margin.right,
height = 1000 - margin.top - margin.bottom;
// Append the svg object to the body of the page
const svg = d3.select("#chart")
.append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", `translate(${margin.left},${margin.top})`);
// Add X axis
const x = d3.scaleTime()
.domain(d3.extent(data, d => d.datetime)) // Assuming data is your dataset and datetime is your date field
.range([0, width]);
// svg.append("g")
// .attr("transform", `translate(0,${height})`)
// .call(d3.axisBottom(x));
// Add X axis label
svg.append("text")
.attr("transform",
"translate(" + (width/2) + " ," +
(height + margin.top + 20) + ")") // Position below the x-axis
.style("text-anchor", "middle")
.style("font-size", "24px")
.text("Date");
const xAxis = d3.axisBottom(x)
.tickFormat(d3.timeFormat("%Y-%m-%d"));
d3.selectAll(".axis text")
.style("font-size", "100px");
svg.append("g")
.attr("class", "x-axis") // It's good practice to add a class for styling and future selections
.attr("transform", `translate(0,${height})`) // Moves the x-axis to the bottom of the chart area
.call(xAxis)
.selectAll("text")
.style("text-anchor", "end")
.style("font-size", "18px")
.attr("dx", "-.8em")
.attr("dy", ".15em")
.attr("transform", "rotate(-65)");
// Add Y axis
svg.append("text")
.attr("transform", "rotate(-90)") // Rotate to align along the y-axis
.attr("y", 10 - margin.left) // Position to the left of the y-axis
.attr("x",0 - (height / 2))
.attr("dy", "1em") // Adjust distance from the axis
.style("text-anchor", "middle")
.style("font-size", "24px")
.text("Avg. Duration (ms)");
svg.append("text") // Append a text element to your SVG container
.attr("class", "chart-title") // Optional: for styling via CSS
.attr("x", width / 2) // Position the title in the center of the chart
.attr("y", 0 - (margin.top / 2)) // Position the title above the chart, adjust as needed
.attr("text-anchor", "middle") // Ensure the text is centered
.style("font-size", "30px") // Set the font size, adjust as needed
.text("LanceDB microbenchmarks"); // The text of your title
const y = d3.scaleLinear()
.domain([0, d3.max(data, d => d.mean_duration_ms)])
.range([height, 0]);
svg.append("g")
.style("font-size", "18px")
.call(d3.axisLeft(y));
// Group the data
const sumstat = d3.group(data, d => d.name);
const color = d3.scaleOrdinal()
.domain(Array.from(sumstat.keys())) // Extracting the unique names from sumstat
.range(d3.schemeTableau10);
// Draw the lines
sumstat.forEach(function(value, key) {
svg.append("path")
.datum(value)
.attr("fill", "none")
.attr("stroke", color(key))
.attr("stroke-width", 1.5)
.attr("d", d3.line()
.x(function(d) { return x(d.datetime); })
.y(function(d) { return y(d.mean_duration_ms); })
);
});
// Tooltip
const tooltip = d3.select("#chart").append("div")
.attr("class", "tooltip")
.style("opacity", 0);
const options = { year: 'numeric', month: 'long', day: 'numeric' };
svg.selectAll(".dot")
.data(data)
.enter()
.append("circle")
.attr("class", "dot")
.attr("data-name", d => d.name)
.attr("cx", function(d) { return x(d.datetime); })
.attr("cy", function(d) { return y(d.mean_duration_ms); })
.attr("r", 5)
.attr("fill", function(d) { return color(d.name); })
.on("mouseover", function(event, d) {
tooltip.transition().duration(200).style("opacity", .9);
tooltip.html(`Benchmark: ${d.name}<br>Date: ${d.datetime.toLocaleString('en-US', options)}<br>mean_duration_ms: ${d.mean_duration_ms.toFixed(2)} ms`)
.style("left", (event.pageX + 20) + "px")
.style("top", (event.pageY - 20) + "px");
})
.on("mouseout", function(d) {
tooltip.transition().duration(500).style("opacity", 0);
});
// Legend
const legendContainer = d3.select("#legend");
// Append the legend title
legendContainer.append("div")
.attr("class", "legend-title")
.style("font-size", "26px")
.text("Benchmarks");
// Proceed to append scrollable legend items into .legend-items
const legendItemsContainer = legendContainer.append("div")
.attr("class", "legend-items");
sumstat.forEach((values, name) => {
// Create a container for each legend item
const legendItem = legendItemsContainer.append("div")
.attr("class", "legend-item")
.style("display", "flex")
.style("font-size", "20px")
.style("align-items", "center")
.style("margin-bottom", "5px")
.style("cursor", "pointer")
.on("click", function(event) {
// Toggle highlighting corresponding data points
toggleHighlighting(name);
});
// Create a colored square for each legend item
legendItem.append("div")
.style("width", "20px")
.style("height", "20px")
.style("margin-right", "10px")
.style("background-color", color(name));
// Add the name of the group to the legend item
legendItem.append("span")
.text(name);
});
// Function to toggle highlighting of data points
let lastClicked = null; // Keep track of the last clicked legend item
function toggleHighlighting(selectedName) {
const dots = d3.select("#chart").selectAll("circle"); // Assuming your data points are circles
if (lastClicked === selectedName) {
// If clicking the same item, reset all
dots.style("opacity", 1).attr("r", 5); // Reset to default styles
lastClicked = null; // Reset tracking variable
} else {
// Dim all dots
dots.style("opacity", 0.2).attr("r", 5);
// Highlight the dots that match the selected legend item
dots.filter(d => d.name === selectedName)
.style("opacity", 1)
.attr("r", 8); // Optionally increase the size for emphasis
lastClicked = selectedName; // Update tracking variable
}
}
});
</script>
</body>
</html>