@d3plus/react 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -0
- package/es/index.jsx +132 -0
- package/es/src/D3plusContext.jsx +5 -0
- package/es/src/Viz.jsx +41 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @d3plus/react
|
|
2
|
+
|
|
3
|
+
React components for d3plus visualizations.
|
|
4
|
+
|
|
5
|
+
## Installing
|
|
6
|
+
|
|
7
|
+
If using npm, `npm install @d3plus/react`. Otherwise, you can download the [latest release from GitHub](https://github.com/d3plus/d3plus/releases/latest) or load from a [CDN](https://cdn.jsdelivr.net/npm/@d3plus/react@3.0.0-alpha.0/+esm).
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
import modules from "@d3plus/react";
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
In vanilla JavaScript, a `d3plus` global is exported from the pre-bundled version:
|
|
14
|
+
|
|
15
|
+
```html
|
|
16
|
+
<script src="https://cdn.jsdelivr.net/npm/@d3plus/react@3.0.0-alpha.0"></script>
|
|
17
|
+
<script>
|
|
18
|
+
console.log(d3plus);
|
|
19
|
+
</script>
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Examples
|
|
23
|
+
|
|
24
|
+
Live examples can be found on [d3plus.org](https://d3plus.org/), which includes a collection of example visualizations using @d3plus/react.
|
|
25
|
+
|
|
26
|
+
## API Reference
|
|
27
|
+
|
|
28
|
+
#####
|
|
29
|
+
* [D3plusContext](#D3plusContext) - A React context instance used to provide global config options via a provider (D3plusContext.Provider).
|
|
30
|
+
* [Viz](#Viz)
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
<a name="D3plusContext"></a>
|
|
35
|
+
#### d3plus.**D3plusContext**() [<>](https://github.com/d3plus/d3plus/blob/main/packages/react/src/D3plusContext.jsx#L3)
|
|
36
|
+
|
|
37
|
+
A React context instance used to provide global config options via a provider (D3plusContext.Provider).
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
This is a global function
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
<a name="Viz"></a>
|
|
45
|
+
#### d3plus.**Viz**(config, [className], [callback]) [<>](https://github.com/d3plus/d3plus/blob/main/packages/react/src/Viz.jsx#L6)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
This is a global function
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
###### <sub>Documentation generated on Thu, 13 Mar 2025 19:58:30 GMT</sub>
|
package/es/index.jsx
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _object_spread(target) {
|
|
15
|
+
for(var i = 1; i < arguments.length; i++){
|
|
16
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
17
|
+
var ownKeys = Object.keys(source);
|
|
18
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
19
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
20
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
ownKeys.forEach(function(key) {
|
|
24
|
+
_define_property(target, key, source[key]);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
}
|
|
29
|
+
import React from "react";
|
|
30
|
+
import { AreaPlot as AreaPlotClass, BarChart as BarChartClass, BoxWhisker as BoxWhiskerClass, BumpChart as BumpChartClass, Donut as DonutClass, Geomap as GeomapClass, LinePlot as LinePlotClass, Matrix as MatrixClass, Network as NetworkClass, Pack as PackClass, Pie as PieClass, Plot as PlotClass, Priestley as PriestleyClass, Radar as RadarClass, RadialMatrix as RadialMatrixClass, Rings as RingsClass, Sankey as SankeyClass, StackedArea as StackedAreaClass, Tree as TreeClass, Treemap as TreemapClass } from "@d3plus/core";
|
|
31
|
+
import Viz from "./src/Viz.jsx";
|
|
32
|
+
export var AreaPlot = function(props) {
|
|
33
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
34
|
+
instance: new AreaPlotClass()
|
|
35
|
+
}, props));
|
|
36
|
+
};
|
|
37
|
+
export var BarChart = function(props) {
|
|
38
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
39
|
+
instance: new BarChartClass()
|
|
40
|
+
}, props));
|
|
41
|
+
};
|
|
42
|
+
export var BoxWhisker = function(props) {
|
|
43
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
44
|
+
instance: new BoxWhiskerClass()
|
|
45
|
+
}, props));
|
|
46
|
+
};
|
|
47
|
+
export var BumpChart = function(props) {
|
|
48
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
49
|
+
instance: new BumpChartClass()
|
|
50
|
+
}, props));
|
|
51
|
+
};
|
|
52
|
+
export var Donut = function(props) {
|
|
53
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
54
|
+
instance: new DonutClass()
|
|
55
|
+
}, props));
|
|
56
|
+
};
|
|
57
|
+
export var Geomap = function(props) {
|
|
58
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
59
|
+
instance: new GeomapClass()
|
|
60
|
+
}, props));
|
|
61
|
+
};
|
|
62
|
+
export var LinePlot = function(props) {
|
|
63
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
64
|
+
instance: new LinePlotClass()
|
|
65
|
+
}, props));
|
|
66
|
+
};
|
|
67
|
+
export var Matrix = function(props) {
|
|
68
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
69
|
+
instance: new MatrixClass()
|
|
70
|
+
}, props));
|
|
71
|
+
};
|
|
72
|
+
export var Network = function(props) {
|
|
73
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
74
|
+
instance: new NetworkClass()
|
|
75
|
+
}, props));
|
|
76
|
+
};
|
|
77
|
+
export var Pack = function(props) {
|
|
78
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
79
|
+
instance: new PackClass()
|
|
80
|
+
}, props));
|
|
81
|
+
};
|
|
82
|
+
export var Pie = function(props) {
|
|
83
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
84
|
+
instance: new PieClass()
|
|
85
|
+
}, props));
|
|
86
|
+
};
|
|
87
|
+
export var Plot = function(props) {
|
|
88
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
89
|
+
instance: new PlotClass()
|
|
90
|
+
}, props));
|
|
91
|
+
};
|
|
92
|
+
export var Priestley = function(props) {
|
|
93
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
94
|
+
instance: new PriestleyClass()
|
|
95
|
+
}, props));
|
|
96
|
+
};
|
|
97
|
+
export var Radar = function(props) {
|
|
98
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
99
|
+
instance: new RadarClass()
|
|
100
|
+
}, props));
|
|
101
|
+
};
|
|
102
|
+
export var RadialMatrix = function(props) {
|
|
103
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
104
|
+
instance: new RadialMatrixClass()
|
|
105
|
+
}, props));
|
|
106
|
+
};
|
|
107
|
+
export var Rings = function(props) {
|
|
108
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
109
|
+
instance: new RingsClass()
|
|
110
|
+
}, props));
|
|
111
|
+
};
|
|
112
|
+
export var Sankey = function(props) {
|
|
113
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
114
|
+
instance: new SankeyClass()
|
|
115
|
+
}, props));
|
|
116
|
+
};
|
|
117
|
+
export var StackedArea = function(props) {
|
|
118
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
119
|
+
instance: new StackedAreaClass()
|
|
120
|
+
}, props));
|
|
121
|
+
};
|
|
122
|
+
export var Tree = function(props) {
|
|
123
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
124
|
+
instance: new TreeClass()
|
|
125
|
+
}, props));
|
|
126
|
+
};
|
|
127
|
+
export var Treemap = function(props) {
|
|
128
|
+
return /*#__PURE__*/ React.createElement(Viz, _object_spread({
|
|
129
|
+
instance: new TreemapClass()
|
|
130
|
+
}, props));
|
|
131
|
+
};
|
|
132
|
+
export { default as D3plusContext } from "./src/D3plusContext.jsx";
|
package/es/src/Viz.jsx
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React, { useContext, useEffect, useRef } from "react";
|
|
2
|
+
import { assign } from "@d3plus/dom";
|
|
3
|
+
import D3plusContext from "./D3plusContext.jsx";
|
|
4
|
+
/**
|
|
5
|
+
@function Viz
|
|
6
|
+
@param {Object} config An object containing method/value pairs to be passed to the visualization's .config( ) method.
|
|
7
|
+
@param {String} [className = "viz"] The class attribute value used for the root/wrapper <div> element.
|
|
8
|
+
@param {Function} [callback] A function to be invoked at the end of each render cycle (passed directly to the render method).
|
|
9
|
+
*/ export default function(param) {
|
|
10
|
+
var callback = param.callback, _param_className = param.className, className = _param_className === void 0 ? "viz" : _param_className, config = param.config, instance = param.instance;
|
|
11
|
+
var forceUpdate = config.forceUpdate;
|
|
12
|
+
var globalConfig = useContext(D3plusContext);
|
|
13
|
+
var container = useRef(null);
|
|
14
|
+
useEffect(function() {
|
|
15
|
+
if (container.current) {
|
|
16
|
+
var c = assign({
|
|
17
|
+
select: container.current
|
|
18
|
+
}, globalConfig, config);
|
|
19
|
+
instance.config(c);
|
|
20
|
+
[
|
|
21
|
+
"data",
|
|
22
|
+
"links",
|
|
23
|
+
"nodes",
|
|
24
|
+
"topojson"
|
|
25
|
+
].forEach(function(method) {
|
|
26
|
+
if (c["".concat(method, "Format")] && c[method]) {
|
|
27
|
+
instance[method](c[method], c["".concat(method, "Format")]);
|
|
28
|
+
delete c["".concat(method, "Format")];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
instance.render(callback);
|
|
32
|
+
}
|
|
33
|
+
}, forceUpdate ? undefined : [
|
|
34
|
+
JSON.stringify(globalConfig),
|
|
35
|
+
JSON.stringify(config)
|
|
36
|
+
]);
|
|
37
|
+
return /*#__PURE__*/ React.createElement("div", {
|
|
38
|
+
className: className,
|
|
39
|
+
ref: container
|
|
40
|
+
});
|
|
41
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@d3plus/react",
|
|
3
|
+
"version": "3.0.0-alpha.0",
|
|
4
|
+
"description": "React components for d3plus visualizations.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": "./es/index.jsx",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=18"
|
|
10
|
+
},
|
|
11
|
+
"sideEffects": false,
|
|
12
|
+
"files": [
|
|
13
|
+
"es"
|
|
14
|
+
],
|
|
15
|
+
"homepage": "https://d3plus.org",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/d3plus/d3plus.git",
|
|
19
|
+
"directory": "packages/react"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"react",
|
|
23
|
+
"d3",
|
|
24
|
+
"d3plus",
|
|
25
|
+
"data",
|
|
26
|
+
"visualization"
|
|
27
|
+
],
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build:esm": "node ../../scripts/build-esm.js",
|
|
30
|
+
"dev": "node ../../scripts/dev.js",
|
|
31
|
+
"test": "eslint"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@d3plus/core": "3.0.0-alpha.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@mantine/core": "^7.8.1",
|
|
38
|
+
"@mantine/hooks": "^7.8.1",
|
|
39
|
+
"@types/react": "^18.2.79",
|
|
40
|
+
"@types/react-dom": "^18.2.25",
|
|
41
|
+
"@vitejs/plugin-react": "^4.2.1",
|
|
42
|
+
"eslint-plugin-react": "^7.37.4",
|
|
43
|
+
"prop-types": "^15.8.1",
|
|
44
|
+
"react": "^18.2.0",
|
|
45
|
+
"react-dom": "^18.2.0",
|
|
46
|
+
"react-transition-group": "^4.4.5",
|
|
47
|
+
"vite": "^5.2.10"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"react": "^18.2.0"
|
|
51
|
+
}
|
|
52
|
+
}
|