@pie-lib/plot 4.0.4-next.30 → 4.0.4-next.34

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 (59) hide show
  1. package/CHANGELOG.json +17 -0
  2. package/CHANGELOG.md +838 -0
  3. package/LICENSE.md +5 -0
  4. package/lib/draggable.js +44 -0
  5. package/lib/draggable.js.map +1 -0
  6. package/lib/graph-props.js +46 -0
  7. package/lib/graph-props.js.map +1 -0
  8. package/lib/grid-draggable.js +361 -0
  9. package/lib/grid-draggable.js.map +1 -0
  10. package/lib/index.js +44 -0
  11. package/lib/index.js.map +1 -0
  12. package/lib/label.js +173 -0
  13. package/lib/label.js.map +1 -0
  14. package/lib/root.js +474 -0
  15. package/lib/root.js.map +1 -0
  16. package/lib/trig.js +149 -0
  17. package/lib/trig.js.map +1 -0
  18. package/lib/types.js +40 -0
  19. package/lib/types.js.map +1 -0
  20. package/lib/utils.js +165 -0
  21. package/lib/utils.js.map +1 -0
  22. package/package.json +25 -35
  23. package/src/__tests__/draggable.test.jsx +41 -0
  24. package/src/__tests__/grid-draggable.test.jsx +487 -0
  25. package/src/__tests__/root.test.jsx +277 -0
  26. package/src/__tests__/trig.test.js +163 -0
  27. package/src/__tests__/utils.test.js +229 -0
  28. package/src/draggable.jsx +11 -0
  29. package/src/graph-props.js +34 -0
  30. package/src/grid-draggable.jsx +332 -0
  31. package/src/index.js +9 -0
  32. package/src/label.jsx +199 -0
  33. package/src/root.jsx +485 -0
  34. package/src/trig.js +151 -0
  35. package/src/types.js +41 -0
  36. package/src/utils.js +167 -0
  37. package/dist/_virtual/_rolldown/runtime.js +0 -20
  38. package/dist/draggable.d.ts +0 -13
  39. package/dist/draggable.js +0 -13
  40. package/dist/graph-props.d.ts +0 -22
  41. package/dist/graph-props.js +0 -29
  42. package/dist/grid-draggable.d.ts +0 -91
  43. package/dist/grid-draggable.js +0 -168
  44. package/dist/index.d.ts +0 -16
  45. package/dist/index.js +0 -8
  46. package/dist/label.d.ts +0 -30
  47. package/dist/label.js +0 -132
  48. package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +0 -16
  49. package/dist/node_modules/.bun/invariant@2.2.4/node_modules/invariant/browser.js +0 -28
  50. package/dist/node_modules/.bun/react-draggable@4.6.0_6dbf9a050bc9aadb/node_modules/react-draggable/build/cjs/chunk-D5BXCJ5G.js +0 -503
  51. package/dist/node_modules/.bun/react-draggable@4.6.0_6dbf9a050bc9aadb/node_modules/react-draggable/build/cjs/cjs.js +0 -5
  52. package/dist/root.d.ts +0 -68
  53. package/dist/root.js +0 -302
  54. package/dist/trig.d.ts +0 -41
  55. package/dist/trig.js +0 -47
  56. package/dist/types.d.ts +0 -125
  57. package/dist/types.js +0 -46
  58. package/dist/utils.d.ts +0 -44
  59. package/dist/utils.js +0 -82
