Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

add tiny invisible width to end of numeric charts for tooltip (#7337)

Shahmir Varqha194e35e9ac63
diff --git a/frontend/src/components/data-table/__tests__/__snapshots__/chart-spec-model.test.ts.snap b/frontend/src/components/data-table/__tests__/__snapshots__/chart-spec-model.test.ts.snap
index 6292bf8edf..188db698b1 100644
--- a/frontend/src/components/data-table/__tests__/__snapshots__/chart-spec-model.test.ts.snap
+++ b/frontend/src/components/data-table/__tests__/__snapshots__/chart-spec-model.test.ts.snap
@@ -219,7 +219,7 @@ exports[`ColumnChartSpecModel > should expect bin values to be used for number a
"type": "quantitative",
},
"x2": {
- "field": "bin_end",
+ "field": "bin_end_extended",
},
"y": {
"aggregate": "max",
@@ -236,7 +236,6 @@ exports[`ColumnChartSpecModel > should expect bin values to be used for number a
"name": "hover",
"select": {
"clear": "mouseout",
- "nearest": true,
"on": "mouseover",
"type": "point",
},
@@ -247,6 +246,10 @@ exports[`ColumnChartSpecModel > should expect bin values to be used for number a
"as": "bin_range",
"calculate": "format(datum.bin_start, '.2f') + ' - ' + format(datum.bin_end, '.2f')",
},
+ {
+ "as": "bin_end_extended",
+ "calculate": "datum.bin_end + 1",
+ },
],
},
],
diff --git a/frontend/src/components/data-table/column-summary/chart-spec-model.tsx b/frontend/src/components/data-table/column-summary/chart-spec-model.tsx
index 507c7c79a6..c64ec00bc8 100644
--- a/frontend/src/components/data-table/column-summary/chart-spec-model.tsx
+++ b/frontend/src/components/data-table/column-summary/chart-spec-model.tsx
@@ -23,6 +23,7 @@ import { calculateBinStep, getPartialTimeTooltip } from "./utils";
// We rely on vega's built-in binning to determine bar widths.
const MAX_BAR_HEIGHT = 20; // px
+const BIN_END_EXTENSION_FACTOR = 0.1;
// If we are concatenating charts, we need to specify each chart's height and width.
const CONCAT_CHART_HEIGHT = 30;
@@ -358,7 +359,6 @@ export class ColumnChartSpecModel<T> {
type: "point",
on: "mouseover",
clear: "mouseout",
- nearest: true, // Nearest avoids flickering when hovering over bars, but it's not perfect
},
},
],
@@ -385,7 +385,7 @@ export class ColumnChartSpecModel<T> {
},
},
x2: {
- field: "bin_end",
+ field: "bin_end_extended",
},
y: {
aggregate: "max",
@@ -411,6 +411,11 @@ export class ColumnChartSpecModel<T> {
calculate: `format(datum.bin_start, '${format}') + ' - ' + format(datum.bin_end, '${format}')`,
as: "bin_range",
},
+ {
+ // Extend bin_end slightly to cover gaps between bars and prevent flickering
+ calculate: `datum.bin_end + ${binStep * BIN_END_EXTENSION_FACTOR}`,
+ as: "bin_end_extended",
+ },
],
},
],