Skip to content

Commit

Permalink
Broken
Browse files Browse the repository at this point in the history
  • Loading branch information
envex committed Feb 3, 2025
1 parent a648037 commit cdbfbd9
Show file tree
Hide file tree
Showing 11 changed files with 374 additions and 105 deletions.
1 change: 1 addition & 0 deletions packages/polaris-viz-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ export enum InternalChartType {
HorizontalBar = 'HorizontalBar',
Combo = 'Combo',
Line = 'Line',
Donut = 'Donut',
}

export enum Hue {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export function getColorVisionEventAttrs({type, index, watch = true}: Props) {
[`${COLOR_VISION_EVENT.dataAttribute}-watch`]: watch,
[`${COLOR_VISION_EVENT.dataAttribute}-type`]: type,
[`${COLOR_VISION_EVENT.dataAttribute}-index`]: index,
['data-tooltip-type']: 'blah',
};
}
1 change: 1 addition & 0 deletions packages/polaris-viz/src/components/Arc/Arc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export function Arc({
height={radius * 4}
width={radius * 4}
gradient={gradient}
index={index}
/>
</g>
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type {GradientStop} from '@shopify/polaris-viz-core';
import {Fragment} from 'react';

import {createCSSConicGradient} from '../../utilities';

Expand All @@ -16,18 +17,30 @@ export function ConicGradientWithStops({
width,
x = 0,
y = 0,
index,
}: ConicGradientWithStopsProps) {
const conicGradientValue = createCSSConicGradient(gradient);

return (
<foreignObject x={x} y={y} width={width} height={height}>
<div
style={{
width: `${width}px`,
height: `${height}px`,
backgroundImage: conicGradientValue,
}}
<Fragment>
<foreignObject x={x} y={y} width={width} height={height}>
<div
style={{
width: `${width}px`,
height: `${height}px`,
backgroundImage: conicGradientValue,
}}
/>
</foreignObject>
<rect
data-tooltip-type="donut"
data-tooltip-index={index}
width={width}
height={height}
x={x}
y={y}
fill="transparent"
/>
</foreignObject>
</Fragment>
);
}
13 changes: 13 additions & 0 deletions packages/polaris-viz/src/components/DonutChart/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
useChartContext,
THIN_ARC_CORNER_THICKNESS,
isInfinity,
InternalChartType,
DataType,
} from '@shopify/polaris-viz-core';
import type {
DataPoint,
Expand All @@ -17,6 +19,7 @@ import type {
Direction,
} from '@shopify/polaris-viz-core';

import {TooltipWrapperNext} from '../../components/TooltipWrapper/TooltipWrapperNext';
import {getAnimationDelayForItems} from '../../utilities/getAnimationDelayForItems';
import {getContainerAlignmentForLegend} from '../../utilities';
import type {ComparisonMetricProps} from '../ComparisonMetric';
Expand Down Expand Up @@ -84,6 +87,7 @@ export function Chart({
const chartId = useUniqueId('Donut');
const [activeIndex, setActiveIndex] = useState<number>(-1);
const selectedTheme = useTheme();
const [svgRef, setSvgRef] = useState<SVGSVGElement | null>(null);

const seriesCount = clamp({
amount: data.length,
Expand Down Expand Up @@ -208,6 +212,7 @@ export function Chart({
viewBox={`${minX} ${minY} ${viewBoxDimensions.width} ${viewBoxDimensions.height}`}
height={diameter}
width={diameter}
ref={setSvgRef}
>
{isLegendMounted && (
<g className={styles.DonutChart}>
Expand Down Expand Up @@ -300,6 +305,14 @@ export function Chart({
}
/>
)}
<TooltipWrapperNext
chartType={InternalChartType.Donut}
focusElementDataType={DataType.Point}
getMarkup={(index) => {
return <div>Tooltip {index}</div>;
}}
parentElement={svgRef}
/>
</div>
);
}
30 changes: 22 additions & 8 deletions packages/polaris-viz/src/components/LineChart/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {VisuallyHiddenRows} from '../VisuallyHiddenRows';
import {YAxis} from '../YAxis';
import {HorizontalGridLines} from '../HorizontalGridLines';
import {ChartElements} from '../ChartElements';
import {TooltipWrapperNext} from '../../components/TooltipWrapper/TooltipWrapperNext';

import {useLineChartTooltipContent} from './hooks/useLineChartTooltipContent';
import {PointsAndCrosshair} from './components';
Expand Down Expand Up @@ -242,6 +243,8 @@ export function Chart({

const halfXAxisLabelWidth = xAxisDetails.labelWidth / 2;

console.log({longestSeriesLength});

return (
<Fragment>
<ChartElements.Svg
Expand Down Expand Up @@ -304,6 +307,24 @@ export function Chart({
theme,
})}

{[...Array(longestSeriesLength).keys()].map((series, index) => {
return (
<rect
height={drawableHeight}
width={drawableWidth / longestSeriesLength}
x={
index * (drawableWidth / longestSeriesLength) -
drawableWidth / longestSeriesLength / 2
}
fill="rgba(255,0,0,0.2)"
data-tooltip-type="line"
data-tooltip-index={index}
data-tooltip-x={xScale(index)}
data-tooltip-y={yScale(index)}
/>
);
})}

{data.map((singleSeries, index) => {
if (singleSeries.metadata?.isVisuallyHidden === true) {
return null;
Expand Down Expand Up @@ -371,15 +392,11 @@ export function Chart({
</ChartElements.Svg>

{longestSeriesLength !== -1 && (
<TooltipWrapper
chartBounds={chartBounds}
<TooltipWrapperNext
chartType={InternalChartType.Line}
focusElementDataType={DataType.Point}
getMarkup={getTooltipMarkup}
data={data}
longestSeriesIndex={longestSeriesIndex}
id={tooltipId.current}
margin={ChartMargin}
onIndexChange={(index) => {
if (index != null && isPerformanceImpacted) {
moveCrosshair(index);
Expand All @@ -388,9 +405,6 @@ export function Chart({
}
}}
parentElement={svgRef}
usePortal
xScale={xScale}
yScale={yScale}
/>
)}

Expand Down
Loading

0 comments on commit cdbfbd9

Please sign in to comment.