package/src/utils.js ADDED
@@ -0,0 +1,167 @@
1
+ import invariant from 'invariant';
2
+ import { head, isEqual, range, tail } from 'lodash-es';
3
+ import Point from '@mapbox/point-geometry';
4
+
5
+ export const xy = (x, y) => ({ x, y });
6
+
7
+ export const buildSizeArray = (size, padding) => {
8
+ padding = Number.isFinite(padding) ? Math.max(padding, 0) : 0;
9
+ invariant(padding < size, 'padding must be less than size');
10
+ const half = Math.round(padding * 0.5);
11
+ return [half, size - half];
12
+ };
13
+
14
+ export const tickCount = (min, max, step) => {
15
+ invariant(min < max, 'min must be less than max');
16
+ const size = Math.abs(min - max);
17
+ return Math.round(size / step);
18
+ };
19
+
20
+ export function getInterval(domain, ticks) {
21
+ const { min, max } = domain;
22
+ const { major, minor } = ticks;
23
+
24
+ if (min >= max) {
25
+ throw new Error(`min is > max: ${min} > ${max}`);
26
+ }
27
+
28
+ const distance = max - min;
29
+ const minorTicks = minor > 0 ? minor + 1 : 1;
30
+ const normalizedMajor = major - 1;
31
+
32
+ if (isNaN(normalizedMajor)) {
33
+ throw new Error('Tick Frequency must be 2 or higher');
34
+ }
35
+
36
+ if (normalizedMajor <= 0) {
37
+ throw new Error('Tick Frequency must be 2 or higher');
38
+ }
39
+
40
+ const divider = normalizedMajor * minorTicks;
41
+ const raw = distance / divider;
42
+ return parseFloat(Number(raw).toFixed(4));
43
+ }
44
+
45
+ const mkRange = (min, max, interval) => {
46
+ const raw = range(min, max, interval);
47
+ /* Fix the last step due to rounding errors */
48
+ raw.splice(raw.length, 1, max);
49
+ return raw;
50
+ };
51
+
52
+ export function snapTo(min, max, interval, value) {
53
+ if (value >= max) {
54
+ return max;
55
+ }
56
+
57
+ if (value <= min) {
58
+ return min;
59
+ }
60
+
61
+ let rng = mkRange(min, max, interval);
62
+
63
+ rng = rng.filter((v) => {
64
+ return Math.abs(value - v) <= interval;
65
+ });
66
+
67
+ return (
68
+ rng.length &&
69
+ rng.reduce((prev, curr) => {
70
+ const currentDistance = Math.abs(curr - value);
71
+ const previousDistance = Math.abs(prev - value);
72
+ return currentDistance <= previousDistance ? curr : prev;
73
+ })
74
+ );
75
+ }
76
+
77
+ export function buildTickModel(domain, ticks, interval, scaleFn) {
78
+ const rng = mkRange(domain.min, domain.max, interval);
79
+
80
+ return rng.map((r, index) => {
81
+ const isMajor = index % (ticks.minor + 1) === 0;
82
+
83
+ return {
84
+ value: r,
85
+ major: isMajor,
86
+ x: scaleFn(r),
87
+ };
88
+ });
89
+ }
90
+
91
+ export const polygonToArea = (points) => {
92
+ const h = head(points);
93
+ const area = {
94
+ left: h.x,
95
+ top: h.y,
96
+ bottom: h.y,
97
+ right: h.x,
98
+ };
99
+ return tail(points).reduce((a, p) => {
100
+ a.left = Math.min(a.left, p.x);
101
+ a.top = Math.max(a.top, p.y);
102
+ a.bottom = Math.min(a.bottom, p.y);
103
+ a.right = Math.max(a.right, p.x);
104
+ return a;
105
+ }, area);
106
+ };
107
+
108
+ export const lineToArea = (from, to) => {
109
+ const left = Math.min(from.x, to.x);
110
+ const top = Math.max(from.y, to.y);
111
+ const bottom = Math.min(from.y, to.y);
112
+ const right = Math.max(from.x, to.x);
113
+ return { left, top, bottom, right };
114
+ };
115
+
116
+ export const bounds = (area, domain, range) => {
117
+ return {
118
+ left: domain.min - area.left,
119
+ right: Math.abs(area.right - domain.max),
120
+ top: Math.abs(area.top - range.max),
121
+ bottom: range.min - area.bottom,
122
+ };
123
+ };
124
+
125
+ export const point = (o) => new Point(o.x, o.y);
126
+ export const getDelta = (from, to) => {
127
+ return point(to).sub(point(from));
128
+ };
129
+
130
+ export const bandKey = (d, index) => `${index}-${d.label || '-'}`;
131
+
132
+ export const isDomainRangeEqual = (graphProps, nextGraphProps) => {
133
+ return isEqual(graphProps.domain, nextGraphProps.domain) && isEqual(graphProps.range, nextGraphProps.range);
134
+ };
135
+
136
+ // findLongestWord is also used in graphing
137
+ export const findLongestWord = (label) => {
138
+ let longestWord = (label || '')
139
+ .replace(/<[^>]+>/g, '')
140
+ .split(' ')
141
+ .sort((a, b) => b.length - a.length);
142
+
143
+ return longestWord[0].length;
144
+ };
145
+
146
+ // amountToIncreaseWidth is also used in graphing
147
+ export const amountToIncreaseWidth = (longestWord) => {
148
+ if (!longestWord) {
149
+ return 0;
150
+ }
151
+
152
+ return longestWord * 20;
153
+ };
154
+
155
+ export const extractTextFromHTML = (htmlString) => {
156
+ const parser = new DOMParser();
157
+ const doc = parser?.parseFromString(htmlString, 'text/html');
158
+ return doc?.body?.textContent || '';
159
+ };
160
+
161
+ export const isEmptyObject = (obj) => {
162
+ return obj && Object.keys(obj).length === 0 && obj.constructor === Object;
163
+ };
164
+
165
+ export const isEmptyString = (str) => {
166
+ return typeof str === 'string' && str.trim() === '';
167
+ };
@@ -1,20 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescriptor, r = Object.getOwnPropertyNames, i = Object.getPrototypeOf, a = Object.prototype.hasOwnProperty, o = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), s = (e, n) => {
3
- let r = {};
4
- for (var i in e) t(r, i, {
5
- get: e[i],
6
- enumerable: !0
7
- });
8
- return n || t(r, Symbol.toStringTag, { value: "Module" }), r;
9
- }, c = (e, i, o, s) => {
10
- if (i && typeof i == "object" || typeof i == "function") for (var c = r(i), l = 0, u = c.length, d; l < u; l++) d = c[l], !a.call(e, d) && d !== o && t(e, d, {
11
- get: ((e) => i[e]).bind(null, d),
12
- enumerable: !(s = n(i, d)) || s.enumerable
13
- });
14
- return e;
15
- }, l = (n, r, a) => (a = n == null ? {} : e(i(n)), c(r || !n || !n.__esModule ? t(a, "default", {
16
- value: n,
17
- enumerable: !0
18
- }) : a, n));
19
- //#endregion
20
- export { o as __commonJSMin, s as __exportAll, l as __toESM };
@@ -1,13 +0,0 @@
1
- /**
2
- * @synced-from pie-lib/packages/plot/src/draggable.jsx
3
- * @auto-generated
4
- *
5
- * This file is automatically synced from pie-elements and converted to TypeScript.
6
- * Manual edits will be overwritten on next sync.
7
- * To make changes, edit the upstream JavaScript file and run sync again.
8
- */
9
- import Draggable, { DraggableCore } from 'react-draggable';
10
- export default class LocalDraggable extends Draggable {
11
- componentWillReceiveProps(next: any): void;
12
- }
13
- export { DraggableCore };
package/dist/draggable.js DELETED
@@ -1,13 +0,0 @@
1
- import "./node_modules/.bun/react-draggable@4.6.0_6dbf9a050bc9aadb/node_modules/react-draggable/build/cjs/chunk-D5BXCJ5G.js";
2
- import { cjs_default as e } from "./node_modules/.bun/react-draggable@4.6.0_6dbf9a050bc9aadb/node_modules/react-draggable/build/cjs/cjs.js";
3
- //#region src/draggable.tsx
4
- var t = class extends e {
5
- componentWillReceiveProps(e) {
6
- super.componentWillReceiveProps(e), this.setState({
7
- x: 0,
8
- y: 0
9
- });
10
- }
11
- };
12
- //#endregion
13
- export { t as default };
@@ -1,22 +0,0 @@
1
- /**
2
- * @synced-from pie-lib/packages/plot/src/graph-props.js
3
- * @auto-generated
4
- *
5
- * This file is automatically synced from pie-elements and converted to TypeScript.
6
- * Manual edits will be overwritten on next sync.
7
- * To make changes, edit the upstream JavaScript file and run sync again.
8
- */
9
- export declare const create: (domain: any, range: any, size: any, getRootNode: any) => {
10
- scale: {
11
- x: any;
12
- y: any;
13
- };
14
- snap: {
15
- x: (value: any) => any;
16
- y: (value: any) => any;
17
- };
18
- domain: any;
19
- range: any;
20
- size: any;
21
- getRootNode: any;
22
- };
@@ -1,29 +0,0 @@
1
- import { __toESM as e } from "./_virtual/_rolldown/runtime.js";
2
- import { require_browser as t } from "./node_modules/.bun/invariant@2.2.4/node_modules/invariant/browser.js";
3
- import { snapTo as n } from "./utils.js";
4
- import { scaleLinear as r } from "d3-scale";
5
- //#region src/graph-props.ts
6
- var i = /* @__PURE__ */ e(t(), 1), a = ({ min: e, max: t, step: n }) => ({
7
- step: n,
8
- min: parseInt(e / n) * n,
9
- max: parseInt(t / n) * n
10
- }), o = (e, t, o, s) => {
11
- (0, i.default)(e.min < e.max, "domain: min must be less than max"), (0, i.default)(t.min < t.max, "range: min must be less than max");
12
- let c = a(e), l = a(t);
13
- return {
14
- scale: {
15
- x: r().domain([e.min, e.max]).range([0, o.width]),
16
- y: r().domain([t.max, t.min]).range([0, o.height])
17
- },
18
- snap: {
19
- x: n.bind(null, c.min, c.max, c.step),
20
- y: n.bind(null, l.min, l.max, l.step)
21
- },
22
- domain: e,
23
- range: t,
24
- size: o,
25
- getRootNode: s
26
- };
27
- };
28
- //#endregion
29
- export { o as create };
@@ -1,91 +0,0 @@
1
- /**
2
- * @synced-from pie-lib/packages/plot/src/grid-draggable.jsx
3
- * @auto-generated
4
- *
5
- * This file is automatically synced from pie-elements and converted to TypeScript.
6
- * Manual edits will be overwritten on next sync.
7
- * To make changes, edit the upstream JavaScript file and run sync again.
8
- */
9
- import React from 'react';
10
- import PropTypes from 'prop-types';
11
- export declare const deltaFn: (scale: any, snap: any, val: any) => (delta: any) => number;
12
- /**
13
- * Creates a Component that is draggable, within a bounded grid.
14
- * @param {*} opts
15
- */
16
- export declare const gridDraggable: (opts: any) => (Comp: any) => {
17
- new (props: any): {
18
- grid: any;
19
- onStart: any;
20
- position: any;
21
- tiny: any;
22
- getScaledBounds: any;
23
- /**
24
- * Retrieves the coordinates of a mouse or touch event relative to an SVG element.
25
- * This method has been overwritten from the d3-selection library's clientPoint to handle touch events and improve clarity.
26
- * @param {Element} node - The SVG element.
27
- * @param {Event} event - The mouse or touch event.
28
- * @returns {Array} - An array containing the coordinates [x, y] relative to the SVG element.
29
- */
30
- getClientPoint: any;
31
- skipDragOutsideOfBounds: any;
32
- onDrag: any;
33
- getDelta: any;
34
- applyDelta: any;
35
- onStop: any;
36
- render(): React.JSX.Element;
37
- context: unknown;
38
- setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<{}>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
39
- forceUpdate(callback?: (() => void) | undefined): void;
40
- readonly props: Readonly<{}>;
41
- state: Readonly<{}>;
42
- refs: {
43
- [key: string]: React.ReactInstance;
44
- };
45
- componentDidMount?(): void;
46
- shouldComponentUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): boolean;
47
- componentWillUnmount?(): void;
48
- componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
49
- getSnapshotBeforeUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>): any;
50
- componentDidUpdate?(prevProps: Readonly<{}>, prevState: Readonly<{}>, snapshot?: any): void;
51
- componentWillMount?(): void;
52
- UNSAFE_componentWillMount?(): void;
53
- componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void;
54
- UNSAFE_componentWillReceiveProps?(nextProps: Readonly<{}>, nextContext: any): void;
55
- componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void;
56
- UNSAFE_componentWillUpdate?(nextProps: Readonly<{}>, nextState: Readonly<{}>, nextContext: any): void;
57
- };
58
- propTypes: {
59
- disabled: PropTypes.Requireable<boolean>;
60
- onDragStart: PropTypes.Requireable<(...args: any[]) => any>;
61
- onDrag: PropTypes.Requireable<(...args: any[]) => any>;
62
- onDragStop: PropTypes.Requireable<(...args: any[]) => any>;
63
- onClick: PropTypes.Requireable<(...args: any[]) => any>;
64
- onMove: PropTypes.Requireable<(...args: any[]) => any>;
65
- graphProps: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
66
- scale: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
67
- x: PropTypes.Validator<(...args: any[]) => any>;
68
- y: PropTypes.Validator<(...args: any[]) => any>;
69
- }>>>;
70
- snap: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
71
- x: PropTypes.Validator<(...args: any[]) => any>;
72
- y: PropTypes.Validator<(...args: any[]) => any>;
73
- }>>>;
74
- domain: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
75
- min: PropTypes.Validator<number>;
76
- max: PropTypes.Validator<number>;
77
- step: PropTypes.Requireable<number>;
78
- }>>>;
79
- range: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
80
- min: PropTypes.Validator<number>;
81
- max: PropTypes.Validator<number>;
82
- step: PropTypes.Requireable<number>;
83
- }>>>;
84
- size: PropTypes.Validator<NonNullable<PropTypes.InferProps<{
85
- width: PropTypes.Validator<number>;
86
- height: PropTypes.Validator<number>;
87
- }>>>;
88
- }>>>;
89
- };
90
- contextType?: React.Context<any> | undefined;
91
- };
@@ -1,168 +0,0 @@
1
- import { __toESM as e } from "./_virtual/_rolldown/runtime.js";
2
- import { GraphPropsType as t } from "./types.js";
3
- import { require_browser as n } from "./node_modules/.bun/invariant@2.2.4/node_modules/invariant/browser.js";
4
- import { getDelta as r } from "./utils.js";
5
- import { DraggableCore as i } from "./node_modules/.bun/react-draggable@4.6.0_6dbf9a050bc9aadb/node_modules/react-draggable/build/cjs/chunk-D5BXCJ5G.js";
6
- import a from "react";
7
- import o from "prop-types";
8
- import { pointer as s } from "d3-selection";
9
- import { jsx as c } from "react/jsx-runtime";
10
- import { isFunction as l } from "@pie-element/shared-lodash";
11
- import u from "debug";
12
- //#region src/grid-draggable.tsx
13
- var d = /* @__PURE__ */ e(n(), 1), f = u("pie-lib:plot:grid-draggable"), p = (e, t, n) => (r) => {
14
- let i = r + e(0);
15
- return t(n + e.invert(i)).toFixed(4) * 1e3 / 1e3;
16
- }, m = (e) => (n) => ((0, d.default)(!!e && l(e.fromDelta) && l(e.bounds) && l(e.anchorPoint), "You must supply an object with: { anchorPoint: Function, fromDelta: Function, bounds: Function }"), class extends a.Component {
17
- static propTypes = {
18
- disabled: o.bool,
19
- onDragStart: o.func,
20
- onDrag: o.func,
21
- onDragStop: o.func,
22
- onClick: o.func,
23
- onMove: o.func,
24
- graphProps: t.isRequired
25
- };
26
- constructor(e) {
27
- super(e), this.state = {
28
- startX: null,
29
- startY: null
30
- };
31
- }
32
- grid = () => {
33
- let { graphProps: e } = this.props, { scale: t, domain: n, range: r } = e;
34
- return {
35
- x: t.x(n.step) - t.x(0),
36
- y: t.y(r.step) - t.y(0)
37
- };
38
- };
39
- onStart = (e) => {
40
- let { onDragStart: t } = this.props;
41
- document.activeElement && document.activeElement.blur(), this._didDrag = !1, this.setState({
42
- startX: e.clientX,
43
- startY: e.clientY
44
- });
45
- let n = e.target, r = (e) => {
46
- n.removeEventListener("click", r, !0), this._didDrag && (e.stopPropagation(), e.preventDefault());
47
- };
48
- n.addEventListener("click", r, !0), t && t();
49
- };
50
- position = () => {
51
- let { x: t, y: n } = e.anchorPoint(this.props), { graphProps: r } = this.props, { scale: i, snap: a } = r;
52
- return {
53
- anchorPoint: {
54
- x: t,
55
- y: n
56
- },
57
- x: p(i.x, a.x, t),
58
- y: p(i.y, a.y, n)
59
- };
60
- };
61
- tiny = (e, t) => {
62
- let n = e.toUpperCase(), r = Math.abs(t[`client${n}`] - this.state[`start${n}`]), i = r < Math.abs(this.grid()[e]) / 10;
63
- return f("[tiny] key: ", e, "delta: ", r, "out: ", i), i;
64
- };
65
- getScaledBounds = () => {
66
- let t = e.bounds(this.props, this.props.graphProps);
67
- f("bounds: ", t);
68
- let n = this.grid(), r = {
69
- left: t.left * n.x,
70
- right: t.right * n.x,
71
- top: t.top * n.y,
72
- bottom: t.bottom * n.y
73
- }, i = Math.abs(n.y);
74
- return r = {
75
- ...r,
76
- top: Math.min(0, r.top) - i,
77
- bottom: Math.abs(r.bottom) + i
78
- }, f("[getScaledBounds]: ", r), r;
79
- };
80
- getClientPoint = (e, t) => {
81
- if (!e || !t) return null;
82
- let n = e.ownerSVGElement || e;
83
- if (n && n.createSVGPoint) {
84
- let r = n.createSVGPoint();
85
- if (t.touches && t.touches.length > 0) {
86
- let e = t.touches[0];
87
- r.x = e.clientX, r.y = e.clientY;
88
- } else r.x = t.clientX, r.y = t.clientY;
89
- return e.getScreenCTM ? (r = r.matrixTransform(e.getScreenCTM().inverse()), [r.x, r.y]) : null;
90
- }
91
- let r = e.getBoundingClientRect();
92
- return r ? [t.clientX - r.left - e.clientLeft, t.clientY - r.top - e.clientTop] : null;
93
- };
94
- skipDragOutsideOfBounds = (e, t, n) => {
95
- let r = n.getRootNode(), i = this.getClientPoint(r, t);
96
- if (i === null) return !0;
97
- let [a, o] = i, { scale: s, domain: c, range: l } = n, u = s.x.invert(a), d = s.y.invert(o), f = e.deltaX > 0 && u < c.min || e.deltaX < 0 && u > c.max, p = e.deltaY > 0 && d > l.max || e.deltaY < 0 && d < l.min;
98
- return f || p;
99
- };
100
- onDrag = (e, t) => {
101
- let { onDrag: n, graphProps: r, disabled: i } = this.props;
102
- if ((Math.abs(t.deltaX) > 1 || Math.abs(t.deltaY) > 1) && (this._didDrag = !0), !n || i) return;
103
- let a = this.getScaledBounds();
104
- if (t.deltaX < 0 && t.deltaX < a.left || t.deltaX > 0 && t.deltaX > a.right || t.deltaY < 0 && t.deltaY < a.top || t.deltaY > 0 && t.deltaY > a.bottom || this.skipDragOutsideOfBounds(t, e, r)) return;
105
- let o = this.applyDelta({
106
- x: t.deltaX,
107
- y: t.deltaY
108
- });
109
- (o !== void 0 || o !== null) && n(o);
110
- };
111
- getDelta = (e) => {
112
- let t = this.position(), n = {
113
- x: t.x(e.x),
114
- y: t.y(e.y)
115
- };
116
- return r(t.anchorPoint, n);
117
- };
118
- applyDelta = (t) => {
119
- let n = this.getDelta(t);
120
- return f("[applyDelta] delta:", n), e.fromDelta(this.props, n);
121
- };
122
- onStop = (e, t) => {
123
- f("[onStop] dd:", t);
124
- let { onDragStop: n, onClick: r, disabled: i } = this.props;
125
- if (n && !i && n(), f("[onStop] lastX/Y: ", t.lastX, t.lastY), !this._didDrag) {
126
- if (!i && typeof e?.stopPropagation == "function" && e.stopPropagation(), r) {
127
- f("call onClick"), this.setState({
128
- startX: null,
129
- startY: null
130
- });
131
- let { graphProps: t } = this.props, { scale: n, snap: i } = t;
132
- try {
133
- let [t, a] = s(e, e.target), o = n.x.invert(t), c = n.y.invert(a);
134
- o = i.x(o), c = i.y(c), r({
135
- x: o,
136
- y: c
137
- });
138
- } catch {
139
- r({});
140
- }
141
- }
142
- return !1;
143
- }
144
- return this.setState({
145
- startX: null,
146
- startY: null
147
- }), !1;
148
- };
149
- render() {
150
- let { disabled: t, onClick: r, ...a } = this.props, o = this.grid(), s = (e) => e.nativeEvent.preventDefault(), l = this.state ? !!this.state.startX : !1;
151
- return /* @__PURE__ */ c(i, {
152
- onMouseDown: s,
153
- onStart: this.onStart,
154
- onDrag: this.onDrag,
155
- onStop: this.onStop,
156
- axis: e.axis || "both",
157
- grid: [o.x, o.y],
158
- children: /* @__PURE__ */ c(n, {
159
- ...a,
160
- disabled: t,
161
- isDragging: l,
162
- onClick: l ? void 0 : r
163
- })
164
- });
165
- }
166
- });
167
- //#endregion
168
- export { m as gridDraggable };
package/dist/index.d.ts DELETED
@@ -1,16 +0,0 @@
1
- /**
2
- * @synced-from pie-lib/packages/plot/src/index.js
3
- * @auto-generated
4
- *
5
- * This file is automatically synced from pie-elements and converted to TypeScript.
6
- * Manual edits will be overwritten on next sync.
7
- * To make changes, edit the upstream JavaScript file and run sync again.
8
- */
9
- import Root from './root.js';
10
- import Draggable from './draggable.js';
11
- import { gridDraggable } from './grid-draggable.js';
12
- import * as utils from './utils.js';
13
- import * as trig from './trig.js';
14
- import * as types from './types.js';
15
- import { create as createGraphProps } from './graph-props.js';
16
- export { Root, Draggable, gridDraggable, utils, trig, types, createGraphProps };
package/dist/index.js DELETED
@@ -1,8 +0,0 @@
1
- import { types_exports as e } from "./types.js";
2
- import { utils_exports as t } from "./utils.js";
3
- import n from "./root.js";
4
- import r from "./draggable.js";
5
- import { gridDraggable as i } from "./grid-draggable.js";
6
- import { trig_exports as a } from "./trig.js";
7
- import { create as o } from "./graph-props.js";
8
- export { r as Draggable, n as Root, o as createGraphProps, i as gridDraggable, a as trig, e as types, t as utils };
package/dist/label.d.ts DELETED
@@ -1,30 +0,0 @@
1
- /**
2
- * @synced-from pie-lib/packages/plot/src/label.jsx
3
- * @auto-generated
4
- *
5
- * This file is automatically synced from pie-elements and converted to TypeScript.
6
- * Manual edits will be overwritten on next sync.
7
- * To make changes, edit the upstream JavaScript file and run sync again.
8
- */
9
- import React from 'react';
10
- import PropTypes from 'prop-types';
11
- declare const LabelComponent: {
12
- (props: any): React.JSX.Element;
13
- propTypes: {
14
- disabledLabel: PropTypes.Requireable<boolean>;
15
- graphHeight: PropTypes.Requireable<number>;
16
- graphWidth: PropTypes.Requireable<number>;
17
- isChartBottomLabel: PropTypes.Requireable<boolean>;
18
- isDefineChartBottomLabel: PropTypes.Requireable<boolean>;
19
- isChartLeftLabel: PropTypes.Requireable<boolean>;
20
- isDefineChartLeftLabel: PropTypes.Requireable<boolean>;
21
- placeholder: PropTypes.Requireable<string>;
22
- text: PropTypes.Requireable<string>;
23
- side: PropTypes.Requireable<string>;
24
- onChange: PropTypes.Requireable<(...args: any[]) => any>;
25
- mathMlOptions: PropTypes.Requireable<object>;
26
- charactersLimit: PropTypes.Requireable<number>;
27
- titleHeight: PropTypes.Requireable<number>;
28
- };
29
- };
30
- export default LabelComponent;