Skip to content

Commit

Permalink
fix(react-components): trendcursor hotkey indicates addition state
Browse files Browse the repository at this point in the history
  • Loading branch information
ssjagad authored and diehbria committed Dec 7, 2023
1 parent 4c9453a commit c9d34e0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { MutableRefObject } from 'react';
import { ECharts } from 'echarts';
import { MAX_TREND_CURSORS } from '../../../constants';
import { InternalGraphicComponentGroupOption } from '../../../types';

export const mouseoverHandler = (isInCursorAddMode: boolean, chartRef: MutableRefObject<ECharts | null>) => {
if (isInCursorAddMode) {
export const mouseoverHandler = (
isInCursorAddMode: boolean,
tcGraphicList: InternalGraphicComponentGroupOption[],
chartRef: MutableRefObject<ECharts | null>
) => {
if (isInCursorAddMode && tcGraphicList.length < MAX_TREND_CURSORS) {
chartRef.current?.getZr().setCursorStyle('crosshair');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,13 @@ const useTrendCursorsEvents = ({
// standalone mode --> updates the local state
useEffect(() => {
const currentChart = chartRef.current;
if (isInCursorAddModeRef.current && graphicRef.current.length < MAX_TREND_CURSORS) {
chartRef.current?.getZr().setCursorStyle('crosshair');
} else {
chartRef.current?.getZr().setCursorStyle('default'); // in case we get out of add mode and mouse does not move, switch back to default cursor
}

const mouseMoveEventHandler = () => mouseoverHandler(isInCursorAddModeRef.current, chartRef);
const mouseMoveEventHandler = () => mouseoverHandler(isInCursorAddModeRef.current, graphicRef.current, chartRef);

// this handles all the clicks on the chart
// this click would be either
Expand Down Expand Up @@ -246,7 +251,15 @@ const useTrendCursorsEvents = ({
currentChart?.getZr()?.off('dragstart', dragStartEventHandler);
currentChart?.off('datazoom', zoomHandler);
};
}, [addNewTrendCursor, deleteTrendCursor, groupId, updateTrendCursorsInSyncState, chartRef, setGraphic]);
}, [
addNewTrendCursor,
deleteTrendCursor,
groupId,
updateTrendCursorsInSyncState,
chartRef,
setGraphic,
isInCursorAddMode,
]);

const copyTrendCursorData = (posX: number) => {
const timestampOfClick = calculateTimeStamp(posX, chartRef);
Expand Down

0 comments on commit c9d34e0

Please sign in to comment.