diff --git a/docs/src/docs/SankeyDiagram/propDocs.json b/docs/src/docs/SankeyDiagram/propDocs.json index e96919a1..db134ed1 100644 --- a/docs/src/docs/SankeyDiagram/propDocs.json +++ b/docs/src/docs/SankeyDiagram/propDocs.json @@ -6,33 +6,11 @@ "type": { "name": "arrayOf", "value": { - "name": "shape", - "value": { - "id": { - "name": "union", - "value": [ - { - "name": "string" - }, - { - "name": "number" - } - ], - "required": false - }, - "value": { - "name": "number", - "required": false - }, - "step": { - "name": "number", - "required": false - } - } + "name": "object" } }, - "required": false, - "description": "Array of node objects, represented by vertical lines.\nThese represent the base entities which links flow into & out of.\nEach should have a numerical value and (optionally) a unique identifier.\nIf no identifier is included, the node index will be used." + "required": true, + "description": "Array of node objects, represented by vertical rectangles.\nThese represent the base entities which links flow into & out of." }, "links": { "type": { @@ -71,15 +49,81 @@ } } }, - "required": false, + "required": true, "description": "Array of link objects, represented by curved paths between nodes.\nLinks represent a magnitude of flow between one node and another.\nEach should have a 'source' node [identifier], a 'target' node [identifier],\nand a numerical value representing flow magnitude." }, + "width": { + "type": { + "name": "number" + }, + "required": true, + "description": "Width of the SVG element.", + "defaultValue": { + "value": "400", + "computed": false + } + }, + "height": { + "type": { + "name": "number" + }, + "required": true, + "description": "Height of the SVG element.", + "defaultValue": { + "value": "300", + "computed": false + } + }, + "className": { + "type": { + "name": "string" + }, + "required": false, + "description": "`className` attribute to be applied to the SVG element.", + "defaultValue": { + "value": "''", + "computed": false + } + }, + "style": { + "type": { + "name": "object" + }, + "required": false, + "description": "Inline style object to be applied to the SVG element.", + "defaultValue": { + "value": "{}", + "computed": false + } + }, "nodeId": { + "type": { + "name": "func" + }, + "required": false, + "description": "Accessor function `nodeId(node, nodeIndex)` which specifies how to access the ID of each node object.\nThese should be the same identifiers used by `links[].source` and `.target`.\nUses the node's index in `nodes` array by default.", + "defaultValue": { + "value": "node => node.index", + "computed": false + } + }, + "nodeLabelText": { + "type": { + "name": "func" + }, + "required": false, + "description": "", + "defaultValue": { + "value": "node => node.name", + "computed": false + } + }, + "showNodes": { "type": { "name": "union", "value": [ { - "name": "string" + "name": "bool" }, { "name": "func" @@ -87,7 +131,11 @@ ] }, "required": false, - "description": "" + "description": "Boolean which determines if node rectangles should be shown,\nor function (`showNode(node, nodeIndex)`) which returns a boolean", + "defaultValue": { + "value": "true", + "computed": false + } }, "nodeWidth": { "type": { @@ -153,7 +201,7 @@ ] }, "required": false, - "description": "Class attribute to be applied to each node,\nor accessor function which returns a class (string).", + "description": "`className` attribute to be applied to each node,\nor accessor function which returns a class (string).", "defaultValue": { "value": "''", "computed": false @@ -178,23 +226,184 @@ "computed": false } }, - "width": { + "showLinks": { + "type": { + "name": "union", + "value": [ + { + "name": "bool" + }, + { + "name": "func" + } + ] + }, + "required": false, + "description": "Boolean which determines if link paths should be shown,\nor function (`showLink(link, linkIndex)`) which returns a boolean", "defaultValue": { - "value": "400", + "value": "true", "computed": false } }, - "height": { + "linkClassName": { + "type": { + "name": "union", + "value": [ + { + "name": "string" + }, + { + "name": "func" + } + ] + }, + "required": false, + "description": "Class attribute to be applied to each link,\nor accessor function which returns a class (string).", "defaultValue": { - "value": "300", + "value": "''", "computed": false } }, - "getNodeId": { + "linkStyle": { + "type": { + "name": "union", + "value": [ + { + "name": "object" + }, + { + "name": "func" + } + ] + }, + "required": false, + "description": "Inline style object to be applied to each link,\nor accessor function which returns a style object.", + "defaultValue": { + "value": "{}", + "computed": false + } + }, + "showNodeLabels": { + "type": { + "name": "union", + "value": [ + { + "name": "bool" + }, + { + "name": "func" + } + ] + }, + "required": false, + "description": "Boolean which determines if node labels should be shown,\nor function (`showLink(link, linkIndex)`) which returns a boolean", + "defaultValue": { + "value": "true", + "computed": false + } + }, + "showLinkLabels": { + "type": { + "name": "union", + "value": [ + { + "name": "bool" + }, + { + "name": "func" + } + ] + }, + "required": false, + "description": "Boolean which determines if node labels should be shown,\nor function (`showLink(link, linkIndex)`) which returns a boolean", "defaultValue": { - "value": "'id'", + "value": "true", "computed": false } + }, + "onMouseEnterNode": { + "type": { + "name": "func" + }, + "required": false, + "description": "" + }, + "onMouseLeaveNode": { + "type": { + "name": "func" + }, + "required": false, + "description": "" + }, + "onMouseMoveNode": { + "type": { + "name": "func" + }, + "required": false, + "description": "" + }, + "onMouseDownNode": { + "type": { + "name": "func" + }, + "required": false, + "description": "" + }, + "onMouseUpNode": { + "type": { + "name": "func" + }, + "required": false, + "description": "" + }, + "onClickNode": { + "type": { + "name": "func" + }, + "required": false, + "description": "" + }, + "onMouseEnterLink": { + "type": { + "name": "func" + }, + "required": false, + "description": "" + }, + "onMouseLeaveLink": { + "type": { + "name": "func" + }, + "required": false, + "description": "" + }, + "onMouseMoveLink": { + "type": { + "name": "func" + }, + "required": false, + "description": "" + }, + "onMouseDownLink": { + "type": { + "name": "func" + }, + "required": false, + "description": "" + }, + "onMouseUpLink": { + "type": { + "name": "func" + }, + "required": false, + "description": "" + }, + "onClickLink": { + "type": { + "name": "func" + }, + "required": false, + "description": "" } } } \ No newline at end of file diff --git a/package.json b/package.json index 2cb10bd1..e3e800bc 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "react-router-dom": "^4.1.2", "remark": "^8.0.0", "remark-react": "^4.0.1", + "rewire": "^3.0.2", "shelljs": "^0.7.8", "sinon": "^4.1.2", "sinon-chai": "^2.14.0", diff --git a/src/SankeyDiagram.js b/src/SankeyDiagram.js index df85d1a3..6f100d98 100644 --- a/src/SankeyDiagram.js +++ b/src/SankeyDiagram.js @@ -17,7 +17,7 @@ const nodeAlignmentsByName = { }; -export const SankeyNode = (props) => { +const SankeyNode = (props) => { const {graph, node, nodeIndex, nodeClassName, nodeStyle, onMouseEnterNode, onMouseLeaveNode, onMouseMoveNode, onMouseDownNode, onMouseUpNode, onClickNode } = props; @@ -41,7 +41,7 @@ export const SankeyNode = (props) => { />; }; -export const SankeyLink = (props) => { +const SankeyLink = (props) => { const { graph, link, linkIndex, linkPath, linkClassName, linkStyle, onMouseEnterLink, onMouseLeaveLink, onMouseMoveLink, onMouseDownLink, onMouseUpLink, onClickLink diff --git a/tests/jsdom/spec/SankeyDiagram.spec.js b/tests/jsdom/spec/SankeyDiagram.spec.js index 762bcdd1..0548141d 100644 --- a/tests/jsdom/spec/SankeyDiagram.spec.js +++ b/tests/jsdom/spec/SankeyDiagram.spec.js @@ -8,9 +8,12 @@ import sinonChai from 'sinon-chai'; chai.use(sinonChai); const {expect} = chai; -import {SankeyDiagram} from '../../../src/index.js'; -import {SankeyNode, SankeyLink} from '../../../src/SankeyDiagram'; - +// use rewire to test internal SankeyNode/Link/etc. components +const rewire = require('rewire'); +const Sankey = rewire('../../../src/SankeyDiagram'); +const SankeyDiagram = Sankey.default; +const SankeyNode = Sankey.__get__('SankeyNode'); +const SankeyLink = Sankey.__get__('SankeyLink'); describe('SankeyDiagram', () => { it('renders a Sankey Diagram', () => { diff --git a/yarn.lock b/yarn.lock index 854b8dc8..331bb624 100644 --- a/yarn.lock +++ b/yarn.lock @@ -623,7 +623,7 @@ babel-plugin-transform-es2015-block-scoped-functions@^6.22.0: dependencies: babel-runtime "^6.22.0" -babel-plugin-transform-es2015-block-scoping@^6.24.1: +babel-plugin-transform-es2015-block-scoping@^6.24.1, babel-plugin-transform-es2015-block-scoping@^6.26.0: version "6.26.0" resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-block-scoping/-/babel-plugin-transform-es2015-block-scoping-6.26.0.tgz#d70f5299c1308d05c12f463813b0a09e73b1895f" dependencies: @@ -5726,6 +5726,13 @@ resolve@^1.1.6: dependencies: path-parse "^1.0.5" +rewire@^3.0.2: + version "3.0.2" + resolved "http://artifactory.spotify.net/artifactory/api/npm/virtual-npm/rewire/-/rewire-3.0.2.tgz#25e5413c4f1676eb3247d1884198b3a265408bbd" + dependencies: + babel-core "^6.26.0" + babel-plugin-transform-es2015-block-scoping "^6.26.0" + right-align@^0.1.1: version "0.1.3" resolved "https://registry.yarnpkg.com/right-align/-/right-align-0.1.3.tgz#61339b722fe6a3515689210d24e14c96148613ef"