-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
437 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
packages/polaris-viz/src/components/LineChart/components/MissingDataArea/MissingDataArea.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import {Fragment, memo, useRef} from 'react'; | ||
import type {LineChartSlotProps} from 'types'; | ||
import type {DataSeries} from '@shopify/polaris-viz-core'; | ||
import {uniqueId, useTheme} from '@shopify/polaris-viz-core'; | ||
|
||
import {useIndexForLabels} from '../../../../hooks/useIndexForLabels'; | ||
|
||
import {Pill} from './components/'; | ||
|
||
export interface Props extends LineChartSlotProps { | ||
data: DataSeries[]; | ||
missingData: any; | ||
} | ||
|
||
function MissingDataAreaRaw({ | ||
data, | ||
drawableHeight, | ||
missingData, | ||
xScale, | ||
}: Props) { | ||
const selectedTheme = useTheme(); | ||
const patternID = useRef(uniqueId('missingDataPattern')); | ||
const indexForLabels = useIndexForLabels(data); | ||
|
||
let fromIndex = -1; | ||
let toIndex = -1; | ||
|
||
data[indexForLabels].data.forEach(({key}, index) => { | ||
if (key === missingData.to) { | ||
toIndex = index; | ||
} | ||
|
||
if (key === missingData.from) { | ||
fromIndex = index; | ||
} | ||
}); | ||
|
||
const width = xScale(toIndex - fromIndex); | ||
|
||
const xPosition = xScale(fromIndex); | ||
|
||
return ( | ||
<Fragment> | ||
<defs> | ||
<pattern | ||
id={patternID.current} | ||
patternUnits="userSpaceOnUse" | ||
width="12" | ||
height="12" | ||
patternTransform="rotate(135)" | ||
> | ||
<line | ||
x1="0" | ||
y="0" | ||
x2="0" | ||
y2="12" | ||
stroke={selectedTheme.missingData.lineColor} | ||
strokeWidth="12" | ||
opacity="0.2" | ||
/> | ||
</pattern> | ||
</defs> | ||
|
||
<line | ||
x1={xPosition} | ||
x2={xPosition} | ||
y1="0" | ||
y2={drawableHeight} | ||
stroke={selectedTheme.missingData.lineColor} | ||
strokeWidth="1" | ||
strokeDasharray="4 4" | ||
/> | ||
|
||
<line | ||
x1={xPosition + width} | ||
x2={xPosition + width} | ||
y1="0" | ||
y2={drawableHeight} | ||
stroke={selectedTheme.missingData.lineColor} | ||
strokeWidth="1" | ||
strokeDasharray="4 4" | ||
/> | ||
|
||
<rect | ||
x={xPosition} | ||
y={0} | ||
height={drawableHeight} | ||
width={width} | ||
fill={`url(#${patternID.current})`} | ||
/> | ||
|
||
<Pill | ||
containerWidth={width} | ||
description={missingData.description} | ||
label={missingData.label} | ||
x={xPosition} | ||
/> | ||
</Fragment> | ||
); | ||
} | ||
|
||
export const MissingDataArea = memo(MissingDataAreaRaw); |
18 changes: 18 additions & 0 deletions
18
...ineChart/components/MissingDataArea/components/DescriptionPopover/DescriptionPopover.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.Wrapper { | ||
pointerevents: 'none'; | ||
overflow: 'visible'; | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
} | ||
|
||
.Container { | ||
padding: 8px; | ||
backdrop-filter: blur(5px); | ||
border-radius: 5px; | ||
box-shadow: 0 0 2px rgba(0, 0, 0, 0.2), 0 2px 10px rgba(0, 0, 0, 0.1); | ||
max-width: 200px; | ||
pointerevents: auto; | ||
width: fit-content; | ||
line-height: 16px; | ||
} |
53 changes: 53 additions & 0 deletions
53
...LineChart/components/MissingDataArea/components/DescriptionPopover/DescriptionPopover.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import {createPortal} from 'react-dom'; | ||
import {FONT_SIZE, useChartContext} from '@shopify/polaris-viz-core'; | ||
|
||
import {useHideTooltipWhenMounted} from '../../../../../../hooks/useHideTooltipWhenMounted'; | ||
import {getChartId} from '../../../../../../utilities/getChartId'; | ||
|
||
import styles from './DescriptionPopover.scss'; | ||
|
||
export interface DescriptionPopoverProps { | ||
description: string; | ||
label: string; | ||
onMouseLeave: () => void; | ||
x: number; | ||
y: number; | ||
yOffset: number; | ||
} | ||
|
||
export function DescriptionPopover({ | ||
description, | ||
label, | ||
onMouseLeave, | ||
x, | ||
y, | ||
yOffset, | ||
}: DescriptionPopoverProps) { | ||
const {id} = useChartContext(); | ||
const chartId = getChartId(id); | ||
|
||
useHideTooltipWhenMounted(); | ||
|
||
return createPortal( | ||
<div | ||
className={styles.Wrapper} | ||
style={{ | ||
top: y, | ||
left: x, | ||
paddingTop: yOffset, | ||
}} | ||
onMouseLeave={onMouseLeave} | ||
data-block-tooltip-events | ||
> | ||
<div | ||
aria-label={label} | ||
className={styles.Container} | ||
role="dialog" | ||
style={{fontSize: FONT_SIZE}} | ||
> | ||
{description} | ||
</div> | ||
</div>, | ||
document.getElementById(chartId) ?? document.body, | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
...rc/components/LineChart/components/MissingDataArea/components/DescriptionPopover/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {DescriptionPopover} from './DescriptionPopover'; |
5 changes: 5 additions & 0 deletions
5
...polaris-viz/src/components/LineChart/components/MissingDataArea/components/Pill/Pill.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@import '../../../../../../styles/common'; | ||
|
||
.Group { | ||
@include no-outline; | ||
} |
Oops, something went wrong.