Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix histogram zr handler #709

Merged
merged 3 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

## Not released

- Fix HistogramWidget breaking onZr events after adding skeleton [#709](https://github.com/CartoDB/carto-react/pull/709)

## 2.0

### 2.0.8 (2023-06-13)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ HistogramWidgetUI.defaultProps = {
HistogramWidgetUI.propTypes = {
data: PropTypes.arrayOf(PropTypes.number).isRequired,
ticks: PropTypes.arrayOf(PropTypes.number).isRequired,
min: PropTypes.number.isRequired,
max: PropTypes.number.isRequired,
min: PropTypes.number,
max: PropTypes.number,
tooltip: PropTypes.bool,
tooltipFormatter: PropTypes.func,
xAxisFormatter: PropTypes.func,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function useHistogramInteractivity({
}

function mouseMoveEvent(params) {
if (initialTimeWindow !== null) {
if (echartsInstance && initialTimeWindow !== null) {
const [x] = echartsInstance.convertFromPixel({ seriesIndex: 0 }, [
params.offsetX,
params.offsetY
Expand All @@ -42,7 +42,7 @@ export default function useHistogramInteractivity({
}
}

if (filterable) {
if (echartsInstance && filterable) {
const mouseDownCleanUp = addEventWithCleanUp(zr, 'mousedown', mouseDownEvent);
const mouseMoveCleanUp = addEventWithCleanUp(zr, 'mousemove', mouseMoveEvent);

Expand Down Expand Up @@ -75,7 +75,7 @@ export default function useHistogramInteractivity({
initialTimeWindow = null;
}

if (filterable) {
if (echartsInstance && filterable) {
return addEventWithCleanUp(zr, 'mouseup', mouseUpEvent);
}
}, [zr, echartsInstance, markArea, data, onSelectedBarsChange, filterable]);
Expand Down Expand Up @@ -114,7 +114,7 @@ export default function useHistogramInteractivity({

// Aux
function addEventWithCleanUp(zr, eventKey, event) {
if (zr) {
if (zr && zr.handler) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Key part here

events[eventKey] = event;
zr.on(eventKey, event);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default function useTimeSeriesInteractivity({ echartsInstance, data }) {
updateCursor('grabbing');
}

if (isMarkAreaSelected) {
if (isMarkAreaSelected && echartsInstance) {
const [x] = echartsInstance.convertFromPixel({ seriesIndex: 0 }, [
params.offsetX,
params.offsetY
Expand Down Expand Up @@ -159,7 +159,7 @@ export default function useTimeSeriesInteractivity({ echartsInstance, data }) {
}
}

if (isMarkAreaMoving) {
if (isMarkAreaMoving && echartsInstance) {
const [x] = echartsInstance.convertFromPixel({ seriesIndex: 0 }, [
params.offsetX,
params.offsetY
Expand Down Expand Up @@ -242,7 +242,7 @@ export default function useTimeSeriesInteractivity({ echartsInstance, data }) {

// Aux
function addEventWithCleanUp(zr, eventKey, event) {
if (zr) {
if (zr && zr.handler) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preventive

events[eventKey] = event;
zr.on(eventKey, event);

Expand Down