Skip to content

Commit 84fd963

Browse files
feat: add tooltip support for exact X & Y values on hover (#31)
* feat: add tooltip support for exact X & Y values on hover * update package-lock.json * fix lint * `npm install` * fix unit * fix unit * ttfb * deduplicate * unify * show tips for both lines * label * label --------- Co-authored-by: Julian Gruber <[email protected]>
1 parent f446abb commit 84fd963

File tree

3 files changed

+92
-8
lines changed

3 files changed

+92
-8
lines changed

src/components/histogram.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ export function Histogram(events, { width, title, thresholds }) {
4040
y: 'count',
4141
x: 'type',
4242
fill: 'type',
43+
tip: {
44+
format: {
45+
threshold: (v) => `Range: ${v}%`,
46+
count: (v) => `Count: ${v} miners`,
47+
type: true,
48+
},
49+
},
4350
}),
4451
],
4552
y: { grid: true },

src/components/line-graph.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ export function LineGraph(
2323
})),
2424
]
2525

26+
// Format functions for tooltip values
27+
const formatDate = (d) =>
28+
new Date(d).toLocaleDateString('en-US', {
29+
year: 'numeric',
30+
month: 'short',
31+
day: 'numeric',
32+
})
33+
const formatPercent = (v) => (v ? `${v.toFixed(2)}%` : 'N/A')
34+
2635
return Plot.plot({
2736
title,
2837
width,
@@ -42,12 +51,26 @@ export function LineGraph(
4251
y: 'success_rate',
4352
stroke: 'type',
4453
curve: 'linear',
54+
tip: {
55+
format: {
56+
x: formatDate,
57+
y: formatPercent,
58+
type: true,
59+
},
60+
},
4561
}),
4662
Plot.lineY(combinedData, {
4763
x: 'day',
4864
y: 'success_rate_http',
4965
stroke: 'type',
5066
curve: 'linear',
67+
tip: {
68+
format: {
69+
x: formatDate,
70+
y: formatPercent,
71+
type: true,
72+
},
73+
},
5174
}),
5275
],
5376
})

src/index.md

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,43 @@ const percentiles = Object.entries(SparkMinerRsrSummaries).flatMap(
155155
${Plot.plot({
156156
title: '# of Filecoin SPs with a non-zero Spark Retrieval Success Rate',
157157
x: { label: null },
158-
y: { grid: true, label: null },
158+
y: { grid: true, label: '# Non-Zero SPs' },
159159
color: { legend: true },
160160
marks: [
161161
Plot.ruleY([0]),
162-
Plot.line(nonZeroMinersOverTime, {
162+
Plot.lineY(nonZeroMinersOverTime, {
163163
x: 'day',
164164
y: 'count_succes_rate',
165165
stroke: "type",
166166
curve: 'catmull-rom',
167+
tip: {
168+
format: {
169+
x: d => new Date(d).toLocaleDateString('en-US', {
170+
year: 'numeric',
171+
month: 'short',
172+
day: 'numeric'
173+
}),
174+
y: v => `${v} SPs`,
175+
type: true
176+
}
177+
}
167178
}),
168-
Plot.line(nonZeroMinersOverTime, {
179+
Plot.lineY(nonZeroMinersOverTime, {
169180
x: 'day',
170181
y: 'count_succes_rate_http',
171182
stroke: "type",
172183
curve: 'catmull-rom',
184+
tip: {
185+
format: {
186+
x: d => new Date(d).toLocaleDateString('en-US', {
187+
year: 'numeric',
188+
month: 'short',
189+
day: 'numeric'
190+
}),
191+
y: v => v ? `${v} SPs` : 'N/A',
192+
type: true
193+
}
194+
}
173195
})
174196
]
175197
})}
@@ -178,7 +200,7 @@ const percentiles = Object.entries(SparkMinerRsrSummaries).flatMap(
178200
${Plot.plot({
179201
title: '# of Filecoin SPs with Spark Retrieval Success Rate above x%',
180202
x: { label: null },
181-
y: { grid: true, label: null },
203+
y: { grid: true, label: '# SPs above x%' },
182204
color: {
183205
scheme: "Paired",
184206
legend: "swatches"
@@ -189,7 +211,18 @@ const percentiles = Object.entries(SparkMinerRsrSummaries).flatMap(
189211
x: 'day',
190212
y: 'count_succes_rate',
191213
stroke: 'label',
192-
curve: 'catmull-rom'
214+
curve: 'catmull-rom',
215+
tip: {
216+
format: {
217+
x: d => new Date(d).toLocaleDateString('en-US', {
218+
year: 'numeric',
219+
month: 'short',
220+
day: 'numeric'
221+
}),
222+
y: v => `${v} SPs`,
223+
label: true
224+
}
225+
}
193226
})
194227
]
195228
})}
@@ -275,7 +308,7 @@ const tidy = clone(SparkRetrievalResultCodes).flatMap(({ day, rates }) => {
275308
color: {
276309
scheme: "Accent",
277310
legend: "swatches",
278-
label: "Codes"
311+
label: "code"
279312
},
280313
marks: [
281314
Plot.rectY(tidy, {
@@ -284,7 +317,18 @@ const tidy = clone(SparkRetrievalResultCodes).flatMap(({ day, rates }) => {
284317
fill: "code",
285318
offset: "normalize",
286319
sort: {color: null, x: "-y" },
287-
interval: 'day'
320+
interval: 'day',
321+
tip: {
322+
format: {
323+
x: d => new Date(d).toLocaleDateString('en-US', {
324+
year: 'numeric',
325+
month: 'short',
326+
day: 'numeric'
327+
}),
328+
y: v => v.toFixed(2),
329+
code: true
330+
}
331+
}
288332
})
289333
]
290334
})}
@@ -297,12 +341,22 @@ const tidy = clone(SparkRetrievalResultCodes).flatMap(({ day, rates }) => {
297341
${Plot.plot({
298342
title: 'Time to First Byte (ms)',
299343
x: { type: 'utc', ticks: 'month' },
300-
y: { grid: true, zero: true},
344+
y: { grid: true, zero: true, label: 'ttfb (ms)' },
301345
marks: [
302346
Plot.lineY(SparkRetrievalTimes, {
303347
x: 'day',
304348
y: 'ttfb_ms',
305349
stroke: "#FFBD3F",
350+
tip: {
351+
format: {
352+
x: d => new Date(d).toLocaleDateString('en-US', {
353+
year: 'numeric',
354+
month: 'short',
355+
day: 'numeric'
356+
}),
357+
y: v => v.toFixed(0)
358+
}
359+
}
306360
})
307361
]
308362
})}

0 commit comments

Comments
 (0)