Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
susiekims committed Dec 4, 2024
1 parent b38b128 commit 34b1e06
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ function TooltipWrapperRaw(props: BaseProps) {
position: DEFAULT_TOOLTIP_POSITION,
});

const {containerBounds: bounds} = useChartContext();

const activeIndexRef = useRef<number | null>(null);
const touchStartTimer = useRef<number>(0);
const isLongTouch = useRef(false);
Expand Down Expand Up @@ -94,16 +96,16 @@ function TooltipWrapperRaw(props: BaseProps) {
}) => {
const containerBounds = {
x: parentElement?.getBoundingClientRect().x ?? 0,
y:
Number(parentElement?.getBoundingClientRect().y ?? 0) +
Number(scrollContainer?.scrollTop ?? 0),
y: parentElement?.getBoundingClientRect().y ?? 0,
// + Number(scrollContainer?.scrollTop ?? 0),
width: parentElement?.getBoundingClientRect().width ?? 0,
height: parentElement?.getBoundingClientRect().height ?? 0,
};
switch (chartType) {
case InternalChartType.Line:
return getLineChartTooltipPosition({
chartBounds,
containerBounds,
data,
event,
eventType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type AlteredPosition = (
export function getAlteredLineChartPosition(
props: AlteredPositionProps,
): AlteredPositionReturn {
const {currentX, currentY, chartBounds, scrollContainer} = props;
const {currentX, currentY, containerBounds, scrollContainer} = props;

let x = currentX;
let y = currentY;
Expand All @@ -28,7 +28,7 @@ export function getAlteredLineChartPosition(
//

if (props.isPerformanceImpacted) {
y = chartBounds.y - (scrollContainer?.scrollTop ?? 0);
y = containerBounds.y - (scrollContainer?.scrollTop ?? 0);
}

//
Expand All @@ -41,6 +41,7 @@ export function getAlteredLineChartPosition(

if (right.wasOutsideBounds) {
const left = getLeftPosition(x, props);
console.log('left', left);

x = left.value;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {clamp} from '@shopify/polaris-viz-core';
import {BoundingRect, clamp} from '@shopify/polaris-viz-core';
import type {ScaleLinear} from 'd3-scale';

import type {TooltipPositionParams} from '../types';
Expand All @@ -7,10 +7,12 @@ import {TOOLTIP_POSITION_DEFAULT_RETURN} from '../constants';
import {getXYFromEventType, eventPointNative} from './eventPoint';

interface Props extends Omit<TooltipPositionParams, 'xScale'> {
containerBounds: BoundingRect;
xScale: ScaleLinear<number, number>;
}

export function getLineChartTooltipPosition({
containerBounds,
chartBounds,
data,
event,
Expand Down Expand Up @@ -53,8 +55,8 @@ export function getLineChartTooltipPosition({
const x = xScale?.(activeIndex) ?? 0;

return {
x: x + chartBounds.x,
y: chartBounds.y,
x: x + containerBounds.x,
y: containerBounds.y,
activeIndex,
};
}
Expand Down

0 comments on commit 34b1e06

Please sign in to comment.