@pie-lib/graphing 2.4.2 → 2.4.3-next.162
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 +18 -113
- package/lib/axis/arrow.js +5 -5
- package/lib/axis/arrow.js.map +1 -1
- package/lib/axis/axes.js +18 -28
- 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 +50 -5
- package/lib/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/axis/arrow.jsx +5 -5
- package/src/axis/axes.jsx +25 -36
- 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 +47 -4
|
@@ -5,6 +5,8 @@ import { trig, types } from '@pie-lib/plot';
|
|
|
5
5
|
import classNames from 'classnames';
|
|
6
6
|
import { withStyles } from '@material-ui/core/styles';
|
|
7
7
|
import { ArrowMarker, genUid } from '../shared/arrow-head';
|
|
8
|
+
import { thinnerShapesNeeded, getAdjustedGraphLimits } from '../../utils';
|
|
9
|
+
|
|
8
10
|
const markerId = genUid();
|
|
9
11
|
|
|
10
12
|
const lineStyles = theme => ({
|
|
@@ -17,16 +19,19 @@ const lineStyles = theme => ({
|
|
|
17
19
|
incorrect: styles.incorrect(theme, 'stroke'),
|
|
18
20
|
incorrectArrow: styles.incorrect(theme)
|
|
19
21
|
});
|
|
22
|
+
|
|
20
23
|
export const ArrowedLine = props => {
|
|
21
24
|
const { className, classes, correctness, disabled, graphProps, from, to, ...rest } = props;
|
|
22
25
|
const { scale } = graphProps;
|
|
23
|
-
const
|
|
26
|
+
const { domain, range } = getAdjustedGraphLimits(graphProps);
|
|
27
|
+
const [eFrom, eTo] = trig.edges(domain, range)(from, to);
|
|
24
28
|
const suffix = correctness || (disabled && 'disabled') || 'enabled';
|
|
25
29
|
|
|
26
30
|
return (
|
|
27
31
|
<g>
|
|
28
32
|
<defs>
|
|
29
33
|
<ArrowMarker
|
|
34
|
+
size={thinnerShapesNeeded(graphProps) ? 4 : 5}
|
|
30
35
|
id={`${props.markerId || markerId}-${suffix}`}
|
|
31
36
|
className={classNames(classes[`${suffix}Arrow`])}
|
|
32
37
|
/>
|
|
@@ -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
|
@@ -21,14 +21,14 @@ export const getTickValues = prop => {
|
|
|
21
21
|
|
|
22
22
|
while (tickVal >= prop.min && tickValues.indexOf(tickVal) < 0) {
|
|
23
23
|
tickValues.push(tickVal);
|
|
24
|
-
tickVal = Math.round((tickVal - prop.step) *
|
|
24
|
+
tickVal = Math.round((tickVal - prop.step) * 10000) / 10000;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
tickVal = Math.round(prop.step *
|
|
27
|
+
tickVal = Math.round(prop.step * 10000) / 10000;
|
|
28
28
|
|
|
29
29
|
while (tickVal <= prop.max && tickValues.indexOf(tickVal) < 0) {
|
|
30
30
|
tickValues.push(tickVal);
|
|
31
|
-
tickVal = Math.round((tickVal + prop.step) *
|
|
31
|
+
tickVal = Math.round((tickVal + prop.step) * 10000) / 10000;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// return only ticks that are inside the min-max interval
|
|
@@ -114,7 +114,7 @@ export const getMiddleOfTwoPoints = (a, b) => ({
|
|
|
114
114
|
y: (a.y + b.y) / 2
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
-
export const roundNumber = number => parseFloat(number.toFixed(
|
|
117
|
+
export const roundNumber = number => parseFloat(number.toFixed(4));
|
|
118
118
|
|
|
119
119
|
export const sameAxes = (p1, p2) =>
|
|
120
120
|
p1 && p2 && (roundNumber(p1.x) === roundNumber(p2.x) || roundNumber(p1.y) === roundNumber(p2.y));
|
|
@@ -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
|
+
};
|