@pie-lib/graphing-solution-set 4.1.0-beta.9 → 5.0.0-next.20261002094057
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/dist/_virtual/_rolldown/runtime.js +20 -0
- package/dist/autosize-input.d.ts +10 -0
- package/dist/autosize-input.js +66 -0
- package/dist/axis/arrow.d.ts +13 -0
- package/dist/axis/arrow.js +34 -0
- package/dist/axis/axes.d.ts +132 -0
- package/dist/axis/axes.js +214 -0
- package/dist/axis/index.d.ts +10 -0
- package/dist/bg.d.ts +51 -0
- package/dist/bg.js +44 -0
- package/dist/container/actions.d.ts +15 -0
- package/dist/container/actions.js +7 -0
- package/dist/container/index.d.ts +58 -0
- package/dist/container/index.js +48 -0
- package/dist/container/marks.d.ts +10 -0
- package/dist/container/marks.js +11 -0
- package/dist/container/middleware.d.ts +10 -0
- package/dist/container/middleware.js +4 -0
- package/dist/container/reducer.d.ts +14 -0
- package/dist/container/reducer.js +7 -0
- package/dist/coordinates-label.d.ts +50 -0
- package/dist/coordinates-label.js +46 -0
- package/dist/graph-with-controls.d.ts +85 -0
- package/dist/graph-with-controls.js +155 -0
- package/dist/graph.d.ts +119 -0
- package/dist/graph.js +221 -0
- package/dist/grid-setup.d.ts +27 -0
- package/dist/grid-setup.js +307 -0
- package/dist/grid.d.ts +43 -0
- package/dist/grid.js +59 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +6 -0
- package/dist/labels.d.ts +73 -0
- package/dist/labels.js +134 -0
- package/dist/mark-label.d.ts +50 -0
- package/dist/mark-label.js +84 -0
- package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/axis/Axis.js +67 -0
- package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/axis/AxisRenderer.js +66 -0
- package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/axis/Ticks.js +39 -0
- package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/constants/orientation.js +9 -0
- package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/utils/createPoint.js +14 -0
- package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/utils/getAxisRangePaddingConfig.js +13 -0
- package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/utils/getLabelTransform.js +16 -0
- package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/utils/getTickFormatter.js +8 -0
- package/dist/node_modules/.bun/@visx_axis@4.0.0_d84c32d47042070f/node_modules/@visx/axis/esm/utils/getTickPosition.js +14 -0
- package/dist/node_modules/.bun/@visx_grid@4.0.0_d84c32d47042070f/node_modules/@visx/grid/esm/grids/Grid.js +43 -0
- package/dist/node_modules/.bun/@visx_grid@4.0.0_d84c32d47042070f/node_modules/@visx/grid/esm/grids/GridColumns.js +46 -0
- package/dist/node_modules/.bun/@visx_grid@4.0.0_d84c32d47042070f/node_modules/@visx/grid/esm/grids/GridRows.js +46 -0
- package/dist/node_modules/.bun/@visx_grid@4.0.0_d84c32d47042070f/node_modules/@visx/grid/esm/utils/getScaleBandwidth.js +6 -0
- package/dist/node_modules/.bun/@visx_group@4.0.0_d84c32d47042070f/node_modules/@visx/group/esm/Group.js +17 -0
- package/dist/node_modules/.bun/@visx_point@4.0.0/node_modules/@visx/point/esm/Point.js +20 -0
- package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/utils/coerceNumber.js +10 -0
- package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/utils/getTicks.js +7 -0
- package/dist/node_modules/.bun/@visx_scale@4.0.0/node_modules/@visx/scale/esm/utils/toString.js +6 -0
- package/dist/node_modules/.bun/@visx_shape@4.0.0_d84c32d47042070f/node_modules/@visx/shape/esm/shapes/Line.js +27 -0
- package/dist/node_modules/.bun/@visx_text@4.0.0_d84c32d47042070f/node_modules/@visx/text/esm/Text.js +27 -0
- package/dist/node_modules/.bun/@visx_text@4.0.0_d84c32d47042070f/node_modules/@visx/text/esm/hooks/useText.js +68 -0
- package/dist/node_modules/.bun/@visx_text@4.0.0_d84c32d47042070f/node_modules/@visx/text/esm/util/getStringWidth.js +19 -0
- package/dist/node_modules/.bun/@visx_text@4.0.0_d84c32d47042070f/node_modules/@visx/text/esm/util/memoize.js +13 -0
- package/dist/node_modules/.bun/balanced-match@0.4.2/node_modules/balanced-match/index.js +32 -0
- package/dist/node_modules/.bun/balanced-match@1.0.2/node_modules/balanced-match/index.js +33 -0
- package/dist/node_modules/.bun/classnames@2.5.1/node_modules/classnames/index.js +32 -0
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
- package/dist/node_modules/.bun/invariant@2.2.4/node_modules/invariant/browser.js +28 -0
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/formula_evaluator.js +37 -0
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/lexer.js +509 -0
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/math_function.js +108 -0
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/postfix.js +31 -0
- package/dist/node_modules/.bun/math-expression-evaluator@1.4.0/node_modules/math-expression-evaluator/src/postfix_evaluator.js +45 -0
- package/dist/node_modules/.bun/reduce-css-calc@1.3.0/node_modules/reduce-css-calc/index.js +49 -0
- package/dist/node_modules/.bun/reduce-function-call@1.0.3/node_modules/reduce-function-call/index.js +34 -0
- package/dist/node_modules/.bun/redux-undo@1.1.0/node_modules/redux-undo/dist/redux-undo.js +185 -0
- package/dist/node_modules/.bun/redux@5.0.1/node_modules/redux/dist/redux.js +198 -0
- package/dist/tool-menu.d.ts +21 -0
- package/dist/tool-menu.js +188 -0
- package/dist/tools/index.d.ts +17 -0
- package/dist/tools/index.js +12 -0
- package/dist/tools/line/component.d.ts +113 -0
- package/dist/tools/line/component.js +58 -0
- package/dist/tools/line/index.d.ts +13 -0
- package/dist/tools/line/index.js +6 -0
- package/dist/tools/polygon/component.d.ts +117 -0
- package/dist/tools/polygon/component.js +194 -0
- package/dist/tools/polygon/index.d.ts +19 -0
- package/dist/tools/polygon/index.js +55 -0
- package/dist/tools/polygon/polygon.d.ts +122 -0
- package/dist/tools/polygon/polygon.js +62 -0
- package/dist/tools/shared/arrow-head.d.ts +43 -0
- package/dist/tools/shared/arrow-head.js +37 -0
- package/dist/tools/shared/line/index.d.ts +240 -0
- package/dist/tools/shared/line/index.js +320 -0
- package/dist/tools/shared/point/arrow-point.d.ts +57 -0
- package/dist/tools/shared/point/arrow-point.js +47 -0
- package/dist/tools/shared/point/arrow.d.ts +46 -0
- package/dist/tools/shared/point/arrow.js +36 -0
- package/dist/tools/shared/point/base-point.d.ts +50 -0
- package/dist/tools/shared/point/base-point.js +88 -0
- package/dist/tools/shared/point/index.d.ts +217 -0
- package/dist/tools/shared/point/index.js +51 -0
- package/dist/tools/shared/styles.d.ts +24 -0
- package/dist/tools/shared/styles.js +17 -0
- package/dist/tools/shared/types.d.ts +15 -0
- package/dist/tools/shared/types.js +10 -0
- package/dist/undo-redo.d.ts +20 -0
- package/dist/undo-redo.js +33 -0
- package/dist/use-debounce.d.ts +9 -0
- package/dist/use-debounce.js +13 -0
- package/dist/utils.d.ts +58 -0
- package/dist/utils.js +72 -0
- package/package.json +52 -42
- package/CHANGELOG.json +0 -1
- package/CHANGELOG.md +0 -449
- package/lib/axis/arrow.js +0 -79
- package/lib/axis/arrow.js.map +0 -1
- package/lib/axis/axes.js +0 -327
- package/lib/axis/axes.js.map +0 -1
- package/lib/axis/index.js +0 -21
- package/lib/axis/index.js.map +0 -1
- package/lib/bg.js +0 -114
- package/lib/bg.js.map +0 -1
- package/lib/container/actions.js +0 -18
- package/lib/container/actions.js.map +0 -1
- package/lib/container/index.js +0 -129
- package/lib/container/index.js.map +0 -1
- package/lib/container/marks.js +0 -22
- package/lib/container/marks.js.map +0 -1
- package/lib/container/middleware.js +0 -19
- package/lib/container/middleware.js.map +0 -1
- package/lib/container/reducer.js +0 -18
- package/lib/container/reducer.js.map +0 -1
- package/lib/coordinates-label.js +0 -77
- package/lib/coordinates-label.js.map +0 -1
- package/lib/graph-with-controls.js +0 -297
- package/lib/graph-with-controls.js.map +0 -1
- package/lib/graph.js +0 -353
- package/lib/graph.js.map +0 -1
- package/lib/grid-setup.js +0 -414
- package/lib/grid-setup.js.map +0 -1
- package/lib/grid.js +0 -131
- package/lib/grid.js.map +0 -1
- package/lib/index.js +0 -40
- package/lib/index.js.map +0 -1
- package/lib/labels.js +0 -199
- package/lib/labels.js.map +0 -1
- package/lib/mark-label.js +0 -159
- package/lib/mark-label.js.map +0 -1
- package/lib/toggle-bar.js +0 -248
- package/lib/toggle-bar.js.map +0 -1
- package/lib/tool-menu.js +0 -218
- package/lib/tool-menu.js.map +0 -1
- package/lib/tools/index.js +0 -24
- package/lib/tools/index.js.map +0 -1
- package/lib/tools/line/component.js +0 -92
- package/lib/tools/line/component.js.map +0 -1
- package/lib/tools/line/index.js +0 -11
- package/lib/tools/line/index.js.map +0 -1
- package/lib/tools/polygon/component.js +0 -358
- package/lib/tools/polygon/component.js.map +0 -1
- package/lib/tools/polygon/index.js +0 -89
- package/lib/tools/polygon/index.js.map +0 -1
- package/lib/tools/polygon/line.js +0 -114
- package/lib/tools/polygon/line.js.map +0 -1
- package/lib/tools/polygon/polygon.js +0 -128
- package/lib/tools/polygon/polygon.js.map +0 -1
- package/lib/tools/shared/arrow-head.js +0 -62
- package/lib/tools/shared/arrow-head.js.map +0 -1
- package/lib/tools/shared/line/index.js +0 -539
- package/lib/tools/shared/line/index.js.map +0 -1
- package/lib/tools/shared/line/line-path.js +0 -121
- package/lib/tools/shared/line/line-path.js.map +0 -1
- package/lib/tools/shared/line/with-root-edge.js +0 -121
- package/lib/tools/shared/line/with-root-edge.js.map +0 -1
- package/lib/tools/shared/point/arrow-point.js +0 -86
- package/lib/tools/shared/point/arrow-point.js.map +0 -1
- package/lib/tools/shared/point/arrow.js +0 -70
- package/lib/tools/shared/point/arrow.js.map +0 -1
- package/lib/tools/shared/point/base-point.js +0 -137
- package/lib/tools/shared/point/base-point.js.map +0 -1
- package/lib/tools/shared/point/index.js +0 -80
- package/lib/tools/shared/point/index.js.map +0 -1
- package/lib/tools/shared/styles.js +0 -26
- package/lib/tools/shared/styles.js.map +0 -1
- package/lib/tools/shared/types.js +0 -15
- package/lib/tools/shared/types.js.map +0 -1
- package/lib/undo-redo.js +0 -67
- package/lib/undo-redo.js.map +0 -1
- package/lib/use-debounce.js +0 -25
- package/lib/use-debounce.js.map +0 -1
- package/lib/utils.js +0 -235
- package/lib/utils.js.map +0 -1
- package/src/axis/arrow.jsx +0 -57
- package/src/axis/axes.jsx +0 -284
- package/src/axis/index.js +0 -3
- package/src/bg.jsx +0 -96
- package/src/container/actions.js +0 -8
- package/src/container/index.jsx +0 -93
- package/src/container/marks.js +0 -14
- package/src/container/middleware.js +0 -7
- package/src/container/reducer.js +0 -5
- package/src/coordinates-label.jsx +0 -62
- package/src/graph-with-controls.jsx +0 -242
- package/src/graph.jsx +0 -333
- package/src/grid-setup.jsx +0 -432
- package/src/grid.jsx +0 -133
- package/src/index.js +0 -7
- package/src/labels.jsx +0 -173
- package/src/mark-label.jsx +0 -125
- package/src/toggle-bar.jsx +0 -221
- package/src/tool-menu.jsx +0 -235
- package/src/tools/index.js +0 -8
- package/src/tools/line/component.jsx +0 -77
- package/src/tools/line/index.js +0 -4
- package/src/tools/polygon/component.jsx +0 -324
- package/src/tools/polygon/index.js +0 -52
- package/src/tools/polygon/line.jsx +0 -80
- package/src/tools/polygon/polygon.jsx +0 -93
- package/src/tools/shared/arrow-head.jsx +0 -46
- package/src/tools/shared/line/index.jsx +0 -471
- package/src/tools/shared/line/line-path.jsx +0 -85
- package/src/tools/shared/line/with-root-edge.jsx +0 -97
- package/src/tools/shared/point/arrow-point.jsx +0 -60
- package/src/tools/shared/point/arrow.jsx +0 -40
- package/src/tools/shared/point/base-point.jsx +0 -113
- package/src/tools/shared/point/index.jsx +0 -58
- package/src/tools/shared/styles.js +0 -20
- package/src/tools/shared/types.js +0 -8
- package/src/undo-redo.jsx +0 -37
- package/src/use-debounce.js +0 -13
- package/src/utils.js +0 -230
package/src/axis/axes.jsx
DELETED
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Axis } from '@visx/axis';
|
|
3
|
-
import { types } from '@pie-lib/plot';
|
|
4
|
-
import PropTypes from 'prop-types';
|
|
5
|
-
import Arrow from './arrow';
|
|
6
|
-
import { styled } from '@mui/material/styles';
|
|
7
|
-
import { amountToIncreaseWidth, countWords, findLongestWord, getTickValues } from '../utils';
|
|
8
|
-
import { color, Readable } from '@pie-lib/render-ui';
|
|
9
|
-
|
|
10
|
-
export const AxisPropTypes = {
|
|
11
|
-
includeArrows: PropTypes.object,
|
|
12
|
-
graphProps: PropTypes.object,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
const AxisDefaultProps = {
|
|
16
|
-
includeArrows: {
|
|
17
|
-
left: true,
|
|
18
|
-
right: true,
|
|
19
|
-
up: true,
|
|
20
|
-
down: true,
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const StyledAxesGroup = styled('g')(() => ({
|
|
25
|
-
'& .visx-axis-line': {
|
|
26
|
-
stroke: '#8a92c0',
|
|
27
|
-
strokeWidth: 4,
|
|
28
|
-
},
|
|
29
|
-
'& .visx-axis-tick': {
|
|
30
|
-
fill: color.defaults.BLACK,
|
|
31
|
-
'& > line': {
|
|
32
|
-
stroke: '#8a92c0',
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
}));
|
|
36
|
-
|
|
37
|
-
const AxisLabelHolder = styled('div')(({ theme, centered }) => ({
|
|
38
|
-
padding: 0,
|
|
39
|
-
margin: 0,
|
|
40
|
-
'* > *': {
|
|
41
|
-
margin: 0,
|
|
42
|
-
padding: 0,
|
|
43
|
-
},
|
|
44
|
-
'& p': {
|
|
45
|
-
margin: 0,
|
|
46
|
-
},
|
|
47
|
-
fontSize: theme.typography.fontSize,
|
|
48
|
-
...(centered && { textAlign: 'center' }),
|
|
49
|
-
}));
|
|
50
|
-
|
|
51
|
-
const StyledArrow = styled(Arrow)({
|
|
52
|
-
fill: '#8a92c0',
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const tickLabelStyles = {
|
|
56
|
-
fontFamily: 'Roboto',
|
|
57
|
-
fontSize: '14px',
|
|
58
|
-
cursor: 'inherit',
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export const sharedValues = (
|
|
62
|
-
firstNegativeX,
|
|
63
|
-
firstNegativeY,
|
|
64
|
-
distanceFromOriginToFirstNegativeX,
|
|
65
|
-
distanceFromOriginToFirstNegativeY,
|
|
66
|
-
deltaAllowance,
|
|
67
|
-
dy,
|
|
68
|
-
) => {
|
|
69
|
-
let result = [];
|
|
70
|
-
|
|
71
|
-
if (
|
|
72
|
-
firstNegativeX === firstNegativeY &&
|
|
73
|
-
distanceFromOriginToFirstNegativeX - deltaAllowance < distanceFromOriginToFirstNegativeY &&
|
|
74
|
-
distanceFromOriginToFirstNegativeY < distanceFromOriginToFirstNegativeX + deltaAllowance &&
|
|
75
|
-
distanceFromOriginToFirstNegativeX - deltaAllowance < dy &&
|
|
76
|
-
dy < distanceFromOriginToFirstNegativeX + deltaAllowance
|
|
77
|
-
) {
|
|
78
|
-
result.push(firstNegativeX);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return result;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
export const firstNegativeValue = (interval) => (interval || []).find((element) => element < 0);
|
|
85
|
-
|
|
86
|
-
export class RawXAxis extends React.Component {
|
|
87
|
-
static propTypes = {
|
|
88
|
-
...AxisPropTypes,
|
|
89
|
-
graphProps: types.GraphPropsType.isRequired,
|
|
90
|
-
};
|
|
91
|
-
static defaultProps = AxisDefaultProps;
|
|
92
|
-
|
|
93
|
-
render() {
|
|
94
|
-
const { includeArrows, graphProps, columnTicksValues, skipValues, distanceFromOriginToFirstNegativeY, dy } =
|
|
95
|
-
this.props;
|
|
96
|
-
const { scale, domain, size, range } = graphProps || {};
|
|
97
|
-
|
|
98
|
-
const labelProps = (label) => {
|
|
99
|
-
const y = skipValues && skipValues[0] === label ? distanceFromOriginToFirstNegativeY + 4 : dy;
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
...tickLabelStyles,
|
|
103
|
-
textAnchor: 'middle',
|
|
104
|
-
y: y,
|
|
105
|
-
dx: label === 0 ? -10 : 0,
|
|
106
|
-
dy: label === 0 ? -7 : 0,
|
|
107
|
-
};
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const necessaryRows = countWords(domain.axisLabel);
|
|
111
|
-
const longestWord = findLongestWord(domain.axisLabel);
|
|
112
|
-
const necessaryWidth = amountToIncreaseWidth(longestWord) + 2;
|
|
113
|
-
|
|
114
|
-
return (
|
|
115
|
-
<StyledAxesGroup>
|
|
116
|
-
<Axis
|
|
117
|
-
scale={scale.x}
|
|
118
|
-
top={scale.y(0)}
|
|
119
|
-
left={0}
|
|
120
|
-
label={domain.label}
|
|
121
|
-
rangePadding={8}
|
|
122
|
-
tickFormat={(value) => value}
|
|
123
|
-
tickLabelProps={labelProps}
|
|
124
|
-
tickValues={columnTicksValues}
|
|
125
|
-
hideZero={!(domain.labelStep || range.labelStep) && domain.min <= 0}
|
|
126
|
-
/>
|
|
127
|
-
{includeArrows && includeArrows.left && <StyledArrow direction="left" x={domain.min} y={0} scale={scale} />}
|
|
128
|
-
{includeArrows && includeArrows.right && <StyledArrow direction="right" x={domain.max} y={0} scale={scale} />}
|
|
129
|
-
{domain.axisLabel && (
|
|
130
|
-
<foreignObject x={size.width + 17} y={scale.y(0) - 9} width={necessaryWidth} height={20 * necessaryRows}>
|
|
131
|
-
<Readable false>
|
|
132
|
-
<AxisLabelHolder dangerouslySetInnerHTML={{ __html: domain.axisLabel }} />
|
|
133
|
-
</Readable>
|
|
134
|
-
</foreignObject>
|
|
135
|
-
)}
|
|
136
|
-
</StyledAxesGroup>
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const XAxis = RawXAxis;
|
|
142
|
-
|
|
143
|
-
export class RawYAxis extends React.Component {
|
|
144
|
-
static propTypes = {
|
|
145
|
-
...AxisPropTypes,
|
|
146
|
-
graphProps: types.GraphPropsType.isRequired,
|
|
147
|
-
};
|
|
148
|
-
static defaultProps = AxisDefaultProps;
|
|
149
|
-
|
|
150
|
-
render() {
|
|
151
|
-
const { includeArrows, graphProps, skipValues, rowTickValues } = this.props;
|
|
152
|
-
const { scale, range, size } = graphProps || {};
|
|
153
|
-
|
|
154
|
-
const necessaryWidth = range.axisLabel ? amountToIncreaseWidth(range.axisLabel.length) : 0;
|
|
155
|
-
|
|
156
|
-
const customTickFormat = (value) => (skipValues && skipValues.indexOf(value) >= 0 ? '' : value);
|
|
157
|
-
|
|
158
|
-
return (
|
|
159
|
-
<StyledAxesGroup>
|
|
160
|
-
<Axis
|
|
161
|
-
orientation={'left'}
|
|
162
|
-
scale={scale.y}
|
|
163
|
-
top={0}
|
|
164
|
-
height={size.height}
|
|
165
|
-
left={scale.x(0)}
|
|
166
|
-
label={range.label}
|
|
167
|
-
labelProps={{ 'data-pie-readable': false }}
|
|
168
|
-
rangePadding={8}
|
|
169
|
-
tickLength={10}
|
|
170
|
-
tickFormat={customTickFormat}
|
|
171
|
-
tickLabelProps={(value) => {
|
|
172
|
-
let digits = value.toLocaleString().replace(/[.-]/g, '').length || 1;
|
|
173
|
-
|
|
174
|
-
return {
|
|
175
|
-
...tickLabelStyles,
|
|
176
|
-
dy: 4,
|
|
177
|
-
dx: -10 - digits * 9,
|
|
178
|
-
'data-pie-readable': false,
|
|
179
|
-
};
|
|
180
|
-
}}
|
|
181
|
-
hideZero={true}
|
|
182
|
-
tickTextAnchor={'bottom'}
|
|
183
|
-
tickValues={rowTickValues}
|
|
184
|
-
/>
|
|
185
|
-
{includeArrows && includeArrows.down && <StyledArrow direction="down" x={0} y={range.min} scale={scale} />}
|
|
186
|
-
{includeArrows && includeArrows.up && <StyledArrow direction="up" x={0} y={range.max} scale={scale} />}
|
|
187
|
-
{range.axisLabel && (
|
|
188
|
-
<foreignObject x={scale.x(0) - necessaryWidth / 2} y={-33} width={necessaryWidth} height="20">
|
|
189
|
-
<Readable false>
|
|
190
|
-
<AxisLabelHolder centered dangerouslySetInnerHTML={{ __html: range.axisLabel }} />
|
|
191
|
-
</Readable>
|
|
192
|
-
</foreignObject>
|
|
193
|
-
)}
|
|
194
|
-
</StyledAxesGroup>
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
const YAxis = RawYAxis;
|
|
200
|
-
|
|
201
|
-
export default class Axes extends React.Component {
|
|
202
|
-
static propTypes = {
|
|
203
|
-
...AxisPropTypes,
|
|
204
|
-
graphProps: types.GraphPropsType.isRequired,
|
|
205
|
-
};
|
|
206
|
-
static defaultProps = AxisDefaultProps;
|
|
207
|
-
|
|
208
|
-
xValues = () => {
|
|
209
|
-
const { graphProps } = this.props;
|
|
210
|
-
const { scale, domain } = graphProps || {};
|
|
211
|
-
|
|
212
|
-
if (!domain || !scale) {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const ticks = getTickValues({ ...domain, step: domain.labelStep });
|
|
217
|
-
const negative = firstNegativeValue(ticks);
|
|
218
|
-
|
|
219
|
-
return {
|
|
220
|
-
columnTicksValues: ticks,
|
|
221
|
-
firstNegativeX: negative,
|
|
222
|
-
distanceFromOriginToFirstNegativeX: Math.abs(scale.y(0) - scale.y(negative)),
|
|
223
|
-
};
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
yValues = () => {
|
|
227
|
-
const { graphProps } = this.props;
|
|
228
|
-
const { scale, range } = graphProps || {};
|
|
229
|
-
|
|
230
|
-
if (!range || !scale) {
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
const ticks = getTickValues({ ...range, step: range.labelStep });
|
|
235
|
-
const negative = firstNegativeValue(ticks);
|
|
236
|
-
|
|
237
|
-
return {
|
|
238
|
-
rowTickValues: ticks,
|
|
239
|
-
firstNegativeY: negative,
|
|
240
|
-
distanceFromOriginToFirstNegativeY: Math.abs(scale.x(0) - scale.x(negative)),
|
|
241
|
-
};
|
|
242
|
-
};
|
|
243
|
-
|
|
244
|
-
render() {
|
|
245
|
-
const { graphProps } = this.props;
|
|
246
|
-
const { domain, range } = graphProps || {};
|
|
247
|
-
const { columnTicksValues, firstNegativeX, distanceFromOriginToFirstNegativeX } = this.xValues();
|
|
248
|
-
const { rowTickValues, firstNegativeY, distanceFromOriginToFirstNegativeY } = this.yValues();
|
|
249
|
-
const deltaAllowance = 6;
|
|
250
|
-
const dy = 25;
|
|
251
|
-
|
|
252
|
-
const skipValues = sharedValues(
|
|
253
|
-
firstNegativeX,
|
|
254
|
-
firstNegativeY,
|
|
255
|
-
distanceFromOriginToFirstNegativeX,
|
|
256
|
-
distanceFromOriginToFirstNegativeY,
|
|
257
|
-
deltaAllowance,
|
|
258
|
-
dy,
|
|
259
|
-
);
|
|
260
|
-
|
|
261
|
-
// each axis has to be displayed only if the domain & range include it
|
|
262
|
-
return (
|
|
263
|
-
<StyledAxesGroup>
|
|
264
|
-
{range.min <= 0 ? (
|
|
265
|
-
<XAxis
|
|
266
|
-
{...this.props}
|
|
267
|
-
skipValues={skipValues}
|
|
268
|
-
columnTicksValues={columnTicksValues}
|
|
269
|
-
distanceFromOriginToFirstNegativeY={distanceFromOriginToFirstNegativeY}
|
|
270
|
-
dy={dy}
|
|
271
|
-
/>
|
|
272
|
-
) : null}
|
|
273
|
-
{domain.min <= 0 ? (
|
|
274
|
-
<YAxis
|
|
275
|
-
{...this.props}
|
|
276
|
-
skipValues={skipValues}
|
|
277
|
-
rowTickValues={rowTickValues}
|
|
278
|
-
distanceFromOriginToFirstNegativeX={distanceFromOriginToFirstNegativeX}
|
|
279
|
-
/>
|
|
280
|
-
) : null}
|
|
281
|
-
</StyledAxesGroup>
|
|
282
|
-
);
|
|
283
|
-
}
|
|
284
|
-
}
|
package/src/axis/index.js
DELETED
package/src/bg.jsx
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { pointer, select } from 'd3-selection';
|
|
4
|
-
import { types, utils } from '@pie-lib/plot';
|
|
5
|
-
import { getTickValues, thinnerShapesNeeded } from './utils';
|
|
6
|
-
|
|
7
|
-
export default class Bg extends React.Component {
|
|
8
|
-
static propTypes = {
|
|
9
|
-
width: PropTypes.number.isRequired,
|
|
10
|
-
height: PropTypes.number.isRequired,
|
|
11
|
-
onClick: PropTypes.func.isRequired,
|
|
12
|
-
graphProps: types.GraphPropsType.isRequired,
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
static defaultProps = {};
|
|
16
|
-
|
|
17
|
-
componentDidMount() {
|
|
18
|
-
const rect = select(this.rect);
|
|
19
|
-
|
|
20
|
-
rect.on('click', (event) => this.onRectClick(rect, event));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
shouldComponentUpdate(nextProps) {
|
|
24
|
-
return (
|
|
25
|
-
!utils.isDomainRangeEqual(this.props.graphProps, nextProps.graphProps) ||
|
|
26
|
-
this.props.width !== nextProps.width ||
|
|
27
|
-
this.props.height !== nextProps.height
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
getRectPadding = () => {
|
|
32
|
-
const { graphProps } = this.props;
|
|
33
|
-
|
|
34
|
-
return thinnerShapesNeeded(graphProps) ? 6 : 10;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Note: we use d3 click + pointer to give us domain values directly.
|
|
39
|
-
* Saves us having to calculate them ourselves from a MouseEvent.
|
|
40
|
-
*/
|
|
41
|
-
onRectClick = (rect, event) => {
|
|
42
|
-
const { onClick, graphProps } = this.props;
|
|
43
|
-
const { scale } = graphProps;
|
|
44
|
-
|
|
45
|
-
const padding = this.getRectPadding();
|
|
46
|
-
const coords = pointer(event, rect.node());
|
|
47
|
-
|
|
48
|
-
// decrease the padding from coordinates to indicate the correct point clicked
|
|
49
|
-
const x = scale.x.invert(coords[0] - padding);
|
|
50
|
-
const y = scale.y.invert(coords[1] - padding);
|
|
51
|
-
|
|
52
|
-
const rowTicks = getTickValues(graphProps.range);
|
|
53
|
-
const columnTicks = getTickValues(graphProps.domain);
|
|
54
|
-
|
|
55
|
-
const closest = (ticks, value) => {
|
|
56
|
-
return (
|
|
57
|
-
ticks.length &&
|
|
58
|
-
ticks.reduce((prev, curr) => {
|
|
59
|
-
const currentDistance = Math.abs(curr - value);
|
|
60
|
-
const previousDistance = Math.abs(prev - value);
|
|
61
|
-
|
|
62
|
-
return currentDistance <= previousDistance ? curr : prev;
|
|
63
|
-
})
|
|
64
|
-
);
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
let snapped = {};
|
|
68
|
-
|
|
69
|
-
if (columnTicks.indexOf(x) >= 0 && rowTicks.indexOf(y) >= 0) {
|
|
70
|
-
snapped.x = x;
|
|
71
|
-
snapped.y = y;
|
|
72
|
-
} else {
|
|
73
|
-
snapped.x = closest(columnTicks, x);
|
|
74
|
-
snapped.y = closest(rowTicks, y);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
onClick(snapped);
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
render() {
|
|
81
|
-
const { width, height } = this.props;
|
|
82
|
-
const padding = this.getRectPadding();
|
|
83
|
-
|
|
84
|
-
// expand the size of clickable area so a small area outside the edges of the grid lines to be clickable
|
|
85
|
-
return (
|
|
86
|
-
<rect
|
|
87
|
-
ref={(rect) => (this.rect = rect)}
|
|
88
|
-
transform={`translate(-${padding}, -${padding})`}
|
|
89
|
-
fill="red"
|
|
90
|
-
fillOpacity="0.0"
|
|
91
|
-
width={width + padding * 2}
|
|
92
|
-
height={height + padding * 2}
|
|
93
|
-
/>
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
}
|
package/src/container/actions.js
DELETED
package/src/container/index.jsx
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { connect, Provider } from 'react-redux';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
import { applyMiddleware, createStore } from 'redux';
|
|
4
|
-
import reducer from './reducer';
|
|
5
|
-
import { changeMarks } from './actions';
|
|
6
|
-
import PropTypes from 'prop-types';
|
|
7
|
-
import { isEqual } from 'lodash-es';
|
|
8
|
-
import { ActionCreators } from 'redux-undo';
|
|
9
|
-
import GraphWithControls from '../graph-with-controls';
|
|
10
|
-
import { getLastAction, lastActionMiddleware } from './middleware';
|
|
11
|
-
|
|
12
|
-
const mapStateToProps = (s) => ({
|
|
13
|
-
marks: s.marks.present,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
const mapDispatchToProps = (dispatch) => ({
|
|
17
|
-
onChangeMarks: (m) => dispatch(changeMarks(m)),
|
|
18
|
-
onUndo: () => dispatch(ActionCreators.undo()),
|
|
19
|
-
onRedo: () => dispatch(ActionCreators.redo()),
|
|
20
|
-
onReset: () => dispatch(changeMarks([])),
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
export const GraphContainer = connect(mapStateToProps, mapDispatchToProps)(GraphWithControls);
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* The graph component entry point with undo/redo
|
|
27
|
-
* Redux is an implementation detail, hide it in the react component.
|
|
28
|
-
*/
|
|
29
|
-
class Root extends React.Component {
|
|
30
|
-
static propTypes = {
|
|
31
|
-
onChangeMarks: PropTypes.func,
|
|
32
|
-
marks: PropTypes.array,
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
constructor(props) {
|
|
36
|
-
super(props);
|
|
37
|
-
|
|
38
|
-
const r = reducer();
|
|
39
|
-
this.store = createStore(r, { marks: props.marks }, applyMiddleware(lastActionMiddleware));
|
|
40
|
-
|
|
41
|
-
this.store.subscribe(this.onStoreChange);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
componentDidUpdate(prevProps) {
|
|
45
|
-
const { marks } = this.props;
|
|
46
|
-
const storeState = this.store.getState();
|
|
47
|
-
|
|
48
|
-
if (isEqual(storeState.marks.present, marks)) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (!isEqual(prevProps.marks, marks)) {
|
|
53
|
-
// Don't dispatch marks that have correctness (evaluate mode marks) into the undo history.
|
|
54
|
-
// These marks are already handled in render() via the correctnessSet path and bypass the
|
|
55
|
-
// Redux store entirely. Dispatching them would pollute the undo history and cause the graph
|
|
56
|
-
// to show the correct answer when the user presses undo after returning to gather mode.
|
|
57
|
-
const hasCorrectness = marks && marks.find((m) => m.correctness);
|
|
58
|
-
|
|
59
|
-
if (!hasCorrectness) {
|
|
60
|
-
this.store.dispatch(changeMarks(marks));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
onStoreChange = () => {
|
|
66
|
-
const { marks, onChangeMarks } = this.props;
|
|
67
|
-
const storeState = this.store.getState();
|
|
68
|
-
const lastAction = getLastAction();
|
|
69
|
-
const isUndoOperation = lastAction.type.includes('UNDO') || lastAction.type.includes('REDO');
|
|
70
|
-
|
|
71
|
-
if (!isEqual(storeState.marks.present, marks)) {
|
|
72
|
-
onChangeMarks(storeState.marks.present, isUndoOperation);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
render() {
|
|
77
|
-
// eslint-disable-next-line no-unused-vars
|
|
78
|
-
const { onChangeMarks, marks, ...rest } = this.props;
|
|
79
|
-
const correctnessSet = marks && marks.find((m) => m.correctness);
|
|
80
|
-
|
|
81
|
-
if (correctnessSet) {
|
|
82
|
-
return <GraphWithControls {...rest} marks={marks} disabled={correctnessSet} />;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return (
|
|
86
|
-
<Provider store={this.store}>
|
|
87
|
-
<GraphContainer {...rest} />
|
|
88
|
-
</Provider>
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export default Root;
|
package/src/container/marks.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const marks = (state = [], action) => {
|
|
2
|
-
switch (action.type) {
|
|
3
|
-
case 'CHANGE_MARKS':
|
|
4
|
-
if (Array.isArray(action.marks)) {
|
|
5
|
-
return action.marks;
|
|
6
|
-
} else {
|
|
7
|
-
throw new Error('marks must be an array');
|
|
8
|
-
}
|
|
9
|
-
default:
|
|
10
|
-
return state;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default marks;
|
package/src/container/reducer.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import { types } from '@pie-lib/plot';
|
|
4
|
-
import { color } from '@pie-lib/render-ui';
|
|
5
|
-
import { styled } from '@mui/material/styles';
|
|
6
|
-
import InputBase from '@mui/material/InputBase';
|
|
7
|
-
import { roundNumber } from './utils';
|
|
8
|
-
|
|
9
|
-
const StyledInputBase = styled(InputBase)(({ theme }) => ({
|
|
10
|
-
fontFamily: theme.typography.fontFamily,
|
|
11
|
-
fontSize: theme.typography.fontSize,
|
|
12
|
-
borderRadius: '8px',
|
|
13
|
-
background: theme.palette.common.white,
|
|
14
|
-
color: color.defaults.BLACK,
|
|
15
|
-
'& .MuiInputBase-input': {
|
|
16
|
-
padding: 0,
|
|
17
|
-
},
|
|
18
|
-
}));
|
|
19
|
-
|
|
20
|
-
export const getLabelPosition = (graphProps, x, y, labelLength) => {
|
|
21
|
-
const { scale, domain, range } = graphProps;
|
|
22
|
-
// treat corner cases for maximum and minimum
|
|
23
|
-
const topShift = y === range.min ? 16 : y === range.max ? 0 : 8;
|
|
24
|
-
const leftShift = 10;
|
|
25
|
-
const rightEdge = scale.x(x) + labelLength + leftShift;
|
|
26
|
-
|
|
27
|
-
if (rightEdge >= scale.x(domain.max)) {
|
|
28
|
-
return {
|
|
29
|
-
left: scale.x(x) - leftShift - labelLength,
|
|
30
|
-
top: scale.y(y) - topShift,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
left: scale.x(x) + leftShift,
|
|
36
|
-
top: scale.y(y) - topShift,
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const CoordinatesLabel = ({ x, y, graphProps }) => {
|
|
41
|
-
const label = `(${roundNumber(x)}, ${roundNumber(y)})`;
|
|
42
|
-
const labelLength = (label.length || 0) * 6;
|
|
43
|
-
const labelPosition = getLabelPosition(graphProps, x, y, labelLength);
|
|
44
|
-
|
|
45
|
-
const style = {
|
|
46
|
-
position: 'absolute',
|
|
47
|
-
pointerEvents: 'auto',
|
|
48
|
-
width: labelLength,
|
|
49
|
-
padding: 0,
|
|
50
|
-
...labelPosition,
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
return <StyledInputBase style={style} value={label} inputProps={{ ariaLabel: 'naked' }} />;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
CoordinatesLabel.propTypes = {
|
|
57
|
-
graphProps: types.GraphPropsType,
|
|
58
|
-
x: PropTypes.number,
|
|
59
|
-
y: PropTypes.number,
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export default CoordinatesLabel;
|