Code Monkey home page Code Monkey logo

Comments (7)

bkrem avatar bkrem commented on May 16, 2024 1

@adilapapaya Thanks man, seeing people do cool stuff with this library is what keeps me motivated :)

As far as I can tell this is basically a mutex-type problem where the onClick handler needs to block until the associated transition time has expired.

I took a shot at this a while ago and didn't quite get there, will give it another serious shot whenever I can commit time during the next week.

As mentioned before, if you feel you have a clean solution to this annoying issue feel free to explain here and/or open a PR and I'll do my best to support you!

cc @superdyzio

from react-d3-tree.

bkrem avatar bkrem commented on May 16, 2024 1

Fixed in v1.10.4 🎉

Thank you @nimitwalia89 for your fix suggestion 👏
With your suggestion I finally broke through some mental barriers that had built up and found a simple solution to the issue that is completely contained within one flag and Tree.handleNodeToggle().

Fix commit for those interested: e5cf741

If the bug is still reproducible in 1.10.4 please reopen this issue, otherwise if you find regressions due to this fix please open another issue.

But for now: good riddance to this shitty bug! 🐛 👋

from react-d3-tree.

jmorrice avatar jmorrice commented on May 16, 2024

+1!

from react-d3-tree.

bkrem avatar bkrem commented on May 16, 2024

Apologies that this hasn't been resolved yet, tried debugging this multiple times in my spare time but haven't been able to pin down the cause yet.

Tackling it again this week, but would love to hear any suggestions/advice you guys have + of course your own PRs to patch this are welcome anytime.

from react-d3-tree.

superdyzio avatar superdyzio commented on May 16, 2024

Still occurs on v1.9.2. @bkrem - Have you approached this again since your last comment?

from react-d3-tree.

adilapapaya avatar adilapapaya commented on May 16, 2024

@bkrem I wonder if you could get around this by adding a dbl click listener and setting that to do nothing.

(also, thanks for the awesome library!!) :)

from react-d3-tree.

nimitwalia89 avatar nimitwalia89 commented on May 16, 2024

@bkrem i kind of found a solution for it. Please give it a try.
Inside Tree/index.js add a variable outside class

let clickDisabled = false;
handleNodeToggle(nodeId, evt) {
    const data = clone(this.state.data);
    const matches = this.findNodesById(nodeId, data, []);
    const targetNode = matches[0];

    if (this.props.collapsible) {
      if(!clickDisabled){
        console.log('click');
      targetNode._collapsed ? this.expandNode(targetNode) : this.collapseNode(targetNode);
      this.setState({ data }, () => this.handleOnClickCb(targetNode, evt));
      this.internalState.targetNode = targetNode;
      }
    } else {
      this.handleOnClickCb(targetNode, evt);
    }
  }

testBreakFix = () => {
    clickDisabled = !clickDisabled;
  }

add clickToggle={this.testBreakFix} prop to Link.

then inside Link/index.js

let timer = null; keep this outside class.

applyOpacity(opacity, transitionDuration, transitionComplete) {
    this.props.clickToggle();
    if (transitionDuration === 0) {
      select(this.link).style('opacity', opacity);
      this.transitionComplete();
    } else {
      select(this.link)
        .transition()
        .duration(transitionDuration)
        .style('opacity', opacity)
        .each('end', this.transitionComplete());
    }
  }

  transitionComplete = () => {
    clearTimeout(timer);
    timer = setTimeout(this.timerFunc, this.props.transitionDuration + 100);
  }

  timerFunc = () => {
    console.log('All done');
    this.props.clickToggle();
  }

Hope this helps

from react-d3-tree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.