canvasxpress-react 65.2.0 → 65.4.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/index.d.ts +34 -0
- package/index.js +29 -10
- package/package.json +3 -2
package/index.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Type definitions for canvasxpress-react
|
|
2
|
+
// Project: https://www.canvasxpress.org
|
|
3
|
+
// Definitions: https://github.com/neuhausi/canvasXpress-react
|
|
4
|
+
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import * as CanvasXpress from 'canvasxpress';
|
|
7
|
+
|
|
8
|
+
export = CanvasXpressReact;
|
|
9
|
+
|
|
10
|
+
interface CanvasXpressReactProps {
|
|
11
|
+
/** DOM id assigned to the rendered <canvas>. */
|
|
12
|
+
target: string;
|
|
13
|
+
/** CanvasXpress data object. */
|
|
14
|
+
data?: CanvasXpress.CXData;
|
|
15
|
+
/** CanvasXpress configuration. */
|
|
16
|
+
config?: CanvasXpress.CXConfig;
|
|
17
|
+
/** CanvasXpress event handlers. */
|
|
18
|
+
events?: CanvasXpress.CXEvents;
|
|
19
|
+
/** Canvas width in pixels (default 500). */
|
|
20
|
+
width?: number;
|
|
21
|
+
/** Canvas height in pixels (default 500). */
|
|
22
|
+
height?: number;
|
|
23
|
+
/** Enable responsive resizing (default false). */
|
|
24
|
+
responsive?: boolean;
|
|
25
|
+
/** Aspect ratio for responsive mode, e.g. "1:1" (default "1:1"). */
|
|
26
|
+
aspectratio?: string;
|
|
27
|
+
/** Receives the live CanvasXpress instance on mount, and `undefined` on unmount. */
|
|
28
|
+
onRef?: (instance: CanvasXpress.CanvasXpressInstance | undefined) => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
declare class CanvasXpressReact extends React.Component<CanvasXpressReactProps> {
|
|
32
|
+
/** The live CanvasXpress instance, available after mount. */
|
|
33
|
+
graph?: CanvasXpress.CanvasXpressInstance;
|
|
34
|
+
}
|
package/index.js
CHANGED
|
@@ -24,30 +24,49 @@ class CanvasXpressReact extends React.Component {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
shouldComponentUpdate(nextProps
|
|
28
|
-
//
|
|
29
|
-
|
|
27
|
+
shouldComponentUpdate(nextProps) {
|
|
28
|
+
//Re-render only when the incoming props differ from the CURRENT props.
|
|
29
|
+
//Comparing against the constructor snapshots (this.data/this.config) drifts
|
|
30
|
+
//after the first update, because those are never refreshed.
|
|
31
|
+
return nextProps.data !== this.props.data
|
|
32
|
+
|| nextProps.config !== this.props.config
|
|
33
|
+
|| nextProps.events !== this.props.events;
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
componentDidUpdate() {
|
|
33
|
-
//Update Graph Options & Data
|
|
34
|
-
this.graph
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
//Update Graph Options & Data. Bail out if the graph never mounted.
|
|
38
|
+
if (!this.graph) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
//resetConfig()/updateConfig() land in canvasxpress >= 65.4. Guard so an
|
|
42
|
+
//older library falls back to updateData's config-merge path instead of
|
|
43
|
+
//throwing on a missing method.
|
|
44
|
+
if (typeof this.graph.resetConfig === 'function' && typeof this.graph.updateConfig === 'function') {
|
|
45
|
+
this.graph.resetConfig();
|
|
46
|
+
//Second arg (n) = "do not draw": defer the redraw so only updateData below
|
|
47
|
+
//paints, avoiding a double render.
|
|
48
|
+
this.graph.updateConfig(this.props.config, true);
|
|
49
|
+
this.graph.updateData(this.props.data);
|
|
50
|
+
} else {
|
|
51
|
+
//Fallback: apply config alongside the data in a single redraw.
|
|
52
|
+
this.graph.updateData(this.props.data, true, false, this.props.config);
|
|
53
|
+
}
|
|
37
54
|
}
|
|
38
55
|
|
|
39
56
|
componentWillUnmount() {
|
|
40
57
|
//Destroy graph and remove reference
|
|
41
|
-
this.graph
|
|
58
|
+
if (this.graph) {
|
|
59
|
+
this.graph.destroy();
|
|
60
|
+
}
|
|
42
61
|
if (this.props.onRef) {
|
|
43
62
|
this.props.onRef(undefined);
|
|
44
63
|
}
|
|
45
64
|
}
|
|
46
65
|
|
|
47
66
|
render() {
|
|
48
|
-
return React.createElement('canvas', { id: this.target, width: this.width, height: this.height, 'data-responsive': this.responsive, 'data-aspectratio': this.
|
|
67
|
+
return React.createElement('canvas', { id: this.target, width: this.width, height: this.height, 'data-responsive': this.responsive, 'data-aspectratio': this.aspectRatio});
|
|
49
68
|
}
|
|
50
69
|
|
|
51
70
|
}
|
|
52
71
|
|
|
53
|
-
|
|
72
|
+
module.exports = CanvasXpressReact;
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "canvasxpress-react",
|
|
3
3
|
"main": "index.js",
|
|
4
|
+
"types": "index.d.ts",
|
|
4
5
|
"title": "CanvasXpress React",
|
|
5
|
-
"version": "65.
|
|
6
|
+
"version": "65.4.0",
|
|
6
7
|
"license": {
|
|
7
8
|
"type": "Dual licensing",
|
|
8
9
|
"url": "https://www.canvasxpress.org/docs/license.html"
|
|
@@ -28,6 +29,6 @@
|
|
|
28
29
|
},
|
|
29
30
|
"homepage": "https://github.com/neuhausi/canvasxpress#readme",
|
|
30
31
|
"dependencies": {
|
|
31
|
-
"canvasxpress": "^65.
|
|
32
|
+
"canvasxpress": "^65.4.0"
|
|
32
33
|
}
|
|
33
34
|
}
|