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

Support for layout options that accept JS func #25

Closed
xhluca opened this issue Jan 13, 2019 · 7 comments
Closed

Support for layout options that accept JS func #25

xhluca opened this issue Jan 13, 2019 · 7 comments

Comments

@xhluca
Copy link
Collaborator

xhluca commented Jan 13, 2019

Description

Certain layout contains options that accept functions. For example, the grid layout:

let options = {
  name: 'grid',

  fit: true, // whether to fit the viewport to the graph
  padding: 30, // padding used on fit
  boundingBox: undefined, // constrain layout bounds; { x1, y1, x2, y2 } or { x1, y1, w, h }
  avoidOverlap: true, // prevents node overlap, may overflow boundingBox if not enough space
  avoidOverlapPadding: 10, // extra spacing around nodes when avoidOverlap: true
  nodeDimensionsIncludeLabels: false, // Excludes the label when calculating node bounding boxes for the layout algorithm
  spacingFactor: undefined, // Applies a multiplicative factor (>0) to expand or compress the overall area that the nodes take up
  condense: false, // uses all available space on false, uses minimal space on true
  rows: undefined, // force num of rows in the grid
  cols: undefined, // force num of columns in the grid
  position: function( node ){}, // returns { row, col } for element
  sort: undefined, // a sorting function to order the nodes; e.g. function(a, b){ return a.data('weight') - b.data('weight') }
  animate: false, // whether to transition the node positions
  animationDuration: 500, // duration of animation in ms if enabled
  animationEasing: undefined, // easing of animation if enabled
  animateFilter: function ( node, i ){ return true; }, // a function that determines whether the node should be animated.  All nodes animated by default on animate enabled.  Non-animated nodes are positioned immediately when the layout starts
  ready: undefined, // callback on layoutready
  stop: undefined, // callback on layoutstop
  transform: function (node, position ){ return position; } // transform a given node position. Useful for changing flow direction in discrete layouts 
};

Obviously, position is not accepted in Python, since it accepts input that is a function mapping from a node object to a {row,col} object.

Possible Solution

Optionally accept dictionary input instead of a function on the Dash/Python side. On the react side, the function will simply look up the object's names (i.e. dictionary keys) and return the corresponding value.

@xhluca xhluca added the future work A feature to be added in future release. Community contribution welcome label Feb 15, 2019
@xhluca xhluca changed the title [Future Work] Support for layout options that accept JS func Support for layout options that accept JS func Feb 15, 2019
@xhluca xhluca added suggestion and removed future work A feature to be added in future release. Community contribution welcome labels Jun 18, 2020
@xhluca
Copy link
Collaborator Author

xhluca commented Jun 29, 2020

Dash clientside callbacks accepts JS, so that should cover some scenarios. If you find a use-case that is not covered, feel free to reopen this.

@xhluca xhluca closed this as completed Jun 29, 2020
@pbelmann
Copy link

Thank you for creating this issue. Could you please show the code how you would solve your example with the dash clientside callback?

@ThomWorm
Copy link

ThomWorm commented Apr 6, 2021

@pbelmann @xhlulu do either of you have an example of how I might use a clientside callback here as a workaround for the inability to use the embedded JS functions? I'm having trouble figuring it out from the dash documentation.

@MoburgLeGrand
Copy link

@ThomWorm Did you ever get this to work ? I can't seem to get it right.

@nmz787-intel
Copy link

did anyone ever come up with an example? I want to try this option on breadthfirst :
depthSort: undefined, // a sorting function to order nodes at equal depth. e.g. function(a, b){ return a.data('weight') - b.data('weight') }

@nmz787-intel
Copy link

seems like the way to do this is, write the JS function as a string in Python... on the JS side, this string would need passed into something like eval

@lvlte
Copy link

lvlte commented Feb 19, 2024

Hi, I'm a bit late but I just wrote an answer on stackoverflow that shows how we can use a clientside callback to assign a JS function to a component property, it addresses the use case of @nmz787-intel but it should help others too. @pbelmann @ThomWorm @MoburgLeGrand

Is it possible to use the depthSort argument in breadthfirst layout in dash-cytoscape?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants