From d7798e0d03961f3290c3bf2f0e2fe9e01f5d417d Mon Sep 17 00:00:00 2001 From: Nathan L Smith Date: Tue, 23 Oct 2018 15:47:20 -0500 Subject: [PATCH] [cytoscape] fixes for data definitions * `width` and `height` of Css.Node can be a string other than "label" if using a [mapper](http://js.cytoscape.org/#style/mappers) (it probably would be good to eventually define the possible values for CSS properties as a type and use that, since these can also take functions and other stuff.) * Node and edge data can have any serializable JSON, so add `{ [key:string: any `} to those definitions. --- types/cytoscape/cytoscape-tests.ts | 5 +++-- types/cytoscape/index.d.ts | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/types/cytoscape/cytoscape-tests.ts b/types/cytoscape/cytoscape-tests.ts index 0cffa42b31..dc0607a3c3 100644 --- a/types/cytoscape/cytoscape-tests.ts +++ b/types/cytoscape/cytoscape-tests.ts @@ -36,7 +36,8 @@ const showAllStyle: cytoscape.Stylesheet[] = [ 'text-halign': 'center', shape: 'rectangle', 'min-zoomed-font-size': 20, - opacity: 1 + opacity: 1, + width: 'mapData(weight, 40, 80, 20, 60)' } }, { @@ -125,7 +126,7 @@ cy.on('zoom', (event) => { cy.off('zoom'); // events(cy); - TODO -cy.add({ data: { id: 'g' }, position: {x: 200, y: 150} }); +cy.add({ data: { id: 'g', someOtherKey: 'value' }, position: {x: 200, y: 150} }); cy.add([ { data: { id: 'h' }, position: {x: 250, y: 100} } ]); diff --git a/types/cytoscape/index.d.ts b/types/cytoscape/index.d.ts index 59482ad507..7ea05577be 100644 --- a/types/cytoscape/index.d.ts +++ b/types/cytoscape/index.d.ts @@ -133,6 +133,8 @@ declare namespace cytoscape { } interface EdgeDataDefinition extends ElementDataDefinition { + id?: string; + /** * the source node id (edge comes from this node) */ @@ -141,6 +143,8 @@ declare namespace cytoscape { * the target node id (edge goes to this node) */ target: string; + + [key: string]: any; } interface NodeDefinition extends ElementDefinition { @@ -148,7 +152,9 @@ declare namespace cytoscape { } interface NodeDataDefinition extends ElementDataDefinition { + id?: string; parent?: string; + [key: string]: any; } interface CytoscapeOptions { @@ -3445,13 +3451,13 @@ declare namespace cytoscape { * This property can take on the special value label * so the width is automatically based on the node’s label. */ - "width"?: number | "label"; + "width"?: number | string; /** * The height of the node’s body. * This property can take on the special value label * so the height is automatically based on the node’s label. */ - "height"?: number | "label"; + "height"?: number | string; /** * The shape of the node’s body. */ @@ -3624,7 +3630,7 @@ declare namespace cytoscape { /** * The width of an edge’s line. */ - "width"?: number | "label"; + "width"?: number | string; /** * The curving method used to separate two or more edges between two nodes; * may be