Skip to content

Commit

Permalink
Fix histogram zr handler (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorVelarde authored Jun 14, 2023
1 parent de72d90 commit 999e81c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
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) {
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) {
events[eventKey] = event;
zr.on(eventKey, event);

Expand Down

0 comments on commit 999e81c

Please sign in to comment.