-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add new tool to draw exclusion zones
- Loading branch information
1 parent
8ba8fc9
commit 1d48ebd
Showing
17 changed files
with
185 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** @jsxImportSource @emotion/react */ | ||
import { css } from '@emotion/react'; | ||
|
||
import { useScale } from '../context/ScaleContext'; | ||
import { TYPES, useHighlight } from '../highlight'; | ||
import ExclusionZonesWrapper from '../hoc/ExclusionZonesWrapper'; | ||
|
||
const styles = css` | ||
pointer-events: bounding-box; | ||
user-select: 'none'; | ||
-webkit-user-select: none; /* Chrome all / Safari all */ | ||
-moz-user-select: none; /* Firefox all */ | ||
.zone-area { | ||
height: 100%; | ||
fill: #dddddd; | ||
cursor: pointer; | ||
} | ||
.zone-area.active { | ||
fill: #ff6f0057; | ||
} | ||
`; | ||
|
||
const ExclusionZone = ({ zone }) => { | ||
const { scaleX } = useScale(); | ||
const highlight = useHighlight([zone.id], TYPES.EXCLUSION_ZONE); | ||
return ( | ||
<g | ||
key={zone.id} | ||
transform={`translate(${scaleX()(zone.to)},0)`} | ||
css={styles} | ||
{...highlight.onHover} | ||
> | ||
<rect | ||
x="0" | ||
width={`${scaleX()(zone.from) - scaleX()(zone.to)}`} | ||
className={`zone-area ${highlight.isActive && 'active'}`} | ||
/> | ||
</g> | ||
); | ||
}; | ||
|
||
function ExclusionZones({ exclusionZones }) { | ||
if (!exclusionZones) return null; | ||
|
||
return ( | ||
<g className="exclusionZones"> | ||
{exclusionZones.map((zone) => ( | ||
<ExclusionZone key={zone.id} zone={zone} /> | ||
))} | ||
</g> | ||
); | ||
} | ||
|
||
export default ExclusionZonesWrapper(ExclusionZones); |
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
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,21 @@ | ||
import { useChartData } from '../context/ChartContext'; | ||
|
||
function ExclusionZonesWrapper(WrappedComponent) { | ||
const Wrapper = (props) => { | ||
const { exclusionZones, activeTab } = useChartData(); | ||
|
||
return ( | ||
<WrappedComponent | ||
{...props} | ||
exclusionZones={ | ||
exclusionZones[activeTab] ? exclusionZones[activeTab] : null | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
return (props) => { | ||
return <Wrapper {...props} />; | ||
}; | ||
} | ||
export default ExclusionZonesWrapper; |
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
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
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