@pie-lib/graphing 2.4.2-next.26 → 2.4.3-next.118
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/CHANGELOG.md +24 -111
- package/lib/axis/arrow.js +5 -5
- package/lib/axis/arrow.js.map +1 -1
- package/lib/axis/axes.js +17 -27
- package/lib/axis/axes.js.map +1 -1
- package/lib/graph.js +4 -4
- package/lib/graph.js.map +1 -1
- package/lib/tools/line/component.js +8 -1
- package/lib/tools/line/component.js.map +1 -1
- package/lib/tools/ray/component.js +8 -1
- package/lib/tools/ray/component.js.map +1 -1
- package/lib/tools/shared/point/arrow.js +3 -1
- package/lib/tools/shared/point/arrow.js.map +1 -1
- package/lib/tools/shared/point/base-point.js +4 -1
- package/lib/tools/shared/point/base-point.js.map +1 -1
- package/lib/utils.js +46 -1
- package/lib/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/axis/arrow.jsx +5 -5
- package/src/axis/axes.jsx +24 -35
- package/src/graph.jsx +4 -4
- package/src/tools/line/component.jsx +6 -1
- package/src/tools/ray/component.jsx +5 -1
- package/src/tools/shared/point/arrow.jsx +2 -1
- package/src/tools/shared/point/base-point.jsx +3 -1
- package/src/utils.js +43 -0
|
@@ -5,6 +5,7 @@ import { ArrowMarker, genUid } from '../shared/arrow-head';
|
|
|
5
5
|
import { trig, types } from '@pie-lib/plot';
|
|
6
6
|
import { withStyles } from '@material-ui/core/styles';
|
|
7
7
|
import classNames from 'classnames';
|
|
8
|
+
import { thinnerShapesNeeded, getAdjustedGraphLimits } from '../../utils';
|
|
8
9
|
|
|
9
10
|
const markerId = genUid();
|
|
10
11
|
|
|
@@ -18,16 +19,19 @@ const rayStyles = theme => ({
|
|
|
18
19
|
incorrect: styles.incorrect(theme, 'stroke'),
|
|
19
20
|
incorrectArrow: styles.incorrect(theme)
|
|
20
21
|
});
|
|
22
|
+
|
|
21
23
|
export const RayLine = props => {
|
|
22
24
|
const { graphProps, from, to, classes, disabled, correctness, className, ...rest } = props;
|
|
23
25
|
const { scale } = graphProps;
|
|
24
|
-
const
|
|
26
|
+
const { domain, range } = getAdjustedGraphLimits(graphProps);
|
|
27
|
+
const [aToB] = trig.edges(domain, range)(from, to);
|
|
25
28
|
const suffix = correctness || (disabled && 'disabled') || 'enabled';
|
|
26
29
|
|
|
27
30
|
return (
|
|
28
31
|
<g>
|
|
29
32
|
<defs>
|
|
30
33
|
<ArrowMarker
|
|
34
|
+
size={thinnerShapesNeeded(graphProps) ? 4 : 5}
|
|
31
35
|
id={`${props.markerId || markerId}-${suffix}`}
|
|
32
36
|
className={classNames(classes[`${suffix}Arrow`])}
|
|
33
37
|
/>
|
|
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
|
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { types } from '@pie-lib/plot';
|
|
5
5
|
import { ArrowHead } from '../arrow-head';
|
|
6
|
+
import { thinnerShapesNeeded } from '../../../utils';
|
|
6
7
|
|
|
7
8
|
export default class Arrow extends React.Component {
|
|
8
9
|
static propTypes = {
|
|
@@ -48,7 +49,7 @@ export default class Arrow extends React.Component {
|
|
|
48
49
|
...rest
|
|
49
50
|
} = this.props;
|
|
50
51
|
|
|
51
|
-
const size = 14;
|
|
52
|
+
const size = thinnerShapesNeeded(graphProps) ? 12 : 14;
|
|
52
53
|
const { scale } = graphProps;
|
|
53
54
|
|
|
54
55
|
const scaledX = scale.x(x);
|
|
@@ -4,6 +4,7 @@ import classNames from 'classnames';
|
|
|
4
4
|
import { types } from '@pie-lib/plot';
|
|
5
5
|
import CoordinatesLabel from '../../../coordinates-label';
|
|
6
6
|
import ReactDOM from 'react-dom';
|
|
7
|
+
import { thinnerShapesNeeded } from '../../../utils';
|
|
7
8
|
|
|
8
9
|
export class RawBp extends React.Component {
|
|
9
10
|
static propTypes = {
|
|
@@ -38,6 +39,7 @@ export class RawBp extends React.Component {
|
|
|
38
39
|
} = this.props;
|
|
39
40
|
const { showCoordinates } = this.state;
|
|
40
41
|
const { scale } = graphProps;
|
|
42
|
+
const r = thinnerShapesNeeded(graphProps) ? 5 : 7;
|
|
41
43
|
|
|
42
44
|
return (
|
|
43
45
|
<g
|
|
@@ -51,7 +53,7 @@ export class RawBp extends React.Component {
|
|
|
51
53
|
onMouseLeave={() => this.setState({ showCoordinates: false })}
|
|
52
54
|
{...rest}
|
|
53
55
|
>
|
|
54
|
-
<circle r=
|
|
56
|
+
<circle r={r} cx={scale.x(x)} cy={scale.y(y)} />
|
|
55
57
|
{labelNode &&
|
|
56
58
|
coordinatesOnHover &&
|
|
57
59
|
showCoordinates &&
|
package/src/utils.js
CHANGED
|
@@ -132,3 +132,46 @@ export const equalPoints = (p1, p2) =>
|
|
|
132
132
|
y: roundNumber(p2.y)
|
|
133
133
|
}
|
|
134
134
|
);
|
|
135
|
+
|
|
136
|
+
const getDistanceBetweenTicks = (axis, size) => {
|
|
137
|
+
const { min, max, step } = axis;
|
|
138
|
+
const nbOfTicks = (max - min) / step;
|
|
139
|
+
|
|
140
|
+
return size / nbOfTicks;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
export const thinnerShapesNeeded = graphProps => {
|
|
144
|
+
const {
|
|
145
|
+
domain,
|
|
146
|
+
range,
|
|
147
|
+
size: { width, height }
|
|
148
|
+
} = graphProps;
|
|
149
|
+
|
|
150
|
+
// 14 is the default width of a point
|
|
151
|
+
return getDistanceBetweenTicks(domain, width) < 14 || getDistanceBetweenTicks(range, height) < 14;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export const getAdjustedGraphLimits = graphProps => {
|
|
155
|
+
const {
|
|
156
|
+
domain,
|
|
157
|
+
range,
|
|
158
|
+
size: { width, height }
|
|
159
|
+
} = graphProps;
|
|
160
|
+
const domainTicksDistance = getDistanceBetweenTicks(domain, width);
|
|
161
|
+
const rangeTicksDistance = getDistanceBetweenTicks(range, height);
|
|
162
|
+
|
|
163
|
+
// 15 is the distance required for the arrow to extend the graph
|
|
164
|
+
const domainPadding = domain.step / (domainTicksDistance / 15);
|
|
165
|
+
const rangePadding = range.step / (rangeTicksDistance / 15);
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
domain: {
|
|
169
|
+
min: domain.min - domainPadding,
|
|
170
|
+
max: domain.max + domainPadding
|
|
171
|
+
},
|
|
172
|
+
range: {
|
|
173
|
+
min: range.min - rangePadding,
|
|
174
|
+
max: range.max + rangePadding
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
};
|