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

display my own nodes style without circles #77

Closed
tzookb opened this issue Feb 9, 2018 · 9 comments
Closed

display my own nodes style without circles #77

tzookb opened this issue Feb 9, 2018 · 9 comments
Labels

Comments

@tzookb
Copy link

tzookb commented Feb 9, 2018

class NodeLabel extends React.PureComponent {
    render() {
      const {className, nodeData} = this.props
      return (
        <div className={className} style={{border: '1px solid black'}}>
          <h2>{nodeData.name}</h2>
          {nodeData._children && 
            <button>{nodeData._collapsed ? 'Expand' : 'Collapse'}</button>
          }
        </div>
      )
    }
  }


                       <Tree 
                            data={[treeObj]} 
                            orientation="vertical" 
                            translate={{x:400, y: 50}}
                            allowForeignObjects
                            nodeLabelComponent={{
                                render: <NodeLabel className='myLabelComponentInSvg' />,
                                foreignObjectWrapper: {
                                y: 24
                                }
                            }}
                            />

I want to have my own boxes design, but that the lines will be connected to the boxes and not circles. Is that achievable now?

Thanks

screen shot 2018-02-09 at 11 18 13

@bkrem
Copy link
Owner

bkrem commented Feb 13, 2018

Hi @tzookb,

Apologies for the wait. Removing the node element isn't actually possible right now, but I'll work on this later tonight or tomorrow since it should be possible to just pass none to svgShape.

That should then let you do what you suggested, although you'll most likely have to fiddle with the positioning/sizing of your boxes to make them align nicely with the graph.

@bkrem bkrem added the question label Feb 13, 2018
@bkrem bkrem added this to the v1.9.0 milestone Feb 13, 2018
@bkrem bkrem mentioned this issue Feb 14, 2018
@bkrem
Copy link
Owner

bkrem commented Feb 14, 2018

Just released v1.9.1 with an option to set nodeSvgShape's shape key to 'none', meaning no svg shapes will be rendered for the nodes.

This should hopefully allow you to achieve what you were asking about :)

@bkrem bkrem closed this as completed Feb 14, 2018
@tzookb
Copy link
Author

tzookb commented Feb 15, 2018

Awesome work @bkrem

but I decided to build my own tree

as I noticed I need to connect the lines to centers of the node etc 👍

@dyennam
Copy link

dyennam commented Feb 20, 2018

Hello @tzookb
Could you please give me an example of how you were able to build you tree with your boxes instead of the default nodes. I am trying to do a similar implementation where i want to override each node(CIRCLE) with like a bootstrap card element. But the cards i render are not getting attached at the node level, they are offset just like you mentioned in your original post.

@bkrem Any way we can have user interaction within foreignObjects? (Ex. clicking buttons inside nodes)

image

<Tree
              data={myTreeData}
              zoomable={true}
              scaleExtent={{min: 1, max: 3}}
              pathFunc='elbow'
              allowForeignObjects={true}
              nodeSvgShape={svgCircle}
              translate={{x:200, y: 200}}
              nodeLabelComponent={{
                render:
  <div>
    <div className='card'>
      <div className='card-body'>
        <h5 className='card-title'>Card title</h5>
        <h6 className='card-subtitle mb-2 text-muted'>Card subtitle</h6>
        <p className='card-text'>Some text to build on the card.</p>
      </div>
    </div>
  </div>,
                foreignObjectWrapper: {
                }
              }}
            />

@bkrem bkrem reopened this Feb 21, 2018
@bkrem
Copy link
Owner

bkrem commented Feb 21, 2018

Hey @dyennam,

Here's a relatively simple way you can achieve what I think you're looking for with foreignObjects by leveraging the nodeLabelComponent, nodeSvgShape and nodeSize props:

https://codesandbox.io/s/zrw16nnxox

Note that I also moved the text you hardcoded in the card into each child's attributes key. This let's you pass whatever you want from within your node's dataset into nodeLabelComponent, since the component you use for nodeLabelComponent's render will be passed the respective node's nodeData as a prop :)

cc @tzookb, might be interesting for you too

@dyennam
Copy link

dyennam commented Feb 22, 2018

@bkrem Thanks for the example, helped me out a bunch.
But if I want to take actions on the cards without it having to collapse / expand, how would i go about it? Like i want to be able to add child/sibling nodes, or capture on click events in certain regions to show popups or such things. I want to collapse on a button click per say, instead of on the node.
I have attached a example: https://codesandbox.io/s/ypz7rp61z

@Ben-Tai
Copy link

Ben-Tai commented Jan 17, 2019

@dyennam did you manage to figure this out?

@dyennam
Copy link

dyennam commented Jan 17, 2019

@dyennam did you manage to figure this out?

@Ben-Tai I wasn't able to figure it out. But to be honest to the dev, I haven't used this library in 8+ months. So not sure if it has been fixed or not either.

@bkrem bkrem removed this from the v1.9.0 milestone Jan 23, 2019
@bkrem
Copy link
Owner

bkrem commented Jan 23, 2019

Closing since the discussion here has drifted from the issue topic onto other feature proposals. Feel free to open a feature request issue for said proposals if relevant.

@bkrem bkrem closed this as completed Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants