Skip to content

Commit 2bf0994

Browse files
committed
Fix observable chart tooltips
1 parent 5cc0f12 commit 2bf0994

3 files changed

Lines changed: 25 additions & 2 deletions

File tree

src/components/charts/PlotContainer.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as React from 'react'
22
import * as Plot from '@observablehq/plot'
33

4+
export const observablePlotClassName = 'tanstack-observable-plot'
5+
46
interface PlotContainerProps {
57
/** Build Plot options given the measured container width. */
68
options: (width: number) => Parameters<typeof Plot.plot>[0]
@@ -37,7 +39,12 @@ export function PlotContainer({
3739
if (width === 0) return
3840

3941
currentPlot = Plot.plot({ ...options(width), width, height })
40-
currentPlot.style.overflow = 'visible'
42+
const svg =
43+
currentPlot instanceof SVGSVGElement
44+
? currentPlot
45+
: currentPlot.querySelector('svg')
46+
svg?.classList.add(observablePlotClassName)
47+
if (svg) svg.style.overflow = 'visible'
4148
container.appendChild(currentPlot)
4249
setReady(true)
4350
}

src/components/npm-stats/NPMStatsChart.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from '@radix-ui/react-dropdown-menu'
1313
import { twMerge } from 'tailwind-merge'
1414
import { Tooltip } from '~/components/Tooltip'
15+
import { observablePlotClassName } from '~/components/charts/PlotContainer'
1516
import {
1617
binningOptionsByType,
1718
getHistoryStartDate,
@@ -4256,14 +4257,15 @@ export function NPMStatsChart({
42564257
plotRef={plotRef}
42574258
showLegend={showLegend}
42584259
options={{
4260+
className: observablePlotClassName,
42594261
marginLeft,
42604262
marginRight,
42614263
marginBottom: isLatestVerticalBar
42624264
? latestVerticalXAxisLayout.marginBottom
42634265
: 70,
42644266
width,
42654267
height,
4266-
clip: hasTimelineZoom ? true : undefined,
4268+
style: { overflow: 'visible' },
42674269
marks: (
42684270
[
42694271
isHorizontalBar
@@ -4289,6 +4291,7 @@ export function NPMStatsChart({
42894291
strokeDasharray: '2 4',
42904292
strokeOpacity: 0.8,
42914293
curve: 'monotone-x',
4294+
clip: hasTimelineZoom ? true : undefined,
42924295
},
42934296
)
42944297
: undefined,
@@ -4300,6 +4303,7 @@ export function NPMStatsChart({
43004303
stroke: getStrokeColor,
43014304
strokeWidth: 2,
43024305
curve: 'monotone-x',
4306+
clip: hasTimelineZoom ? true : undefined,
43034307
},
43044308
)
43054309
: undefined,
@@ -4329,6 +4333,7 @@ export function NPMStatsChart({
43294333
z: 'seriesName',
43304334
fill: getSeriesGradientFill,
43314335
curve: 'monotone-x',
4336+
clip: hasTimelineZoom ? true : undefined,
43324337
})
43334338
: undefined,
43344339
viewMode === 'history' && chartType === 'stacked-stream'
@@ -4339,6 +4344,7 @@ export function NPMStatsChart({
43394344
z: 'seriesName',
43404345
fill: getSeriesGradientFill,
43414346
curve: 'monotone-x',
4347+
clip: hasTimelineZoom ? true : undefined,
43424348
})
43434349
: undefined,
43444350
viewMode === 'history' &&
@@ -4353,6 +4359,7 @@ export function NPMStatsChart({
43534359
strokeWidth: 1.4,
43544360
strokeOpacity: 0.95,
43554361
curve: 'monotone-x',
4362+
clip: hasTimelineZoom ? true : undefined,
43564363
})
43574364
: undefined,
43584365
viewMode === 'history' &&

src/styles/app.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ html.theme-switching *::after {
152152
}
153153
}
154154

155+
.tanstack-observable-plot {
156+
--plot-background: var(--color-white);
157+
overflow: visible;
158+
}
159+
160+
html.dark .tanstack-observable-plot {
161+
--plot-background: var(--color-gray-800);
162+
}
163+
155164
button {
156165
@apply cursor-pointer;
157166
}

0 commit comments

Comments
 (0)