Skip to content

Commit 67dceba

Browse files
committed
Tax dashboard - interactive hover
1 parent ab45e83 commit 67dceba

File tree

1 file changed

+69
-59
lines changed

1 file changed

+69
-59
lines changed

data-story/tax-explorer.html

Lines changed: 69 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ <h3>Summary Statistics</h3>
301301
}
302302

303303
return tax;
304-
}
304+
}
305305

306306

307307
// Calculate National Insurance
@@ -395,9 +395,63 @@ <h3>Summary Statistics</h3>
395395
width: 700,
396396
height: 400,
397397
data: { values: data },
398+
encoding: {
399+
x: {
400+
field: "income",
401+
type: "quantitative",
402+
title: "Personal income (£)",
403+
axis: {
404+
format: "$,d",
405+
labelAngle: 0,
406+
titleFontSize: 13
407+
}
408+
}
409+
},
398410
layer: [
399411
{
400-
data: { values: [{ income: summaryIncome }] },
412+
encoding: {
413+
y: {
414+
field: "marginalRate",
415+
type: "quantitative",
416+
title: "Rate (%)",
417+
scale: { domain: [0, 1] },
418+
axis: { format: "%" }
419+
},
420+
color: {
421+
value: "#ff6b6b"
422+
}
423+
},
424+
layer: [
425+
{
426+
mark: { type: "line", strokeWidth: 2, color: "#ff6b6b" },
427+
},
428+
{
429+
mark: { type: "point" },
430+
transform: [{filter: { param: "hover", empty: false }}]
431+
}
432+
]
433+
},
434+
{
435+
encoding: {
436+
y: {
437+
field: "effectiveRate",
438+
type: "quantitative"
439+
},
440+
color: {
441+
value: "#4CAF50"
442+
}
443+
},
444+
layer: [
445+
{
446+
mark: { type: "line", strokeWidth: 2, color: "#4CAF50", strokeDash: [5, 5] },
447+
},
448+
{
449+
mark: { type: "point" },
450+
transform: [{filter: { param: "hover", empty: false }}]
451+
}
452+
]
453+
},
454+
{
401455
mark: {
402456
type: "rule",
403457
strokeWidth: 2,
@@ -406,67 +460,23 @@ <h3>Summary Statistics</h3>
406460
opacity: 0.7
407461
},
408462
encoding: {
409-
x: {
410-
field: "income",
411-
type: "quantitative",
412-
// scale: {
413-
// domain: [0, Math.max(...data.map(d => d.income))]
414-
// }
415-
},
416-
tooltip: [
417-
{ field: "income", type: "quantitative", title: "Your Income", format: "$.0f" }
418-
]
419-
}
420-
},
421-
{
422-
mark: { type: "line", strokeWidth: 2, color: "#ff6b6b" },
423-
encoding: {
424-
x: {
425-
field: "income",
426-
type: "quantitative",
427-
title: "Personal income (£)",
428-
axis: {
429-
format: "$,d",
430-
labelAngle: 0,
431-
titleFontSize: 13
432-
}
433-
},
434-
y: {
435-
field: "marginalRate",
436-
type: "quantitative",
437-
title: "Rate (%)",
438-
scale: { domain: [0, 1] },
439-
axis: { format: "%" }
440-
},
441-
color: {
442-
value: "#ff6b6b"
463+
opacity: {
464+
condition: { value: 0.3, param: "hover", empty: false },
465+
value: 0
443466
},
444467
tooltip: [
445-
{ field: "income", type: "quantitative", title: "Income", format: "$,.0f" },
446-
{ field: "marginalRate", type: "quantitative", title: "Marginal Rate", format: ".1%" }
447-
]
448-
}
449-
},
450-
{
451-
mark: { type: "line", strokeWidth: 2, color: "#4CAF50", strokeDash: [5, 5] },
452-
encoding: {
453-
x: {
454-
field: "income",
455-
type: "quantitative"
456-
},
457-
y: {
458-
field: "effectiveRate",
459-
type: "quantitative",
460-
axis: { format: "%" }
461-
},
462-
color: {
463-
value: "#4CAF50"
464-
},
465-
tooltip: [
466-
{ field: "income", type: "quantitative", title: "Income", format: "$,.0f" },
468+
{ field: "income", type: "quantitative", title: "Your Income", format: "$,.0f" },
469+
{ field: "marginalRate", type: "quantitative", title: "Marginal Rate", format: ".1%" },
467470
{ field: "effectiveRate", type: "quantitative", title: "Effective Rate", format: ".1%" }
468471
]
469-
}
472+
},
473+
params: [
474+
{
475+
name: "hover",
476+
value: [{ x: summaryIncome }],
477+
select: { type: "point", fields: ["income"], on: "pointerover", clear: "dblclick", nearest: true }
478+
}
479+
]
470480
},
471481
{
472482
data: { values: labelData },

0 commit comments

Comments
 (0)