Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/nivoPublic

Rendering the tooltip in a portal#2044

ilyabo started this conversation inIdeas
Discussion options

We have to render potentially large tooltips in a small chart displayed within a container which needs to useoverflow: auto to be scrollable. That leads to the tooltip being cut:

One common approach to prevent this is to use a portal. Unfortunately, Nivo doesn't provide portal support (unlike someother charting libraries). It would be really useful if it did so!

But here's my workaround for theLine chart with the slice mode enabled:

Posting it here so maybe somebody finds it useful too.

const MARGIN = {top: 40, right: 20, bottom: 30, left: 50};const width = 400;const height = 200;const chartWidth = width - MARGIN.left - MARGIN.right;const containerRef = useRef<HTMLDivElement>(null);return (  <div ref={containerRef}>    <Line      width={width}      height={height}      data={data}      margin={MARGIN}      …      enableCrosshair={true}      enableSlices="x"      animate={false}      isInteractive={true}      useMesh={true}      sliceTooltip={({slice}) => {        const containerBounds = containerRef.current?.getBoundingClientRect();        if (!containerBounds) return null;        return createPortal(          <div            style={{              position: 'absolute',              left: containerBounds.left + slice.x + MARGIN.left,              top: containerBounds.top + slice.y + MARGIN.top,              pointerEvents: 'none',            }}          >            <div              style={{                display: 'inline-block',                marginLeft: slice.x > chartWidth / 2 ? '-100%' : '0',              }}>              <div style={{                fontSize: 10,                background: '#262D40',                padding: '9px 12px',                borderRadius: 10,                margin: 10              }}>                {slice.points.map(point => (                  <div                    key={point.id}                    style={{                      color: point.serieColor,                      padding: '3px 0',                    }}                  >                    <strong>{point.serieId}</strong> [{point.data.yFormatted}]                  </div>                ))}              </div>            </div>          </div>,          document.body        );      }}    />  </div>);
You must be logged in to vote

Replies: 1 comment

Comment options

I also think it would make sense to use a portal (even as a default), but the positioning would need to be handled differently.

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Ideas
2 participants
@ilyabo@plouc

[8]ページ先頭

©2009-2025 Movatter.jp