@recharts/devtools 0.0.2 → 0.0.4
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 +49 -22
- package/dist/src/components/RechartsDevtools.d.ts +2 -0
- package/dist/src/components/RechartsDevtools.js +65 -0
- package/dist/src/components/useEventDispatch.d.ts +1 -0
- package/dist/src/components/useEventDispatch.js +14 -0
- package/dist/src/constants.d.ts +1 -0
- package/dist/src/constants.js +4 -0
- package/dist/src/context/RechartsDevtoolsContext.d.ts +8 -0
- package/dist/src/context/RechartsDevtoolsContext.js +58 -0
- package/dist/src/hooks/useSessionStorageState.d.ts +7 -0
- package/dist/src/hooks/useSessionStorageState.js +31 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.js +3 -0
- package/dist/src/inspectors/ActiveTooltipLabelInspector.d.ts +2 -0
- package/dist/src/inspectors/ActiveTooltipLabelInspector.js +18 -0
- package/dist/src/inspectors/ChartDimensionInspector.d.ts +2 -0
- package/dist/src/inspectors/ChartDimensionInspector.js +24 -0
- package/dist/src/inspectors/MarginInspector.d.ts +2 -0
- package/dist/src/inspectors/MarginInspector.js +43 -0
- package/dist/src/inspectors/OffsetInspector.d.ts +2 -0
- package/dist/src/inspectors/OffsetInspector.js +45 -0
- package/dist/src/inspectors/PlotAreaInspector.d.ts +2 -0
- package/dist/src/inspectors/PlotAreaInspector.js +36 -0
- package/dist/src/inspectors/UseActiveTooltipDataPointsInspector.d.ts +2 -0
- package/dist/src/inspectors/UseActiveTooltipDataPointsInspector.js +18 -0
- package/dist/src/inspectors/XAxisDomainInspector.d.ts +2 -0
- package/dist/src/inspectors/XAxisDomainInspector.js +18 -0
- package/dist/src/inspectors/YAxisDomainInspector.d.ts +2 -0
- package/dist/src/inspectors/YAxisDomainInspector.js +18 -0
- package/dist/src/inspectors/generic/ArrayInspector.d.ts +5 -0
- package/dist/src/inspectors/generic/ArrayInspector.js +63 -0
- package/dist/src/inspectors/generic/ObjectInspector.d.ts +7 -0
- package/dist/src/inspectors/generic/ObjectInspector.js +77 -0
- package/dist/src/inspectors/generic/PrimitiveInspector.d.ts +5 -0
- package/dist/src/inspectors/generic/PrimitiveInspector.js +15 -0
- package/dist/src/inspectors/utils/SvgDimensionShower.d.ts +14 -0
- package/dist/src/inspectors/utils/SvgDimensionShower.js +66 -0
- package/dist/src/types.d.ts +5 -0
- package/dist/src/types.js +2 -0
- package/package.json +43 -33
package/README.md
CHANGED
|
@@ -1,39 +1,66 @@
|
|
|
1
1
|
# @recharts/devtools
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Intended for development and debugging purpose only. We won't stop you from using this in prod but also we won't support it. Expect breaking changes in every release.
|
|
3
|
+
Devtools for Recharts.
|
|
6
4
|
|
|
7
5
|
## Installation
|
|
8
6
|
|
|
9
7
|
```bash
|
|
10
|
-
npm install @recharts/devtools
|
|
8
|
+
npm install @recharts/devtools --save-dev
|
|
11
9
|
```
|
|
12
10
|
|
|
13
11
|
## Usage
|
|
14
12
|
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
### Basic Usage
|
|
14
|
+
|
|
15
|
+
Import the `RechartsDevtools` component and render it inside of your chart.
|
|
16
|
+
|
|
17
|
+
Add a div with specific ID where the devtools will render a portal.
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
```tsx
|
|
20
|
+
import { RechartsDevtools, RECHARTS_DEVTOOLS_PORTAL_ID } from '@recharts/devtools';
|
|
21
|
+
import { AreaChart } from 'recharts';
|
|
22
|
+
|
|
23
|
+
function App() {
|
|
24
|
+
return (
|
|
25
|
+
<article>
|
|
26
|
+
<AreaChart>
|
|
27
|
+
{/* The DevTools component reads state from inside of the chart */}
|
|
28
|
+
<RechartsDevtools />
|
|
29
|
+
</AreaChart>
|
|
30
|
+
{/* The Portal component renders the devtools UI, debugging information, hooks and other stuff */}
|
|
31
|
+
<div id={RECHARTS_DEVTOOLS_PORTAL_ID} />
|
|
32
|
+
</article>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
20
35
|
```
|
|
21
36
|
|
|
22
|
-
|
|
37
|
+
### Multiple Instances (Context Mode)
|
|
23
38
|
|
|
24
|
-
|
|
25
|
-
- `npm run test`: Run tests with Vitest
|
|
26
|
-
- `npm run lint`: Lint code
|
|
39
|
+
If you have multiple charts or devtools instances on the same page (e.g., in a documentation site with live editors), you should use the `RechartsDevtoolsContext` and `RechartsDevtoolsPortal` to ensure each devtools instance targets the correct location without ID conflicts.
|
|
27
40
|
|
|
28
|
-
|
|
41
|
+
1. Wrap your chart and editor/devtools area with `RechartsDevtoolsContext`. One context for one devtools.
|
|
42
|
+
2. Place `RechartsDevtoolsPortal` where you want the devtools UI to be rendered.
|
|
43
|
+
3. `RechartsDevtools` will automatically detect the context and render into the associated portal.
|
|
29
44
|
|
|
30
|
-
|
|
45
|
+
```tsx
|
|
46
|
+
import { RechartsDevtools, RechartsDevtoolsContext, RechartsDevtoolsPortal } from '@recharts/devtools';
|
|
47
|
+
import { AreaChart, LineChart } from 'recharts';
|
|
31
48
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
49
|
+
function EditorWithPreview() {
|
|
50
|
+
return (
|
|
51
|
+
<RechartsDevtoolsContext>
|
|
52
|
+
<AreaChart>
|
|
53
|
+
<RechartsDevtools />
|
|
54
|
+
</AreaChart>
|
|
55
|
+
<RechartsDevtoolsPortal />
|
|
56
|
+
</RechartsDevtoolsContext>
|
|
57
|
+
|
|
58
|
+
<RechartsDevtoolsContext>
|
|
59
|
+
<LineChart>
|
|
60
|
+
<RechartsDevtools />
|
|
61
|
+
</LineChart>
|
|
62
|
+
<RechartsDevtoolsPortal />
|
|
63
|
+
</RechartsDevtoolsContext>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
```
|
|
@@ -0,0 +1,65 @@
|
|
|
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.RechartsDevtools = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const react_dom_1 = require("react-dom");
|
|
9
|
+
const constants_1 = require("../constants");
|
|
10
|
+
const ChartDimensionInspector_1 = require("../inspectors/ChartDimensionInspector");
|
|
11
|
+
const MarginInspector_1 = require("../inspectors/MarginInspector");
|
|
12
|
+
const OffsetInspector_1 = require("../inspectors/OffsetInspector");
|
|
13
|
+
const PlotAreaInspector_1 = require("../inspectors/PlotAreaInspector");
|
|
14
|
+
const UseActiveTooltipDataPointsInspector_1 = require("../inspectors/UseActiveTooltipDataPointsInspector");
|
|
15
|
+
const XAxisDomainInspector_1 = require("../inspectors/XAxisDomainInspector");
|
|
16
|
+
const YAxisDomainInspector_1 = require("../inspectors/YAxisDomainInspector");
|
|
17
|
+
const ActiveTooltipLabelInspector_1 = require("../inspectors/ActiveTooltipLabelInspector");
|
|
18
|
+
const useSessionStorageState_1 = require("../hooks/useSessionStorageState");
|
|
19
|
+
const RechartsDevtoolsContext_1 = require("../context/RechartsDevtoolsContext");
|
|
20
|
+
const INSPECTORS = {
|
|
21
|
+
'useChartWidth | useChartHeight': ChartDimensionInspector_1.ChartDimensionInspector,
|
|
22
|
+
useMargin: MarginInspector_1.MarginInspector,
|
|
23
|
+
useOffset: OffsetInspector_1.OffsetInspector,
|
|
24
|
+
usePlotArea: PlotAreaInspector_1.PlotAreaInspector,
|
|
25
|
+
useActiveTooltipDataPoints: UseActiveTooltipDataPointsInspector_1.UseActiveTooltipDataPointsInspector,
|
|
26
|
+
useXAxisDomain: XAxisDomainInspector_1.XAxisDomainInspector,
|
|
27
|
+
useYAxisDomain: YAxisDomainInspector_1.YAxisDomainInspector,
|
|
28
|
+
useActiveTooltipLabel: ActiveTooltipLabelInspector_1.ActiveTooltipLabelInspector,
|
|
29
|
+
};
|
|
30
|
+
function useSelectedInspector() {
|
|
31
|
+
const [selectedInspectorId, setSelectedInspectorId] = (0, useSessionStorageState_1.useSessionStorageState)('useChartWidth | useChartHeight');
|
|
32
|
+
const selectedInspector = INSPECTORS[selectedInspectorId];
|
|
33
|
+
if (!selectedInspector) {
|
|
34
|
+
setSelectedInspectorId('useChartWidth | useChartHeight');
|
|
35
|
+
}
|
|
36
|
+
return { selectedInspectorId, setSelectedInspectorId, selectedInspector };
|
|
37
|
+
}
|
|
38
|
+
const RechartsDevtools = () => {
|
|
39
|
+
const contextId = (0, RechartsDevtoolsContext_1.useRechartsDevtoolsContext)();
|
|
40
|
+
const portalId = contextId ?? constants_1.RECHARTS_DEVTOOLS_PORTAL_ID;
|
|
41
|
+
const [container, setContainer] = react_1.default.useState(null);
|
|
42
|
+
react_1.default.useEffect(() => {
|
|
43
|
+
setContainer(document.getElementById(portalId));
|
|
44
|
+
}, [portalId]);
|
|
45
|
+
const { selectedInspectorId, setSelectedInspectorId, selectedInspector } = useSelectedInspector();
|
|
46
|
+
const [isOverlayEnabled, setIsOverlayEnabled] = (0, useSessionStorageState_1.useSessionStorageState)(false);
|
|
47
|
+
if (!container || !selectedInspector) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const { Inspector, Overlay } = selectedInspector;
|
|
51
|
+
return (react_1.default.createElement(react_1.default.Fragment, null,
|
|
52
|
+
Overlay && isOverlayEnabled && react_1.default.createElement(Overlay, null),
|
|
53
|
+
(0, react_dom_1.createPortal)(react_1.default.createElement("div", { className: "recharts-devtools", style: { fontFamily: 'monospace', fontSize: '12px' } },
|
|
54
|
+
react_1.default.createElement("div", { style: { marginBottom: '10px', paddingBottom: '10px', borderBottom: '1px solid #ccc' } },
|
|
55
|
+
react_1.default.createElement("div", { style: { display: 'flex', alignItems: 'center', marginBottom: '4px', gap: '8px' } },
|
|
56
|
+
react_1.default.createElement("label", null, "Inspect Hook:"),
|
|
57
|
+
react_1.default.createElement("select", { value: selectedInspectorId, onChange: (e) => setSelectedInspectorId(e.target.value), style: { padding: '4px' } }, Object.keys(INSPECTORS).map((key) => (react_1.default.createElement("option", { key: key, value: key }, key)))),
|
|
58
|
+
Overlay && (react_1.default.createElement("div", { style: { marginTop: '4px' } },
|
|
59
|
+
react_1.default.createElement("label", { style: { cursor: 'pointer', display: 'flex', alignItems: 'center' } },
|
|
60
|
+
react_1.default.createElement("input", { type: "checkbox", checked: isOverlayEnabled, onChange: (e) => setIsOverlayEnabled(e.target.checked), style: { marginRight: '4px' } }),
|
|
61
|
+
"Show Overlay on chart"))))),
|
|
62
|
+
react_1.default.createElement("div", { style: { padding: '10px 0' } },
|
|
63
|
+
react_1.default.createElement(Inspector, null))), container)));
|
|
64
|
+
};
|
|
65
|
+
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,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface RechartsDevtoolsContextProps {
|
|
3
|
+
children: React.ReactNode;
|
|
4
|
+
}
|
|
5
|
+
export declare const RechartsDevtoolsContext: React.FC<RechartsDevtoolsContextProps>;
|
|
6
|
+
export declare const useRechartsDevtoolsContext: () => string | null;
|
|
7
|
+
export declare const RechartsDevtoolsPortal: React.FC<React.HTMLAttributes<HTMLDivElement>>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
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.RechartsDevtoolsPortal = exports.useRechartsDevtoolsContext = exports.RechartsDevtoolsContext = void 0;
|
|
37
|
+
const react_1 = __importStar(require("react"));
|
|
38
|
+
const constants_1 = require("../constants");
|
|
39
|
+
const Context = (0, react_1.createContext)(null);
|
|
40
|
+
const RechartsDevtoolsContext = ({ children }) => {
|
|
41
|
+
// Generate a unique ID for this instance.
|
|
42
|
+
// React.useId returns a string that includes colons, e.g., ":r0:"
|
|
43
|
+
// We sanitize it to make it a valid HTML ID and safer for CSS selectors if needed.
|
|
44
|
+
const rawId = (0, react_1.useId)();
|
|
45
|
+
const portalId = `recharts-devtools-portal-${rawId.replace(/:/g, '')}`;
|
|
46
|
+
return react_1.default.createElement(Context.Provider, { value: portalId }, children);
|
|
47
|
+
};
|
|
48
|
+
exports.RechartsDevtoolsContext = RechartsDevtoolsContext;
|
|
49
|
+
const useRechartsDevtoolsContext = () => {
|
|
50
|
+
return (0, react_1.useContext)(Context);
|
|
51
|
+
};
|
|
52
|
+
exports.useRechartsDevtoolsContext = useRechartsDevtoolsContext;
|
|
53
|
+
const RechartsDevtoolsPortal = (props) => {
|
|
54
|
+
const contextId = (0, exports.useRechartsDevtoolsContext)();
|
|
55
|
+
const id = contextId ?? constants_1.RECHARTS_DEVTOOLS_PORTAL_ID;
|
|
56
|
+
return react_1.default.createElement("div", { id: id, ...props });
|
|
57
|
+
};
|
|
58
|
+
exports.RechartsDevtoolsPortal = RechartsDevtoolsPortal;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This hook works just the same as `useState`, but it also stores the state in the session storage.
|
|
3
|
+
* It uses `useId` from React to generate a unique key for the state.
|
|
4
|
+
*
|
|
5
|
+
* In browsers without session storage support, it will fallback to `useState`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useSessionStorageState: <T>(initialState: T) => readonly [any, import("react").Dispatch<any>];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useSessionStorageState = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
/**
|
|
6
|
+
* This hook works just the same as `useState`, but it also stores the state in the session storage.
|
|
7
|
+
* It uses `useId` from React to generate a unique key for the state.
|
|
8
|
+
*
|
|
9
|
+
* In browsers without session storage support, it will fallback to `useState`.
|
|
10
|
+
*/
|
|
11
|
+
const useSessionStorageState = (initialState) => {
|
|
12
|
+
const id = (0, react_1.useId)();
|
|
13
|
+
const [state, setState] = (0, react_1.useState)(() => {
|
|
14
|
+
try {
|
|
15
|
+
const storedState = sessionStorage.getItem(id);
|
|
16
|
+
return storedState ? JSON.parse(storedState) : initialState;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return initialState;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
(0, react_1.useEffect)(() => {
|
|
23
|
+
try {
|
|
24
|
+
sessionStorage.setItem(id, JSON.stringify(state));
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
}
|
|
28
|
+
}, [state]);
|
|
29
|
+
return [state, setState];
|
|
30
|
+
};
|
|
31
|
+
exports.useSessionStorageState = useSessionStorageState;
|
package/dist/src/index.d.ts
CHANGED
package/dist/src/index.js
CHANGED
|
@@ -16,3 +16,6 @@ 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("./context/RechartsDevtoolsContext"), exports);
|
|
21
|
+
__exportStar(require("./constants"), exports);
|
|
@@ -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,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,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,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,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,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,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,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,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,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,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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,39 +1,49 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
"name": "@recharts/devtools",
|
|
3
|
+
"publishConfig": {
|
|
4
|
+
"access": "public"
|
|
5
|
+
},
|
|
6
|
+
"version": "0.0.4",
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
}
|