@recharts/devtools 0.0.2 → 0.0.3

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.
Files changed (35) hide show
  1. package/dist/src/components/RechartsDevtools.d.ts +2 -0
  2. package/dist/src/components/RechartsDevtools.js +80 -0
  3. package/dist/src/components/useEventDispatch.d.ts +1 -0
  4. package/dist/src/components/useEventDispatch.js +14 -0
  5. package/dist/src/constants.d.ts +1 -0
  6. package/dist/src/constants.js +4 -0
  7. package/dist/src/index.d.ts +2 -0
  8. package/dist/src/index.js +2 -0
  9. package/dist/src/inspectors/ActiveTooltipLabelInspector.d.ts +2 -0
  10. package/dist/src/inspectors/ActiveTooltipLabelInspector.js +18 -0
  11. package/dist/src/inspectors/ChartDimensionInspector.d.ts +2 -0
  12. package/dist/src/inspectors/ChartDimensionInspector.js +24 -0
  13. package/dist/src/inspectors/MarginInspector.d.ts +2 -0
  14. package/dist/src/inspectors/MarginInspector.js +43 -0
  15. package/dist/src/inspectors/OffsetInspector.d.ts +2 -0
  16. package/dist/src/inspectors/OffsetInspector.js +45 -0
  17. package/dist/src/inspectors/PlotAreaInspector.d.ts +2 -0
  18. package/dist/src/inspectors/PlotAreaInspector.js +36 -0
  19. package/dist/src/inspectors/UseActiveTooltipDataPointsInspector.d.ts +2 -0
  20. package/dist/src/inspectors/UseActiveTooltipDataPointsInspector.js +18 -0
  21. package/dist/src/inspectors/XAxisDomainInspector.d.ts +2 -0
  22. package/dist/src/inspectors/XAxisDomainInspector.js +18 -0
  23. package/dist/src/inspectors/YAxisDomainInspector.d.ts +2 -0
  24. package/dist/src/inspectors/YAxisDomainInspector.js +18 -0
  25. package/dist/src/inspectors/generic/ArrayInspector.d.ts +5 -0
  26. package/dist/src/inspectors/generic/ArrayInspector.js +63 -0
  27. package/dist/src/inspectors/generic/ObjectInspector.d.ts +7 -0
  28. package/dist/src/inspectors/generic/ObjectInspector.js +77 -0
  29. package/dist/src/inspectors/generic/PrimitiveInspector.d.ts +5 -0
  30. package/dist/src/inspectors/generic/PrimitiveInspector.js +15 -0
  31. package/dist/src/inspectors/utils/SvgDimensionShower.d.ts +14 -0
  32. package/dist/src/inspectors/utils/SvgDimensionShower.js +66 -0
  33. package/dist/src/types.d.ts +5 -0
  34. package/dist/src/types.js +2 -0
  35. package/package.json +43 -33
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const RechartsDevtools: () => React.JSX.Element | null;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.RechartsDevtools = void 0;
37
+ const react_1 = __importStar(require("react"));
38
+ const react_dom_1 = require("react-dom");
39
+ const constants_1 = require("../constants");
40
+ const ChartDimensionInspector_1 = require("../inspectors/ChartDimensionInspector");
41
+ const MarginInspector_1 = require("../inspectors/MarginInspector");
42
+ const OffsetInspector_1 = require("../inspectors/OffsetInspector");
43
+ const PlotAreaInspector_1 = require("../inspectors/PlotAreaInspector");
44
+ const UseActiveTooltipDataPointsInspector_1 = require("../inspectors/UseActiveTooltipDataPointsInspector");
45
+ const XAxisDomainInspector_1 = require("../inspectors/XAxisDomainInspector");
46
+ const YAxisDomainInspector_1 = require("../inspectors/YAxisDomainInspector");
47
+ const ActiveTooltipLabelInspector_1 = require("../inspectors/ActiveTooltipLabelInspector");
48
+ const INSPECTORS = {
49
+ 'useChartWidth | useChartHeight': ChartDimensionInspector_1.ChartDimensionInspector,
50
+ useMargin: MarginInspector_1.MarginInspector,
51
+ useOffset: OffsetInspector_1.OffsetInspector,
52
+ usePlotArea: PlotAreaInspector_1.PlotAreaInspector,
53
+ useActiveTooltipDataPoints: UseActiveTooltipDataPointsInspector_1.UseActiveTooltipDataPointsInspector,
54
+ useXAxisDomain: XAxisDomainInspector_1.XAxisDomainInspector,
55
+ useYAxisDomain: YAxisDomainInspector_1.YAxisDomainInspector,
56
+ useActiveTooltipLabel: ActiveTooltipLabelInspector_1.ActiveTooltipLabelInspector,
57
+ };
58
+ const RechartsDevtools = () => {
59
+ const container = document.getElementById(constants_1.RECHARTS_DEVTOOLS_PORTAL_ID);
60
+ const [selectedInspector, setSelectedInspector] = (0, react_1.useState)('useChartWidth | useChartHeight');
61
+ const [isOverlayEnabled, setIsOverlayEnabled] = (0, react_1.useState)(true);
62
+ if (!container) {
63
+ return null;
64
+ }
65
+ const { Inspector, Overlay } = INSPECTORS[selectedInspector];
66
+ return (react_1.default.createElement(react_1.default.Fragment, null,
67
+ Overlay && isOverlayEnabled && react_1.default.createElement(Overlay, null),
68
+ (0, react_dom_1.createPortal)(react_1.default.createElement("div", { className: "recharts-devtools", style: { fontFamily: 'monospace', fontSize: '12px' } },
69
+ react_1.default.createElement("div", { style: { marginBottom: '10px', paddingBottom: '10px', borderBottom: '1px solid #ccc' } },
70
+ react_1.default.createElement("div", { style: { display: 'flex', alignItems: 'center', marginBottom: '4px', gap: '8px' } },
71
+ react_1.default.createElement("label", null, "Inspect Hook:"),
72
+ react_1.default.createElement("select", { value: selectedInspector, onChange: (e) => setSelectedInspector(e.target.value), style: { padding: '4px' } }, Object.keys(INSPECTORS).map((key) => (react_1.default.createElement("option", { key: key, value: key }, key)))),
73
+ Overlay && (react_1.default.createElement("div", { style: { marginTop: '4px' } },
74
+ react_1.default.createElement("label", { style: { cursor: 'pointer', display: 'flex', alignItems: 'center' } },
75
+ react_1.default.createElement("input", { type: "checkbox", checked: isOverlayEnabled, onChange: (e) => setIsOverlayEnabled(e.target.checked), style: { marginRight: '4px' } }),
76
+ "Show Overlay on chart"))))),
77
+ react_1.default.createElement("div", { style: { padding: '10px 0' } },
78
+ react_1.default.createElement(Inspector, null))), container)));
79
+ };
80
+ exports.RechartsDevtools = RechartsDevtools;
@@ -0,0 +1 @@
1
+ export declare function useEventDispatch(detail: unknown): void;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useEventDispatch = useEventDispatch;
4
+ const react_1 = require("react");
5
+ const constants_1 = require("../constants");
6
+ function useEventDispatch(detail) {
7
+ (0, react_1.useEffect)(() => {
8
+ const container = document.getElementById(constants_1.RECHARTS_DEVTOOLS_PORTAL_ID);
9
+ if (!container)
10
+ return;
11
+ const event = new CustomEvent('recharts-devtools-change', { detail });
12
+ container.dispatchEvent(event);
13
+ }, [detail]);
14
+ }
@@ -0,0 +1 @@
1
+ export declare const RECHARTS_DEVTOOLS_PORTAL_ID = "recharts-devtools-portal";
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RECHARTS_DEVTOOLS_PORTAL_ID = void 0;
4
+ exports.RECHARTS_DEVTOOLS_PORTAL_ID = 'recharts-devtools-portal';
@@ -1,2 +1,4 @@
1
1
  export * from './random';
