-
Notifications
You must be signed in to change notification settings - Fork 28
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
1 parent
1f18106
commit 29a6655
Showing
12 changed files
with
403 additions
and
6 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
33 changes: 33 additions & 0 deletions
33
packages/polaris-viz/src/components/FunnelChartNext/components/Tooltip/Tooltip.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,33 @@ | ||
.Rows { | ||
display: grid; | ||
grid-template-columns: 1fr 1fr; | ||
gap: 8px; | ||
} | ||
|
||
.Row { | ||
font-size: 12px; | ||
display: grid; | ||
grid-column: 1 / -1; | ||
grid-template-columns: subgrid; | ||
color: rgba(97, 97, 97, 1); | ||
align-items: center; | ||
} | ||
|
||
.Keys { | ||
display: flex; | ||
align-items: center; | ||
gap: 4px; | ||
} | ||
|
||
.Values { | ||
display: flex; | ||
align-items: center; | ||
justify-content: flex-end; | ||
gap: 4px; | ||
font-weight: 600; | ||
|
||
strong { | ||
font-weight: 600; | ||
color: rgba(31, 33, 36, 1); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
packages/polaris-viz/src/components/FunnelChartNext/components/Tooltip/Tooltip.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,93 @@ | ||
import {Fragment} from 'react'; | ||
import type {Color, DataPoint, LabelFormatter} from '@shopify/polaris-viz-core'; | ||
import {DEFAULT_THEME_NAME} from '@shopify/polaris-viz-core'; | ||
|
||
import {TOOLTIP_WIDTH} from '../../constants'; | ||
import {FUNNEL_CHART_CONNECTOR_GRADIENT} from '../../../shared/FunnelChartConnector'; | ||
import {FUNNEL_CHART_SEGMENT_FILL} from '../../../shared/FunnelChartSegment'; | ||
import type {FunnelChartNextProps} from '../../FunnelChartNext'; | ||
import {SeriesIcon} from '../../../shared/SeriesIcon'; | ||
import {calculateDropOff} from '../../utilities/calculate-dropoff'; | ||
import {TooltipContentContainer, TooltipTitle} from '../../../TooltipContent'; | ||
|
||
import styles from './Tooltip.scss'; | ||
|
||
export interface TooltipContentProps { | ||
activeIndex: number; | ||
dataSeries: DataPoint[]; | ||
tooltipLabels: FunnelChartNextProps['tooltipLabels']; | ||
labelFormatter: LabelFormatter; | ||
percentageFormatter: (value: number) => string; | ||
} | ||
|
||
interface Data { | ||
key: string; | ||
value: string; | ||
color: Color; | ||
percent: number; | ||
} | ||
|
||
export function Tooltip({ | ||
activeIndex, | ||
dataSeries, | ||
tooltipLabels, | ||
labelFormatter, | ||
percentageFormatter, | ||
}: TooltipContentProps) { | ||
const point = dataSeries[activeIndex]; | ||
const previousPoint = dataSeries[activeIndex - 1]; | ||
const isFirst = activeIndex === 0; | ||
|
||
const dropOffPercentage = Math.abs( | ||
calculateDropOff(previousPoint?.value ?? 0, point?.value ?? 0), | ||
); | ||
|
||
const data: Data[] = [ | ||
{ | ||
key: tooltipLabels.reached, | ||
value: labelFormatter(point.value), | ||
color: FUNNEL_CHART_SEGMENT_FILL, | ||
percent: isFirst ? 100 : 100 - dropOffPercentage, | ||
}, | ||
]; | ||
|
||
if (!isFirst) { | ||
data.push({ | ||
key: tooltipLabels.dropped, | ||
value: labelFormatter((previousPoint?.value ?? 0) - (point.value ?? 0)), | ||
percent: dropOffPercentage, | ||
color: FUNNEL_CHART_CONNECTOR_GRADIENT, | ||
}); | ||
} | ||
|
||
return ( | ||
<TooltipContentContainer | ||
maxWidth={TOOLTIP_WIDTH} | ||
theme={DEFAULT_THEME_NAME} | ||
> | ||
{() => ( | ||
<Fragment> | ||
<TooltipTitle theme={DEFAULT_THEME_NAME}>{point.key}</TooltipTitle> | ||
<div className={styles.Rows}> | ||
{data.map(({key, value, color, percent}, index) => { | ||
return ( | ||
<div className={styles.Row} key={`row-${index}-${key}`}> | ||
<div className={styles.Keys}> | ||
<SeriesIcon color={color!} shape="Bar" /> | ||
<span>{key}</span> | ||
</div> | ||
<div className={styles.Values}> | ||
<span>{value}</span> | ||
<span> | ||
<strong>{percentageFormatter(percent)}</strong> | ||
</span> | ||
</div> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
</Fragment> | ||
)} | ||
</TooltipContentContainer> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
packages/polaris-viz/src/components/FunnelChartNext/components/Tooltip/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 {Tooltip} from './Tooltip'; |
Oops, something went wrong.