Skip to content

Commit

Permalink
fix: baseline correction zones visibility
Browse files Browse the repository at this point in the history
They should only appear and be removable when the baseline correction tool is selected.

close #2348
  • Loading branch information
hamed-musallam committed Jul 7, 2023
1 parent 02e94fa commit 0f27e2f
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions src/component/1d/tool/BaseLineZones.tsx
Expand Up @@ -28,42 +28,46 @@ const styles = css`
`;

function BaseLineZones() {
const { toolOptions } = useChartData();
const {
toolOptions: {
selectedTool,
data: { baselineCorrection },
},
} = useChartData();

const { scaleX } = useScaleChecked();
const dispatch = useDispatch();

const deleteRangeHandler = (id) => {
dispatch({ type: 'DELETE_BASE_LINE_ZONE', payload: { id } });
};
const baseLineZones = baselineCorrection.zones;

const baseLineZones = toolOptions.data.baselineCorrection.zones;
if (selectedTool !== 'baselineCorrection' || baseLineZones.length === 0) {
return null;
}

return (
<>
{baseLineZones.length > 0 && (
<g>
{baseLineZones.map((zone) => (
<g
key={zone.id}
transform={`translate(${scaleX()(zone.to)},0)`}
css={styles}
>
<DeleteButton
x={-20}
y={10}
onDelete={() => deleteRangeHandler(zone.id)}
/>
<rect
x="0"
width={`${scaleX()(zone.from) - scaleX()(zone.to)}`}
className="zone-area"
/>
</g>
))}
<g>
{baselineCorrection.zones.map((zone) => (
<g
key={zone.id}
transform={`translate(${scaleX()(zone.to)},0)`}
css={styles}
>
<DeleteButton
x={-20}
y={10}
onDelete={() => deleteRangeHandler(zone.id)}
/>
<rect
x="0"
width={`${scaleX()(zone.from) - scaleX()(zone.to)}`}
className="zone-area"
/>
</g>
)}
</>
))}
</g>
);
}

Expand Down

0 comments on commit 0f27e2f

Please sign in to comment.