2
2
  export * from './generateMockData';
3
+ export * from './components/RechartsDevtools';
4
+ export * from './constants';
package/dist/src/index.js CHANGED
@@ -16,3 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./random"), exports);
18
18
  __exportStar(require("./generateMockData"), exports);
19
+ __exportStar(require("./components/RechartsDevtools"), exports);
20
+ __exportStar(require("./constants"), exports);
@@ -0,0 +1,2 @@
1
+ import { InspectorDef } from '../types';
2
+ export declare const ActiveTooltipLabelInspector: InspectorDef;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ActiveTooltipLabelInspector = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const recharts_1 = require("recharts");
9
+ const PrimitiveInspector_1 = require("./generic/PrimitiveInspector");
10
+ const useEventDispatch_1 = require("../components/useEventDispatch");
11
+ const Inspector = () => {
12
+ const activeLabel = (0, recharts_1.useActiveTooltipLabel)();
13
+ (0, useEventDispatch_1.useEventDispatch)(activeLabel);
14
+ return react_1.default.createElement(PrimitiveInspector_1.PrimitiveInspector, { value: activeLabel });
15
+ };
16
+ exports.ActiveTooltipLabelInspector = {
17
+ Inspector,
18
+ };
@@ -0,0 +1,2 @@
1
+ import { InspectorDef } from '../types';
2
+ export declare const ChartDimensionInspector: InspectorDef;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ChartDimensionInspector = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const recharts_1 = require("recharts");
9
+ const useEventDispatch_1 = require("../components/useEventDispatch");
10
+ const Inspector = () => {
11
+ const chartWidth = (0, recharts_1.useChartWidth)();
12
+ const chartHeight = (0, recharts_1.useChartHeight)();
13
+ (0, useEventDispatch_1.useEventDispatch)({ useChartWidth: chartWidth, useChartHeight: chartHeight });
14
+ return (react_1.default.createElement("div", null,
15
+ react_1.default.createElement("div", null,
16
+ "useChartWidth: ",
17
+ chartWidth),
18
+ react_1.default.createElement("div", null,
19
+ "useChartHeight: ",
20
+ chartHeight)));
21
+ };
22
+ exports.ChartDimensionInspector = {
23
+ Inspector,
24
+ };
@@ -0,0 +1,2 @@
1
+ import { InspectorDef } from '../types';
2
+ export declare const MarginInspector: InspectorDef;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.MarginInspector = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const recharts_1 = require("recharts");
9
+ const SvgDimensionShower_1 = require("./utils/SvgDimensionShower");
10
+ const ObjectInspector_1 = require("./generic/ObjectInspector");
11
+ const Overlay = () => {
12
+ const margin = (0, recharts_1.useMargin)();
13
+ const height = (0, recharts_1.useChartHeight)();
14
+ const width = (0, recharts_1.useChartWidth)();
15
+ if (margin == null || width == null || height == null) {
16
+ return null;
17
+ }
18
+ return (react_1.default.createElement(react_1.default.Fragment, null,
19
+ react_1.default.createElement(SvgDimensionShower_1.SvgDimensionShower, { width: margin.left, height: height, labels: {
20
+ background: 'Left',
21
+ horizontal: 'useMargin.left',
22
+ } }),
23
+ react_1.default.createElement(SvgDimensionShower_1.SvgDimensionShower, { width: margin.right, x: width - margin.right, height: height, labels: {
24
+ background: 'Right',
25
+ horizontal: 'useMargin.right',
26
+ } }),
27
+ react_1.default.createElement(SvgDimensionShower_1.SvgDimensionShower, { width: width, height: margin.top, labels: {
28
+ background: 'Top',
29
+ vertical: 'useMargin.top',
30
+ } }),
31
+ react_1.default.createElement(SvgDimensionShower_1.SvgDimensionShower, { width: width, height: margin.bottom, y: height - margin.bottom, labels: {
32
+ background: 'Bottom',
33
+ vertical: 'useMargin.bottom',
34
+ } })));
35
+ };
36
+ const Inspector = () => {
37
+ const margin = (0, recharts_1.useMargin)();
38
+ return react_1.default.createElement(ObjectInspector_1.ObjectInspector, { obj: margin });
39
+ };
40
+ exports.MarginInspector = {
41
+ Overlay,
42
+ Inspector,
43
+ };
@@ -0,0 +1,2 @@
1
+ import { InspectorDef } from '../types';
2
+ export declare const OffsetInspector: InspectorDef;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.OffsetInspector = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const recharts_1 = require("recharts");
9
+ const SvgDimensionShower_1 = require("./utils/SvgDimensionShower");
10
+ const ObjectInspector_1 = require("./generic/ObjectInspector");
11
+ const useEventDispatch_1 = require("../components/useEventDispatch");
12
+ const Overlay = () => {
13
+ const offset = (0, recharts_1.useOffset)();
14
+ const height = (0, recharts_1.useChartHeight)();
15
+ const width = (0, recharts_1.useChartWidth)();
16
+ if (offset == null || width == null || height == null) {
17
+ return null;
18
+ }
19
+ return (react_1.default.createElement(react_1.default.Fragment, null,
20
+ react_1.default.createElement(SvgDimensionShower_1.SvgDimensionShower, { width: offset.left, height: height, labels: {
21
+ background: 'Left',
22
+ horizontal: 'useOffset.left',
23
+ } }),
24
+ react_1.default.createElement(SvgDimensionShower_1.SvgDimensionShower, { width: offset.right, x: width - offset.right, height: height, labels: {
25
+ background: 'Right',
26
+ horizontal: 'useOffset.right',
27
+ } }),
28
+ react_1.default.createElement(SvgDimensionShower_1.SvgDimensionShower, { width: width, height: offset.top, labels: {
29
+ background: 'Top',
30
+ vertical: 'useOffset.top',
31
+ } }),
32
+ react_1.default.createElement(SvgDimensionShower_1.SvgDimensionShower, { width: width, height: offset.bottom, y: height - offset.bottom, labels: {
33
+ background: 'Bottom',
34
+ vertical: 'useOffset.bottom',
35
+ } })));
36
+ };
37
+ const Inspector = () => {
38
+ const offset = (0, recharts_1.useOffset)();
39
+ (0, useEventDispatch_1.useEventDispatch)(offset);
40
+ return react_1.default.createElement(ObjectInspector_1.ObjectInspector, { obj: offset });
41
+ };
42
+ exports.OffsetInspector = {
43
+ Overlay,
44
+ Inspector,
45
+ };
@@ -0,0 +1,2 @@
1
+ import { InspectorDef } from '../types';
2
+ export declare const PlotAreaInspector: InspectorDef;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PlotAreaInspector = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const recharts_1 = require("recharts");
9
+ const SvgDimensionShower_1 = require("./utils/SvgDimensionShower");
10
+ const ObjectInspector_1 = require("./generic/ObjectInspector");
11
+ const useEventDispatch_1 = require("../components/useEventDispatch");
12
+ const Overlay = () => {
13
+ const plotArea = (0, recharts_1.usePlotArea)();
14
+ const width = (0, recharts_1.useChartWidth)();
15
+ const height = (0, recharts_1.useChartHeight)();
16
+ if (plotArea == null || width == null || height == null) {
17
+ return null;
18
+ }
19
+ return (react_1.default.createElement(react_1.default.Fragment, null,
20
+ react_1.default.createElement(SvgDimensionShower_1.SvgDimensionShower, { width: width, height: plotArea.y, labels: { background: 'y', vertical: 'usePlotArea.y' } }),
21
+ react_1.default.createElement(SvgDimensionShower_1.SvgDimensionShower, { width: plotArea.x, height: height, labels: { background: 'x', horizontal: 'usePlotArea.x' } }),
22
+ react_1.default.createElement(SvgDimensionShower_1.SvgDimensionShower, { x: plotArea.x, y: plotArea.y, width: plotArea.width, height: plotArea.height, labels: {
23
+ background: 'Plot area',
24
+ horizontal: 'usePlotArea.width',
25
+ vertical: 'usePlotArea.height',
26
+ } })));
27
+ };
28
+ const Inspector = () => {
29
+ const plotArea = (0, recharts_1.usePlotArea)();
30
+ (0, useEventDispatch_1.useEventDispatch)(plotArea);
31
+ return react_1.default.createElement(ObjectInspector_1.ObjectInspector, { obj: plotArea });
32
+ };
33
+ exports.PlotAreaInspector = {
34
+ Overlay,
35
+ Inspector,
36
+ };
@@ -0,0 +1,2 @@
1
+ import { InspectorDef } from '../types';
2
+ export declare const UseActiveTooltipDataPointsInspector: InspectorDef;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.UseActiveTooltipDataPointsInspector = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const recharts_1 = require("recharts");
9
+ const ArrayInspector_1 = require("./generic/ArrayInspector");
10
+ const useEventDispatch_1 = require("../components/useEventDispatch");
11
+ const Inspector = () => {
12
+ const dataPoints = (0, recharts_1.useActiveTooltipDataPoints)();
13
+ (0, useEventDispatch_1.useEventDispatch)(dataPoints);
14
+ return react_1.default.createElement(ArrayInspector_1.ArrayInspector, { arr: dataPoints, expandByDefault: true });
15
+ };
16
+ exports.UseActiveTooltipDataPointsInspector = {
17
+ Inspector,
18
+ };
@@ -0,0 +1,2 @@
1
+ import { InspectorDef } from '../types';
2
+ export declare const XAxisDomainInspector: InspectorDef;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.XAxisDomainInspector = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const recharts_1 = require("recharts");
9
+ const ArrayInspector_1 = require("./generic/ArrayInspector");
10
+ const useEventDispatch_1 = require("../components/useEventDispatch");
11
+ const Inspector = () => {
12
+ const xAxisDomain = (0, recharts_1.useXAxisDomain)();
13
+ (0, useEventDispatch_1.useEventDispatch)(xAxisDomain);
14
+ return react_1.default.createElement(ArrayInspector_1.ArrayInspector, { arr: xAxisDomain });
15
+ };
16
+ exports.XAxisDomainInspector = {
17
+ Inspector,
18
+ };
@@ -0,0 +1,2 @@
1
+ import { InspectorDef } from '../types';
2
+ export declare const YAxisDomainInspector: InspectorDef;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.YAxisDomainInspector = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const recharts_1 = require("recharts");
9
+ const ArrayInspector_1 = require("./generic/ArrayInspector");
10
+ const useEventDispatch_1 = require("../components/useEventDispatch");
11
+ const Inspector = () => {
12
+ const yAxisDomain = (0, recharts_1.useYAxisDomain)();
13
+ (0, useEventDispatch_1.useEventDispatch)(yAxisDomain);
14
+ return react_1.default.createElement(ArrayInspector_1.ArrayInspector, { arr: yAxisDomain });
15
+ };
16
+ exports.YAxisDomainInspector = {
17
+ Inspector,
18
+ };
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ export declare function ArrayInspector({ arr, expandByDefault, }: {
3
+ arr: ReadonlyArray<unknown> | undefined;
4
+ expandByDefault?: boolean;
5
+ }): React.JSX.Element;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ArrayInspector = ArrayInspector;
37
+ const react_1 = __importStar(require("react"));
38
+ const PrimitiveInspector_1 = require("./PrimitiveInspector");
39
+ function ArrayOfObjectsInspector({ arr, expand }) {
40
+ if (!expand) {
41
+ return react_1.default.createElement("code", null,
42
+ "Array(",
43
+ arr.length,
44
+ ")");
45
+ }
46
+ return (react_1.default.createElement("pre", null,
47
+ react_1.default.createElement("code", null,
48
+ "[",
49
+ arr.map(PrimitiveInspector_1.serializePrimitive).join(',\n'),
50
+ "]")));
51
+ }
52
+ function ArrayInspector({ arr, expandByDefault, }) {
53
+ if (arr == null) {
54
+ return react_1.default.createElement(PrimitiveInspector_1.PrimitiveInspector, { value: arr });
55
+ }
56
+ const length = arr.length ?? 0;
57
+ const typeofArr = typeof arr[0];
58
+ const shouldExpandByDefault = expandByDefault || length <= 1 || (typeofArr !== 'object' && typeofArr !== 'function');
59
+ const [expand, setExpand] = (0, react_1.useState)(shouldExpandByDefault);
60
+ return (react_1.default.createElement(react_1.default.Fragment, null,
61
+ expand ? (react_1.default.createElement("button", { type: "button", onClick: () => setExpand(false) }, "Collapse")) : (react_1.default.createElement("button", { type: "button", onClick: () => setExpand(true) }, "Expand")),
62
+ react_1.default.createElement(ArrayOfObjectsInspector, { arr: arr, expand: expand })));
63
+ }
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ export declare function ValueInspector({ value }: {
3
+ value: unknown;
4
+ }): React.JSX.Element;
5
+ export declare function ObjectInspector({ obj }: {
6
+ obj: Record<string, any> | undefined;
7
+ }): React.JSX.Element;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ValueInspector = ValueInspector;
37
+ exports.ObjectInspector = ObjectInspector;
38
+ const react_1 = __importStar(require("react"));
39
+ const PrimitiveInspector_1 = require("./PrimitiveInspector");
40
+ /*
41
+ * Values that are expanded by default:
42
+ * - primitives
43
+ * - objects with 0 or 1 or 2 keys
44
+ * - arrays with 0 or 1 elements
45
+ */
46
+ function shouldExpandByDefault(value) {
47
+ if (Array.isArray(value)) {
48
+ return value.length <= 1;
49
+ }
50
+ if (value != null && typeof value === 'object') {
51
+ return Object.keys(value).length <= 2;
52
+ }
53
+ return true;
54
+ }
55
+ function NotPrimitiveInspector({ value }) {
56
+ const [expand, setExpand] = (0, react_1.useState)(shouldExpandByDefault(value));
57
+ return (react_1.default.createElement(react_1.default.Fragment, null,
58
+ expand ? (react_1.default.createElement("button", { type: "button", onClick: () => setExpand(false) }, "Collapse")) : (react_1.default.createElement("button", { type: "button", onClick: () => setExpand(true) }, "Expand")),
59
+ expand ? (react_1.default.createElement("pre", null,
60
+ react_1.default.createElement("code", null, JSON.stringify(value, null, 2)))) : (react_1.default.createElement("code", null, typeof value))));
61
+ }
62
+ function ValueInspector({ value }) {
63
+ if (value == null || typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean') {
64
+ return react_1.default.createElement(PrimitiveInspector_1.PrimitiveInspector, { value: value });
65
+ }
66
+ return react_1.default.createElement(NotPrimitiveInspector, { value: value });
67
+ }
68
+ function ObjectInspector({ obj }) {
69
+ if (obj == null) {
70
+ return react_1.default.createElement("code", null, JSON.stringify(obj));
71
+ }
72
+ const keys = Object.keys(obj);
73
+ return (react_1.default.createElement("div", null, keys.map(key => (react_1.default.createElement("div", { key: key },
74
+ react_1.default.createElement("strong", null, key),
75
+ ": ",
76
+ react_1.default.createElement(ValueInspector, { value: obj[key] }))))));
77
+ }
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ export declare function serializePrimitive(value: unknown): string;
3
+ export declare function PrimitiveInspector({ value }: {
4
+ value: unknown;
5
+ }): React.JSX.Element;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.serializePrimitive = serializePrimitive;
7
+ exports.PrimitiveInspector = PrimitiveInspector;
8
+ const react_1 = __importDefault(require("react"));
9
+ function serializePrimitive(value) {
10
+ return value === undefined ? 'undefined' : JSON.stringify(value, null, 2);
11
+ }
12
+ function PrimitiveInspector({ value }) {
13
+ const str = serializePrimitive(value);
14
+ return react_1.default.createElement("code", null, str);
15
+ }
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ type Labels = {
3
+ background: string;
4
+ horizontal?: string;
5
+ vertical?: string;
6
+ };
7
+ export declare function SvgDimensionShower({ x, y, width, height, labels, }: {
8
+ x?: number;
9
+ y?: number;
10
+ width: number;
11
+ height: number;
12
+ labels: Labels;
13
+ }): React.JSX.Element;
14
+ export {};
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SvgDimensionShower = SvgDimensionShower;
7
+ const react_1 = __importDefault(require("react"));
8
+ /**
9
+ * Renders a line with arrows on left and right.
10
+ * @constructor
11
+ */
12
+ function HorizontalLineWithArrows({ x1, x2, y, label, stroke = 'black', }) {
13
+ const strokeWidth = 2;
14
+ const arrowSize = 7;
15
+ const width = x2 - x1;
16
+ return (react_1.default.createElement(react_1.default.Fragment, null,
17
+ react_1.default.createElement("line", { x1: x1, y1: y, x2: x2, y2: y, stroke: stroke, strokeWidth: strokeWidth }),
18
+ react_1.default.createElement("line", { x1: x1, y1: y, x2: x1 + arrowSize, y2: y - arrowSize, stroke: stroke, strokeWidth: strokeWidth }),
19
+ react_1.default.createElement("line", { x1: x1, y1: y, x2: x1 + arrowSize, y2: y + arrowSize, stroke: stroke, strokeWidth: strokeWidth }),
20
+ react_1.default.createElement("line", { x1: x2, y1: y, x2: x2 - arrowSize, y2: y - arrowSize, stroke: stroke, strokeWidth: strokeWidth }),
21
+ react_1.default.createElement("line", { x1: x2, y1: y, x2: x2 - arrowSize, y2: y + arrowSize, stroke: stroke, strokeWidth: strokeWidth }),
22
+ react_1.default.createElement("text", { x: width * 0.9, y: y + 8, textAnchor: "end", dominantBaseline: "hanging", stroke: "red" }, label)));
23
+ }
24
+ function Background({ width, height, label, }) {
25
+ const patternId = `pattern+${label.replace(/\s+/g, '-')}`;
26
+ return (react_1.default.createElement("svg", { width: width, height: height, style: { position: 'absolute', top: 0, left: 0 } },
27
+ react_1.default.createElement("defs", null,
28
+ react_1.default.createElement("pattern", { id: patternId, x: 0, y: 0, width: 120, height: 50, patternUnits: "userSpaceOnUse", patternTransform: "rotate(30)" },
29
+ react_1.default.createElement("text", { x: 0, y: 10, fontSize: 24, stroke: "#eee", fill: "#eee", dominantBaseline: "hanging" }, label.toUpperCase()))),
30
+ react_1.default.createElement("rect", { x: 0, y: 0, width: width, height: height, fill: `url(#${patternId})` })));
31
+ }
32
+ function VerticalLineWithArrows({ x, y1, y2, label, stroke = 'black', }) {
33
+ const strokeWidth = 2;
34
+ const arrowSize = 7;
35
+ const height = y2 - y1;
36
+ return (react_1.default.createElement(react_1.default.Fragment, null,
37
+ react_1.default.createElement("line", { x1: x, y1: y1, x2: x, y2: y2, stroke: stroke, strokeWidth: strokeWidth }),
38
+ react_1.default.createElement("line", { x1: x, y1: y1, x2: x - arrowSize, y2: y1 + arrowSize, stroke: stroke, strokeWidth: strokeWidth }),
39
+ react_1.default.createElement("line", { x1: x, y1: y1, x2: x + arrowSize, y2: y1 + arrowSize, stroke: stroke, strokeWidth: strokeWidth }),
40
+ react_1.default.createElement("line", { x1: x, y1: y2, x2: x - arrowSize, y2: y2 - arrowSize, stroke: stroke, strokeWidth: strokeWidth }),
41
+ react_1.default.createElement("line", { x1: x, y1: y2, x2: x + arrowSize, y2: y2 - arrowSize, stroke: stroke, strokeWidth: strokeWidth }),
42
+ react_1.default.createElement("text", { x: x + 8, y: height * 0.7, textAnchor: "start", dominantBaseline: "middle", stroke: "blue" }, label)));
43
+ }
44
+ /**
45
+ * Creates a label for the horizontal line.
46
+ * It will trim information to save space if the width is too small.
47
+ * @param width number of pixels to display
48
+ * @param label description of the width
49
+ * @return the label to display
50
+ */
51
+ function makeHorizontalLabel(width, label) {
52
+ if (width < 50) {
53
+ return String(width);
54
+ }
55
+ if (width < 100) {
56
+ return `${width}px`;
57
+ }
58
+ return `${label}: ${width}px`;
59
+ }
60
+ function SvgDimensionShower({ x = 0, y = 0, width, height, labels, }) {
61
+ return (react_1.default.createElement("svg", { width: width, height: height, x: x, y: y, style: { pointerEvents: 'none' } },
62
+ react_1.default.createElement(Background, { width: width, height: height, label: labels.background }),
63
+ react_1.default.createElement("rect", { x: 0, y: 0, width: width, height: height, fill: "none", stroke: "green", strokeWidth: 5, strokeDasharray: "3 3" }),
64
+ labels.horizontal && (react_1.default.createElement(HorizontalLineWithArrows, { x1: 0, y: height * 0.15, x2: width, stroke: "red", label: makeHorizontalLabel(width, labels.horizontal) })),
65
+ labels.vertical && (react_1.default.createElement(VerticalLineWithArrows, { x: width * 0.1, y1: 0, y2: height, stroke: "blue", label: `${labels.vertical}: ${height}px` }))));
66
+ }
@@ -0,0 +1,5 @@
1
+ import { ComponentType } from 'react';
2
+ export type InspectorDef = {
3
+ Overlay?: ComponentType;
4
+ Inspector: ComponentType;
5
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,39 +1,49 @@
1
1
  {
2
- "name": "@recharts/devtools",
3
- "publishConfig": {
4
- "access": "public"
5
- },
6
- "version": "0.0.2",
7
- "description": "Devtools and helper functions for Recharts",
8
- "main": "dist/src/index.js",
9
- "types": "dist/src/index.d.ts",
10
- "files": [
11
- "dist"
12
- ],
2
+ "name": "@recharts/devtools",
3
+ "publishConfig": {
4
+ "access": "public"
5
+ },
6
+ "version": "0.0.3",
7
+ "description": "Devtools and helper functions for Recharts",
8
+ "main": "dist/src/index.js",
9
+ "types": "dist/src/index.d.ts",
10
+ "files": [
11
+ "dist"
12
+ ],
13
13
  "repository": {
14
14
  "url": "https://github.com/recharts/devtools"
15
15
  },
16
16
  "scripts": {
17
- "build": "tsc",
18
- "test": "vitest run",
19
- "lint": "eslint src test --ext .ts",
20
- "format": "prettier --write \"{src,test}/**/*.ts\"",
21
- "release": "node ./scripts/publish.js"
22
- },
23
- "keywords": [
24
- "recharts",
25
- "devtools",
26
- "charts"
27
- ],
28
- "author": "Recharts Group",
29
- "license": "MIT",
30
- "devDependencies": {
31
- "@types/node": "^20.0.0",
32
- "@typescript-eslint/eslint-plugin": "^6.0.0",
33
- "@typescript-eslint/parser": "^6.0.0",
34
- "eslint": "^8.0.0",
35
- "prettier": "^3.0.0",
36
- "typescript": "^5.0.0",
37
- "vitest": "^1.0.0"
38
- }
17
+ "build": "tsc",
18
+ "test": "vitest run",
19
+ "lint": "eslint src test --ext .ts",
20
+ "format": "prettier --write \"{src,test}/**/*.ts\"",
21
+ "release": "node ./scripts/publish.js"
22
+ },
23
+ "keywords": [
24
+ "recharts",
25
+ "devtools",
26
+ "charts"
27
+ ],
28
+ "author": "Recharts Group",
29
+ "license": "MIT",
30
+ "devDependencies": {
31
+ "@types/node": "^20.0.0",
32
+ "@types/react": "^18.0.0",
33
+ "@types/react-dom": "^18.0.0",
34
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
35
+ "@typescript-eslint/parser": "^6.0.0",
36
+ "eslint": "^8.0.0",
37
+ "prettier": "^3.0.0",
38
+ "typescript": "^5.0.0",
39
+ "vitest": "^1.0.0",
40
+ "react": "^19.0.0",
41
+ "react-dom": "^19.0.0",
42
+ "recharts": "latest"
43
+ },
44
+ "peerDependencies": {
45
+ "react": "^18.0.0 || ^19.0.0",
46
+ "react-dom": "^18.0.0 || ^19.0.0",
47
+ "recharts": "^3.3.0"
48
+ }
39
49
  }