feedzai / brushable-histogram

A time histogram with a brushable preview of the whole dataset below it
Other
91 stars 9 forks source link

Brush ref not getting initialised in DensityChart #46

Open lakhansamani opened 4 years ago

lakhansamani commented 4 years ago

Issue

Not able to create a brushable histogram because of the following error

Uncaught Error: illegal type: function brush(group) {
    var overlay = group
        .property("__brush", initialize)
      .selectAll(".overlay")
      .data([type("overlay")]);

    overlay.enter().append("rect")
        .attr("class", "overlay")
        .attr("pointer-events", "all")
        .attr("cursor", cursors.overlay)
      .merge(overlay)
        .each(function() {
          var extent = local(this).extent;
          d3Selection.select(this)
              .attr("x", extent[0][0])
              .attr("y", extent[0][1])
              .attr("width", extent[1][0] - extent[0][0])
              .attr("height", extent[1][1] - extent[0][1]);
        });

    group.selectAll(".selection")
      .data([type("selection")])
      .enter().append("rect")
        .attr("class", "selection")
        .attr("cursor", cursors.selection)
        .attr("fill", "#777")
        .attr("fill-opacity", 0.3)
        .attr("stroke", "#fff")
        .attr("shape-rendering", "crispEdges");

    var handle = group.selectAll(".handle")
      .data(dim.handles, function(d) { return d.type; });

    handle.exit().remove();

    handle.enter().append("rect")
        .attr("class", function(d) { return "handle handle--" + d.type; })
        .attr("cursor", function(d) { return cursors[d.type]; });

    group
        .each(redraw)
        .attr("fill", "none")
        .attr("pointer-events", "all")
        .style("-webkit-tap-highlight-color", "rgba(0,0,0,0)")
        .on("mousedown.brush touchstart.brush", started);
  }
    at Object.dispatch (d3-dispatch.js:12)
    at brush$1 (d3-brush.js:157)
    at brushX (d3-brush.js:143)
    at DensityChart.componentDidMount (DensityChart.js:76)
    at commitLifeCycles (react-dom.development.js:22101)
    at commitLayoutEffects (react-dom.development.js:25344)
    at HTMLUnknownElement.callCallback (react-dom.development.js:336)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:385)
    at invokeGuardedCallback (react-dom.development.js:440)
    at commitRootImpl (react-dom.development.js:25082)
    at unstable_runWithPriority (scheduler.development.js:697)
    at runWithPriority$2 (react-dom.development.js:12149)
    at commitRoot (react-dom.development.js:24922)
    at finishSyncRender (react-dom.development.js:24329)
    at performSyncWorkOnRoot (react-dom.development.js:24307)
    at eval (react-dom.development.js:12199)
    at unstable_runWithPriority (scheduler.development.js:697)
    at runWithPriority$2 (react-dom.development.js:12149)
    at flushSyncCallbackQueueImpl (react-dom.development.js:12194)
    at flushSyncCallbackQueue (react-dom.development.js:12182)
    at scheduleUpdateOnFiber (react-dom.development.js:23709)
    at Object.enqueueSetState (react-dom.development.js:13994)
    at SizeAwareComponent.Component.setState (react.development.js:325)
    at SizeAwareComponent._this2.strategisedSetState (react-sizeme.js:308)
    at eval (react-sizeme.js:336)
    at invokeFunc (index.js:160)
    at leadingEdge (index.js:170)
    at debounced (index.js:235)
    at addListener (element-resize-detector.js:163)
    at onElementDetectable (element-resize-detector.js:238)
    at ready (scroll.js:600)
    at Object.process (batch-processor.js:124)
    at processBatch (batch-processor.js:37)

Steps to reproduce

https://codesandbox.io/s/recursing-jackson-yvucx

nancruz commented 4 years ago

Hi @lakhansamani,

Can you please try to install the "d3-dispatch" 1.0.5 version? I think the 1.0.6 version is being installed as an indirect dependency, which is causing that error.

lakhansamani commented 4 years ago

@nancruz I tried adding d3-dispatch: 1.0.5 in the same sandbox but now, it is giving null event error

Screenshot 2020-04-06 14 21 33
lakhansamani commented 4 years ago

@nancruz also I had to install core-js: 2.* to make this mark. There might be some peer dependencies for which versions could be fixed here.

lakhansamani commented 4 years ago

@nancruz figured out the issue behind the version change. I was using yarn to install my dependencies and since the yarn.lock with specific versions was not present. It failed.

Have created PR for the same by importing the yarn from package-lock.json

nancruz commented 4 years ago

Thank you @lakhansamani