@pie-lib/graphing-utils 1.1.33-next.0 → 1.1.34-next.1848
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.json +1 -77
- package/CHANGELOG.md +198 -8
- package/NEXT.CHANGELOG.json +1 -0
- package/lib/index.js +174 -14
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/utils.test.js +197 -0
- package/src/index.js +131 -11
- package/README.md +0 -13
package/CHANGELOG.json
CHANGED
|
@@ -1,77 +1 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"type": "feat",
|
|
4
|
-
"scope": null,
|
|
5
|
-
"subject": "moved utils into their own package",
|
|
6
|
-
"merge": null,
|
|
7
|
-
"header": "feat: moved utils into their own package",
|
|
8
|
-
"body": null,
|
|
9
|
-
"footer": null,
|
|
10
|
-
"notes": [],
|
|
11
|
-
"hash": "280341d1cbff12953bccefec417374c0b94077eb",
|
|
12
|
-
"gitTags": "",
|
|
13
|
-
"committerDate": "2019-07-02 08:20:57 -0400",
|
|
14
|
-
"isTagged": true,
|
|
15
|
-
"tag": "@pie-lib/graphing-utils@1.1.0"
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"type": "feat",
|
|
19
|
-
"scope": null,
|
|
20
|
-
"subject": "moved utils into their own package",
|
|
21
|
-
"merge": null,
|
|
22
|
-
"header": "feat: moved utils into their own package",
|
|
23
|
-
"body": null,
|
|
24
|
-
"footer": null,
|
|
25
|
-
"notes": [],
|
|
26
|
-
"hash": "c0b8e003b6928019b6a48f7b334e0c2f9171c8d4",
|
|
27
|
-
"gitTags": "",
|
|
28
|
-
"committerDate": "2019-07-02 08:08:52 -0400",
|
|
29
|
-
"isTagged": true,
|
|
30
|
-
"tag": "@pie-lib/graphing-utils@1.1.0"
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
"type": "feat",
|
|
34
|
-
"scope": null,
|
|
35
|
-
"subject": "moved utils into their own package",
|
|
36
|
-
"merge": null,
|
|
37
|
-
"header": "feat: moved utils into their own package",
|
|
38
|
-
"body": null,
|
|
39
|
-
"footer": null,
|
|
40
|
-
"notes": [],
|
|
41
|
-
"hash": "c9a7d40cec0a4ad75107b81dd1b1228ff0ce446c",
|
|
42
|
-
"gitTags": "",
|
|
43
|
-
"committerDate": "2019-07-02 08:01:12 -0400",
|
|
44
|
-
"isTagged": true,
|
|
45
|
-
"tag": "@pie-lib/graphing-utils@1.1.0"
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
"type": "fix",
|
|
49
|
-
"scope": null,
|
|
50
|
-
"subject": "4136: Parabola graphing is amiss",
|
|
51
|
-
"merge": null,
|
|
52
|
-
"header": "fix: 4136: Parabola graphing is amiss",
|
|
53
|
-
"body": null,
|
|
54
|
-
"footer": null,
|
|
55
|
-
"notes": [],
|
|
56
|
-
"hash": "f915685ce9103b877928385f49318688c8a60d26",
|
|
57
|
-
"gitTags": " (origin/andreea/ch4136/parabola-graphing-is-amiss)",
|
|
58
|
-
"committerDate": "2020-03-09 12:16:32 +0200",
|
|
59
|
-
"isTagged": true,
|
|
60
|
-
"tag": "@pie-lib/graphing-utils@1.1.3"
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
"type": "fix",
|
|
64
|
-
"scope": null,
|
|
65
|
-
"subject": "add module prop to package.json",
|
|
66
|
-
"merge": null,
|
|
67
|
-
"header": "fix: add module prop to package.json",
|
|
68
|
-
"body": null,
|
|
69
|
-
"footer": null,
|
|
70
|
-
"notes": [],
|
|
71
|
-
"hash": "12db87f436f3db537f5157a02fba6c18995748cf",
|
|
72
|
-
"gitTags": "",
|
|
73
|
-
"committerDate": "2020-03-30 13:01:31 +0100",
|
|
74
|
-
"isTagged": true,
|
|
75
|
-
"tag": "@pie-lib/graphing-utils@1.1.4"
|
|
76
|
-
}
|
|
77
|
-
]
|
|
1
|
+
[]
|
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
# [1.16.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.15.0...@pie-lib/graphing-utils@1.16.0) (2025-09-18)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
# [1.15.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.14.0...@pie-lib/graphing-utils@1.15.0) (2025-09-18)
|
|
15
15
|
|
|
16
16
|
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
17
17
|
|
|
@@ -19,7 +19,23 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
# [1.14.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.14.0) (2025-09-18)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* fixed pie-lib/icons import [PD-5126] ([dcb506c](https://github.com/pie-framework/pie-lib/commit/dcb506c914a177f6d88bf73247a023bfe71dac1f))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Features
|
|
31
|
+
|
|
32
|
+
* split pie-toolbox into multiple packages [PD-5126] ([7d55a25](https://github.com/pie-framework/pie-lib/commit/7d55a2552d084cd3d0d5c00dc77411b2ced2f5e2))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# [1.13.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.12.0...@pie-lib/graphing-utils@1.13.0) (2025-09-17)
|
|
23
39
|
|
|
24
40
|
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
25
41
|
|
|
@@ -27,7 +43,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
27
43
|
|
|
28
44
|
|
|
29
45
|
|
|
30
|
-
|
|
46
|
+
# [1.12.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.11.0...@pie-lib/graphing-utils@1.12.0) (2025-09-17)
|
|
31
47
|
|
|
32
48
|
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
33
49
|
|
|
@@ -35,7 +51,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
35
51
|
|
|
36
52
|
|
|
37
53
|
|
|
38
|
-
|
|
54
|
+
# [1.11.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.10.1...@pie-lib/graphing-utils@1.11.0) (2025-09-17)
|
|
39
55
|
|
|
40
56
|
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
41
57
|
|
|
@@ -43,29 +59,203 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
|
|
|
43
59
|
|
|
44
60
|
|
|
45
61
|
|
|
46
|
-
## [1.1
|
|
62
|
+
## [1.10.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.10.1) (2025-08-11)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
### Bug Fixes
|
|
66
|
+
|
|
67
|
+
* fixed pie-lib/icons import [PD-5126] ([dcb506c](https://github.com/pie-framework/pie-lib/commit/dcb506c914a177f6d88bf73247a023bfe71dac1f))
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
### Features
|
|
71
|
+
|
|
72
|
+
* split pie-toolbox into multiple packages [PD-5126] ([7d55a25](https://github.com/pie-framework/pie-lib/commit/7d55a2552d084cd3d0d5c00dc77411b2ced2f5e2))
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# [1.10.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.10.0) (2025-08-07)
|
|
79
|
+
|
|
80
|
+
### Features
|
|
81
|
+
|
|
82
|
+
- split pie-toolbox into multiple packages [PD-5126](<[7d55a25](https://github.com/pie-framework/pie-lib/commit/7d55a2552d084cd3d0d5c00dc77411b2ced2f5e2)>)
|
|
83
|
+
|
|
84
|
+
# [1.9.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.9.0) (2025-07-31)
|
|
47
85
|
|
|
48
86
|
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
49
87
|
|
|
88
|
+
# [1.8.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.8.0) (2025-07-31)
|
|
50
89
|
|
|
90
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
51
91
|
|
|
92
|
+
# [1.7.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.7.0) (2025-07-31)
|
|
52
93
|
|
|
94
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
53
95
|
|
|
54
|
-
|
|
96
|
+
# [1.6.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.6.0) (2025-07-31)
|
|
55
97
|
|
|
56
98
|
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
57
99
|
|
|
100
|
+
# [1.5.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.5.0) (2025-07-31)
|
|
58
101
|
|
|
102
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
59
103
|
|
|
104
|
+
# [1.4.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.4.0) (2025-07-31)
|
|
60
105
|
|
|
106
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
61
107
|
|
|
62
|
-
|
|
108
|
+
# [1.6.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.6.0) (2025-07-31)
|
|
109
|
+
|
|
110
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
111
|
+
|
|
112
|
+
# [1.5.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.5.0) (2025-07-31)
|
|
113
|
+
|
|
114
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
115
|
+
|
|
116
|
+
# [1.4.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.4.0) (2025-07-31)
|
|
117
|
+
|
|
118
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
119
|
+
|
|
120
|
+
# [1.5.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.5.0) (2025-07-31)
|
|
121
|
+
|
|
122
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
123
|
+
|
|
124
|
+
# [1.4.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.4.0) (2025-07-31)
|
|
125
|
+
|
|
126
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
127
|
+
|
|
128
|
+
# [1.3.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.3.0) (2025-07-31)
|
|
129
|
+
|
|
130
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
131
|
+
|
|
132
|
+
# [1.3.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.3.0) (2025-07-31)
|
|
63
133
|
|
|
64
134
|
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
65
135
|
|
|
136
|
+
# [1.4.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.4.0) (2025-07-31)
|
|
66
137
|
|
|
138
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
139
|
+
|
|
140
|
+
# [1.3.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.3.0) (2025-07-31)
|
|
141
|
+
|
|
142
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
143
|
+
|
|
144
|
+
# [1.2.0-beta.8](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.8) (2025-07-25)
|
|
145
|
+
|
|
146
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
147
|
+
|
|
148
|
+
# [1.2.0-beta.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.7) (2025-07-25)
|
|
149
|
+
|
|
150
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
151
|
+
|
|
152
|
+
# [1.2.0-beta.7](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.7) (2025-07-25)
|
|
153
|
+
|
|
154
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
155
|
+
|
|
156
|
+
# [1.2.0-beta.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.6) (2025-07-25)
|
|
157
|
+
|
|
158
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
159
|
+
|
|
160
|
+
# [1.2.0-beta.6](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.6) (2025-07-25)
|
|
161
|
+
|
|
162
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
67
163
|
|
|
164
|
+
# [1.2.0-beta.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.5) (2025-07-25)
|
|
68
165
|
|
|
166
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
167
|
+
|
|
168
|
+
# [1.2.0-beta.5](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.5) (2025-07-25)
|
|
169
|
+
|
|
170
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
171
|
+
|
|
172
|
+
# [1.2.0-beta.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.4) (2025-07-25)
|
|
173
|
+
|
|
174
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
175
|
+
|
|
176
|
+
# [1.2.0-beta.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.3) (2025-07-25)
|
|
177
|
+
|
|
178
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
179
|
+
|
|
180
|
+
# [1.2.0-beta.4](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.4) (2025-07-23)
|
|
181
|
+
|
|
182
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
183
|
+
|
|
184
|
+
# [1.2.0-beta.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.3) (2025-07-23)
|
|
185
|
+
|
|
186
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
187
|
+
|
|
188
|
+
# [1.2.0-beta.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.3) (2025-07-20)
|
|
189
|
+
|
|
190
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
191
|
+
|
|
192
|
+
# [1.2.0-beta.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.2) (2025-07-20)
|
|
193
|
+
|
|
194
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
195
|
+
|
|
196
|
+
# [1.2.0-beta.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.1) (2025-07-20)
|
|
197
|
+
|
|
198
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
199
|
+
|
|
200
|
+
# [1.2.0-beta.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.2) (2025-07-20)
|
|
201
|
+
|
|
202
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
203
|
+
|
|
204
|
+
# [1.2.0-beta.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.1) (2025-07-20)
|
|
205
|
+
|
|
206
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
207
|
+
|
|
208
|
+
# [1.2.0-beta.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.1) (2025-07-20)
|
|
209
|
+
|
|
210
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
211
|
+
|
|
212
|
+
# [1.2.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.0) (2025-07-20)
|
|
213
|
+
|
|
214
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
215
|
+
|
|
216
|
+
# [1.3.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.3.0-beta.0) (2025-07-15)
|
|
217
|
+
|
|
218
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
219
|
+
|
|
220
|
+
# [1.2.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.33...@pie-lib/graphing-utils@1.2.0-beta.0) (2025-07-15)
|
|
221
|
+
|
|
222
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
223
|
+
|
|
224
|
+
## [1.1.33](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.32...@pie-lib/graphing-utils@1.1.33) (2023-06-24)
|
|
225
|
+
|
|
226
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
227
|
+
|
|
228
|
+
## [1.1.32](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.30...@pie-lib/graphing-utils@1.1.32) (2023-01-31)
|
|
229
|
+
|
|
230
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
231
|
+
|
|
232
|
+
## [1.1.30](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.29...@pie-lib/graphing-utils@1.1.30) (2023-01-31)
|
|
233
|
+
|
|
234
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
235
|
+
|
|
236
|
+
## [1.1.29](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.28...@pie-lib/graphing-utils@1.1.29) (2023-01-31)
|
|
237
|
+
|
|
238
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
239
|
+
|
|
240
|
+
## [1.1.28](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.27...@pie-lib/graphing-utils@1.1.28) (2023-01-31)
|
|
241
|
+
|
|
242
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
243
|
+
|
|
244
|
+
## [1.1.27](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.25...@pie-lib/graphing-utils@1.1.27) (2023-01-31)
|
|
245
|
+
|
|
246
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
247
|
+
|
|
248
|
+
## [1.1.25](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.23...@pie-lib/graphing-utils@1.1.25) (2023-01-31)
|
|
249
|
+
|
|
250
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
251
|
+
|
|
252
|
+
## [1.1.23](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.21...@pie-lib/graphing-utils@1.1.23) (2023-01-31)
|
|
253
|
+
|
|
254
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
255
|
+
|
|
256
|
+
## [1.1.21](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.20...@pie-lib/graphing-utils@1.1.21) (2022-11-23)
|
|
257
|
+
|
|
258
|
+
**Note:** Version bump only for package @pie-lib/graphing-utils
|
|
69
259
|
|
|
70
260
|
## [1.1.20](https://github.com/pie-framework/pie-lib/compare/@pie-lib/graphing-utils@1.1.18...@pie-lib/graphing-utils@1.1.20) (2021-06-25)
|
|
71
261
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
package/lib/index.js
CHANGED
|
@@ -5,7 +5,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.xPoints = exports.sinY = exports.pointsToABC = exports.parabolaFromTwoPoints = exports.parabolaFromThreePoints = exports.parabola = exports.getAmplitudeAndFreq = exports.buildDataPoints = exports.FREQ_DIVIDER = void 0;
|
|
8
|
+
exports.xPoints = exports.sinY = exports.pointsToAForAbsolute = exports.pointsToABForExponential = exports.pointsToABC = exports.parabolaFromTwoPoints = exports.parabolaFromThreePoints = exports.parabola = exports.getAmplitudeAndFreq = exports.exponentialFromTwoPoints = exports.exponential = exports["default"] = exports.buildDataPoints = exports.absoluteFromTwoPoints = exports.absolute = exports.FREQ_DIVIDER = void 0;
|
|
9
|
+
|
|
10
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
11
|
|
|
10
12
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
13
|
|
|
@@ -152,32 +154,190 @@ var parabola = function parabola(a, b, c) {
|
|
|
152
154
|
return a * Math.pow(x, 2) + b * x + c;
|
|
153
155
|
};
|
|
154
156
|
};
|
|
157
|
+
/**
|
|
158
|
+
* Absolute value from two points Root (Vertex) the point where the two rays intersect and edge One point on a ray.
|
|
159
|
+
* @param root 1st point selected on graph
|
|
160
|
+
* @param edge 2nd point selected on graph
|
|
161
|
+
* https://www.desmos.com/calculator/rarxiatpip
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
exports.parabola = parabola;
|
|
166
|
+
|
|
167
|
+
var absoluteFromTwoPoints = function absoluteFromTwoPoints(root, edge) {
|
|
168
|
+
edge = edge || _objectSpread({}, root);
|
|
169
|
+
var a = pointsToAForAbsolute(root, edge);
|
|
170
|
+
return absolute(a, root.x, root.y);
|
|
171
|
+
};
|
|
172
|
+
/*
|
|
173
|
+
* Finds value of a in y=a*abs(x-h)+k function
|
|
174
|
+
* @param one 1st point
|
|
175
|
+
* @param two 2nd point
|
|
176
|
+
* */
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
exports.absoluteFromTwoPoints = absoluteFromTwoPoints;
|
|
180
|
+
|
|
181
|
+
var pointsToAForAbsolute = function pointsToAForAbsolute(one, two) {
|
|
182
|
+
var y1 = two.y - one.y;
|
|
183
|
+
var x1 = two.x - one.x;
|
|
184
|
+
var a = y1 / x1;
|
|
185
|
+
|
|
186
|
+
if (two.x < one.x) {
|
|
187
|
+
a = a * -1;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return a;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* y=a*abs(x-h)+k
|
|
194
|
+
*/
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
exports.pointsToAForAbsolute = pointsToAForAbsolute;
|
|
198
|
+
|
|
199
|
+
var absolute = function absolute(a, h, k) {
|
|
200
|
+
return function (x) {
|
|
201
|
+
return a * Math.abs(x - h) + k;
|
|
202
|
+
};
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Exponential from two points on exponential graph.
|
|
206
|
+
* @param root 1st point selected on graph
|
|
207
|
+
* @param edge 2nd point selected on graph
|
|
208
|
+
* https://www.desmos.com/calculator/3fisjexbvp
|
|
209
|
+
*/
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
exports.absolute = absolute;
|
|
213
|
+
|
|
214
|
+
var exponentialFromTwoPoints = function exponentialFromTwoPoints(root, edge) {
|
|
215
|
+
edge = edge || _objectSpread({}, root);
|
|
216
|
+
|
|
217
|
+
var _pointsToABForExponen = pointsToABForExponential(root, edge),
|
|
218
|
+
a = _pointsToABForExponen.a,
|
|
219
|
+
b = _pointsToABForExponen.b;
|
|
220
|
+
|
|
221
|
+
return exponential(a, b);
|
|
222
|
+
};
|
|
223
|
+
/*
|
|
224
|
+
* Finds value of a and b in y=a*(b)^x function
|
|
225
|
+
* @param one 1st point
|
|
226
|
+
* @param two 2nd point
|
|
227
|
+
* */
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
exports.exponentialFromTwoPoints = exponentialFromTwoPoints;
|
|
231
|
+
|
|
232
|
+
var pointsToABForExponential = function pointsToABForExponential(one, two) {
|
|
233
|
+
var p = one.y / two.y;
|
|
234
|
+
var r = 1 / (one.x - two.x);
|
|
235
|
+
var b = Math.pow(p, r);
|
|
236
|
+
var a = one.y / Math.pow(b, one.x);
|
|
237
|
+
return {
|
|
238
|
+
a: a,
|
|
239
|
+
b: b
|
|
240
|
+
};
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* y=a*(b)^x
|
|
244
|
+
*/
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
exports.pointsToABForExponential = pointsToABForExponential;
|
|
248
|
+
|
|
249
|
+
var exponential = function exponential(a, b) {
|
|
250
|
+
return function (x) {
|
|
251
|
+
return a * Math.pow(b, x);
|
|
252
|
+
};
|
|
253
|
+
};
|
|
155
254
|
/**
|
|
156
255
|
* Generate a set of data points, add spacing before min and after max if there is space between minx + min and maxX and max
|
|
157
|
-
* @param {*}
|
|
158
|
-
* @param {*}
|
|
256
|
+
* @param {*} domain
|
|
257
|
+
* @param {*} range
|
|
159
258
|
* @param {*} root
|
|
160
259
|
* @param {*} edge
|
|
161
|
-
* @param {*} interval
|
|
162
260
|
* @param {*} yFn
|
|
261
|
+
* @param {*} excludeOutsidePoints
|
|
163
262
|
*/
|
|
164
263
|
|
|
165
264
|
|
|
166
|
-
exports.
|
|
167
|
-
|
|
168
|
-
var buildDataPoints = function buildDataPoints(
|
|
169
|
-
|
|
265
|
+
exports.exponential = exponential;
|
|
266
|
+
|
|
267
|
+
var buildDataPoints = function buildDataPoints(domain, range, root, edge, yFn) {
|
|
268
|
+
var excludeOutsidePoints = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
269
|
+
log('[buildDataPoints] domain:', domain, 'range:', range, 'root:', root, 'edge:', edge);
|
|
270
|
+
domain = _objectSpread({
|
|
271
|
+
min: 0,
|
|
272
|
+
max: 0,
|
|
273
|
+
step: 1
|
|
274
|
+
}, domain);
|
|
275
|
+
range = _objectSpread({
|
|
276
|
+
min: 0,
|
|
277
|
+
max: 0,
|
|
278
|
+
step: 1
|
|
279
|
+
}, range);
|
|
170
280
|
edge = edge ? edge : _objectSpread({}, root);
|
|
171
281
|
var minX = Math.min(root.x, edge.x);
|
|
172
|
-
var
|
|
173
|
-
|
|
174
|
-
var
|
|
175
|
-
var
|
|
176
|
-
|
|
177
|
-
|
|
282
|
+
var xPts = xPoints(minX, domain.step, domain.min - domain.step, domain.max + domain.step);
|
|
283
|
+
log('[buildDataPoints]:xPts:', xPts);
|
|
284
|
+
var startIndex = -1;
|
|
285
|
+
var endIndex = -1; // generate points based on the yFn
|
|
286
|
+
|
|
287
|
+
var points = xPts.map(function (v) {
|
|
178
288
|
return new _pointGeometry["default"](v, yFn(v));
|
|
179
289
|
});
|
|
290
|
+
|
|
291
|
+
if (!excludeOutsidePoints) {
|
|
292
|
+
return points;
|
|
293
|
+
} // exclude the points with y outside range min and max
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
var filteredPoints = points.reduce(function (acc, val, index) {
|
|
297
|
+
if (val.y >= range.min - range.step && val.y <= range.max + range.step) {
|
|
298
|
+
if (startIndex === -1) {
|
|
299
|
+
startIndex = index;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
if (endIndex < index) {
|
|
303
|
+
endIndex = index;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
return [].concat((0, _toConsumableArray2["default"])(acc), [val]);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return acc;
|
|
310
|
+
}, []); // add the first value outside range min and max smaller than range.min if exists
|
|
311
|
+
|
|
312
|
+
if (startIndex - 1 >= 0) {
|
|
313
|
+
filteredPoints.unshift(points[startIndex - 1]);
|
|
314
|
+
} // add the first value outside range min and max greater than range.min if exists
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
if (endIndex + 1 <= points.length - 1) {
|
|
318
|
+
filteredPoints.push(points[endIndex + 1]);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
return points;
|
|
180
322
|
};
|
|
181
323
|
|
|
182
324
|
exports.buildDataPoints = buildDataPoints;
|
|
325
|
+
var _default = {
|
|
326
|
+
FREQ_DIVIDER: FREQ_DIVIDER,
|
|
327
|
+
getAmplitudeAndFreq: getAmplitudeAndFreq,
|
|
328
|
+
xPoints: xPoints,
|
|
329
|
+
sinY: sinY,
|
|
330
|
+
parabolaFromTwoPoints: parabolaFromTwoPoints,
|
|
331
|
+
parabolaFromThreePoints: parabolaFromThreePoints,
|
|
332
|
+
pointsToABC: pointsToABC,
|
|
333
|
+
parabola: parabola,
|
|
334
|
+
absoluteFromTwoPoints: absoluteFromTwoPoints,
|
|
335
|
+
pointsToAForAbsolute: pointsToAForAbsolute,
|
|
336
|
+
absolute: absolute,
|
|
337
|
+
exponentialFromTwoPoints: exponentialFromTwoPoints,
|
|
338
|
+
pointsToABForExponential: pointsToABForExponential,
|
|
339
|
+
exponential: exponential,
|
|
340
|
+
buildDataPoints: buildDataPoints
|
|
341
|
+
};
|
|
342
|
+
exports["default"] = _default;
|
|
183
343
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.js"],"names":["log","FREQ_DIVIDER","getAmplitudeAndFreq","root","edge","freq","amplitude","x","r","Point","y","e","d","sub","xPoints","min","max","Math","abs","leftpoints","_","rangeRight","rightpoints","range","concat","sinY","shift","phase","vertical","TWO_PI","PI","num","frac","sin","sinFloat","parseFloat","toFixed","parabolaFromTwoPoints","mirrorEdge","parabolaFromThreePoints","one","two","three","pointsToABC","a","b","c","parabola","a1","pow","b1","d1","a2","b2","d2","bMult","a3","d3","buildDataPoints","interval","yFn","minX","maxX","leftSpace","rightSpace","xs","map","v"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;AACA,IAAMA,GAAG,GAAG,uBAAM,8BAAN,CAAZ;AAEO,IAAMC,YAAY,GAAG,EAArB;;;AAEA,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,CAACC,IAAD,EAAOC,IAAP,EAAgB;AACjD,MAAI,CA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I,GAAGA,IAAI,GAAGA,IAAH,qBAAeD,IAAf,CAAX;AACA,MAAM0D,IAAI,GAAG5C,IAAI,CAACF,GAAL,CAASZ,IAAI,CAACI,CAAd,EAAiBH,IAAI,CAACG,CAAtB,CAAb;AACA,MAAMuD,IAAI,GAAG7C,IAAI,CAACD,GAAL,CAASb,IAAI,CAACI,CAAd,EAAiBH,IAAI,CAACG,CAAtB,CAAb;AACA,MAAMwD,SAAS,GAAGhD,GAAG,GAAG8C,IAAxB;AACA,MAAMG,UAAU,GAAGhD,GAAG,GAAG8C,IAAzB;AACA,MAAMG,EAAE,GAAGnD,OAAO,CAAC+C,IAAD,EAAOF,QAAP,EAAiB5C,GAAG,GAAGiD,UAAvB,EAAmChD,GAAG,GAAG+C,SAAzC,CAAlB;AACA/D,EAAAA,GAAG,CAAC,uBAAD,EAA0BiE,EAA1B,CAAH;AACA,SAAOA,EAAE,CAACC,GAAH,CAAO,UAACC,CAAD;AAAA,WAAO,IAAI1D,yBAAJ,CAAU0D,CAAV,EAAaP,GAAG,CAACO,CAAD,CAAhB,CAAP;AAAA,GAAP,CAAP;AACD,CAVM","sourcesContent":["import debug from 'debug';\nimport Point from '@mapbox/point-geometry';\nimport _ from 'lodash';\nconst log = debug('pie-lib:graphing:tools:utils');\n\nexport const FREQ_DIVIDER = 16;\n\nexport const getAmplitudeAndFreq = (root, edge) => {\n if (!edge) {\n return { freq: 0, amplitude: 0 };\n }\n\n if (root.x == edge.x) {\n return { freq: 0, amplitude: 0 };\n }\n\n const r = new Point(root.x, root.y);\n const e = new Point(edge.x, edge.y);\n const d = e.sub(r);\n // edge point describes 1/4 of the freq\n return { freq: d.x * 4, amplitude: d.y };\n};\n\n/**\n * build the x points with root as the anchor.\n */\nexport const xPoints = (root, freq, min, max) => {\n freq = Math.abs(freq);\n log('[xPoints] root:', root, 'freq:', freq, ' min:', min, ' max:', max);\n const leftpoints = _.rangeRight(root, min - freq, freq * -1);\n const rightpoints = _.range(root + freq, max + freq, freq);\n\n return _.concat(leftpoints, rightpoints);\n};\n\n/**\n * Calculate y for x value using amp, freq and shift\n * https://www.desmos.com/calculator/f1psfoiiv6\n */\nexport const sinY = (amplitude, freq, shift) => (x) => {\n shift = { phase: 0, vertical: 0, ...shift };\n const TWO_PI = Math.PI * 2;\n const num = TWO_PI * (x - shift.phase);\n const frac = num / freq;\n const sin = Math.sin(frac);\n const sinFloat = parseFloat(sin).toFixed(10);\n return amplitude * sinFloat + shift.vertical;\n};\n\n/**\n * You need three points for the quadratic eq, so we mirror the edge point\n * https://www.desmos.com/calculator/xhz1xqgpca\n */\nexport const parabolaFromTwoPoints = (root, edge) => {\n edge = edge || { ...root };\n const mirrorEdge = { x: root.x - (edge.x - root.x), y: edge.y };\n return parabolaFromThreePoints(root, edge, mirrorEdge);\n};\n\nexport const parabolaFromThreePoints = (one, two, three) => {\n log(one, two, three);\n const { a, b, c } = pointsToABC(one, two, three);\n log(a, b, c);\n return parabola(a, b, c);\n};\n/** derive a,b,c from the 3 points */\nexport const pointsToABC = (one, two, three) => {\n const a1 = Math.pow(one.x, 2) * -1 + Math.pow(two.x, 2);\n const b1 = one.x * -1 + two.x;\n const d1 = one.y * -1 + two.y;\n const a2 = Math.pow(two.x, 2) * -1 + Math.pow(three.x, 2);\n const b2 = two.x * -1 + three.x;\n const d2 = two.y * -1 + three.y;\n const bMult = (b2 / b1) * -1;\n const a3 = bMult * a1 + a2;\n const d3 = bMult * d1 + d2;\n const a = d3 / a3;\n const b = (d1 - a1 * a) / b1;\n const c = one.y - a * Math.pow(one.x, 2) - b * one.x;\n return { a, b, c };\n};\n\n/**\n * y=ax^2+bx+c\n */\nexport const parabola = (a, b, c) => (x) => a * Math.pow(x, 2) + b * x + c;\n\n/**\n * Generate a set of data points, add spacing before min and after max if there is space between minx + min and maxX and max\n * @param {*} min\n * @param {*} max\n * @param {*} root\n * @param {*} edge\n * @param {*} interval\n * @param {*} yFn\n */\nexport const buildDataPoints = (min, max, root, edge, interval, yFn) => {\n log('[buildDataPoints] min:', min, 'max:', max, 'root:', root);\n edge = edge ? edge : { ...root };\n const minX = Math.min(root.x, edge.x);\n const maxX = Math.max(root.x, edge.x);\n const leftSpace = min - minX;\n const rightSpace = max - maxX;\n const xs = xPoints(minX, interval, min - rightSpace, max - leftSpace);\n log('[buildDataPoints]:xs:', xs);\n return xs.map((v) => new Point(v, yFn(v)));\n};\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../src/index.js"],"names":["log","FREQ_DIVIDER","getAmplitudeAndFreq","root","edge","freq","amplitude","x","r","Point","y","e","d","sub","xPoints","min","max","Math","abs","leftpoints","_","rangeRight","rightpoints","range","concat","sinY","shift","phase","vertical","TWO_PI","PI","num","frac","sin","sinFloat","parseFloat","toFixed","parabolaFromTwoPoints","mirrorEdge","parabolaFromThreePoints","one","two","three","pointsToABC","a","b","c","parabola","a1","pow","b1","d1","a2","b2","d2","bMult","a3","d3","absoluteFromTwoPoints","pointsToAForAbsolute","absolute","y1","x1","h","k","exponentialFromTwoPoints","pointsToABForExponential","exponential","p","buildDataPoints","domain","yFn","excludeOutsidePoints","step","minX","xPts","startIndex","endIndex","points","map","v","filteredPoints","reduce","acc","val","index","unshift","length","push"],"mappings":";;;;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;AACA,IAAMA,GAAG,GAAG,uBAAM,8BAAN,CAAZ;AAEO,IAAMC,YAAY,GAAG,EAArB;;;AAEA,IAAMC,mBAAmB,GAAG,SAAtBA,mBAAsB,CAACC,IAAD,EAAOC,IAAP,EAAgB;AACjD,MAAI,CAACA,IAAL,EAAW;AACT,WAAO;AAAEC,MAAAA,IAAI,EAAE,CAAR;AAAWC,MAAAA,SAAS,EAAE;AAAtB,KAAP;AACD;;AAED,MAAIH,IAAI,CAACI,CAAL,IAAUH,IAAI,CAACG,CAAnB,EAAsB;AACpB,WAAO;AAAEF,MAAAA,IAAI,EAAE,CAAR;AAAWC,MAAAA,SAAS,EAAE;AAAtB,KAAP;AACD;;AAED,MAAME,C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A7B;AACD,GA1C8F,CA4C/F;;;AACA,MAAIC,QAAQ,GAAG,CAAX,IAAgBC,MAAM,CAACS,MAAP,GAAgB,CAApC,EAAuC;AACrCN,IAAAA,cAAc,CAACO,IAAf,CAAoBV,MAAM,CAACD,QAAQ,GAAG,CAAZ,CAA1B;AACD;;AAED,SAAOC,MAAP;AACD,CAlDM;;;eAoDQ;AACb7E,EAAAA,YAAY,EAAZA,YADa;AAEbC,EAAAA,mBAAmB,EAAnBA,mBAFa;AAGbY,EAAAA,OAAO,EAAPA,OAHa;AAIbW,EAAAA,IAAI,EAAJA,IAJa;AAKbY,EAAAA,qBAAqB,EAArBA,qBALa;AAMbE,EAAAA,uBAAuB,EAAvBA,uBANa;AAObI,EAAAA,WAAW,EAAXA,WAPa;AAQbI,EAAAA,QAAQ,EAARA,QARa;AASbW,EAAAA,qBAAqB,EAArBA,qBATa;AAUbC,EAAAA,oBAAoB,EAApBA,oBAVa;AAWbC,EAAAA,QAAQ,EAARA,QAXa;AAYbK,EAAAA,wBAAwB,EAAxBA,wBAZa;AAabC,EAAAA,wBAAwB,EAAxBA,wBAba;AAcbC,EAAAA,WAAW,EAAXA,WAda;AAebE,EAAAA,eAAe,EAAfA;AAfa,C","sourcesContent":["import debug from 'debug';\nimport Point from '@mapbox/point-geometry';\nimport _ from 'lodash';\nconst log = debug('pie-lib:graphing:tools:utils');\n\nexport const FREQ_DIVIDER = 16;\n\nexport const getAmplitudeAndFreq = (root, edge) => {\n if (!edge) {\n return { freq: 0, amplitude: 0 };\n }\n\n if (root.x == edge.x) {\n return { freq: 0, amplitude: 0 };\n }\n\n const r = new Point(root.x, root.y);\n const e = new Point(edge.x, edge.y);\n const d = e.sub(r);\n // edge point describes 1/4 of the freq\n return { freq: d.x * 4, amplitude: d.y };\n};\n\n/**\n * build the x points with root as the anchor.\n */\nexport const xPoints = (root, freq, min, max) => {\n freq = Math.abs(freq);\n log('[xPoints] root:', root, 'freq:', freq, ' min:', min, ' max:', max);\n const leftpoints = _.rangeRight(root, min - freq, freq * -1);\n const rightpoints = _.range(root + freq, max + freq, freq);\n\n return _.concat(leftpoints, rightpoints);\n};\n\n/**\n * Calculate y for x value using amp, freq and shift\n * https://www.desmos.com/calculator/f1psfoiiv6\n */\nexport const sinY = (amplitude, freq, shift) => (x) => {\n shift = { phase: 0, vertical: 0, ...shift };\n const TWO_PI = Math.PI * 2;\n const num = TWO_PI * (x - shift.phase);\n const frac = num / freq;\n const sin = Math.sin(frac);\n const sinFloat = parseFloat(sin).toFixed(10);\n return amplitude * sinFloat + shift.vertical;\n};\n\n/**\n * You need three points for the quadratic eq, so we mirror the edge point\n * https://www.desmos.com/calculator/xhz1xqgpca\n */\nexport const parabolaFromTwoPoints = (root, edge) => {\n edge = edge || { ...root };\n const mirrorEdge = { x: root.x - (edge.x - root.x), y: edge.y };\n return parabolaFromThreePoints(root, edge, mirrorEdge);\n};\n\nexport const parabolaFromThreePoints = (one, two, three) => {\n log(one, two, three);\n const { a, b, c } = pointsToABC(one, two, three);\n log(a, b, c);\n return parabola(a, b, c);\n};\n/** derive a,b,c from the 3 points */\nexport const pointsToABC = (one, two, three) => {\n const a1 = Math.pow(one.x, 2) * -1 + Math.pow(two.x, 2);\n const b1 = one.x * -1 + two.x;\n const d1 = one.y * -1 + two.y;\n const a2 = Math.pow(two.x, 2) * -1 + Math.pow(three.x, 2);\n const b2 = two.x * -1 + three.x;\n const d2 = two.y * -1 + three.y;\n const bMult = (b2 / b1) * -1;\n const a3 = bMult * a1 + a2;\n const d3 = bMult * d1 + d2;\n const a = d3 / a3;\n const b = (d1 - a1 * a) / b1;\n const c = one.y - a * Math.pow(one.x, 2) - b * one.x;\n return { a, b, c };\n};\n\n/**\n * y=ax^2+bx+c\n */\nexport const parabola = (a, b, c) => (x) => a * Math.pow(x, 2) + b * x + c;\n\n/**\n * Absolute value from two points Root (Vertex) the point where the two rays intersect and edge One point on a ray.\n * @param root 1st point selected on graph\n * @param edge 2nd point selected on graph\n * https://www.desmos.com/calculator/rarxiatpip\n */\nexport const absoluteFromTwoPoints = (root, edge) => {\n edge = edge || { ...root };\n const a = pointsToAForAbsolute(root, edge);\n return absolute(a, root.x, root.y);\n};\n\n/*\n * Finds value of a in y=a*abs(x-h)+k function\n * @param one 1st point\n * @param two 2nd point\n * */\nexport const pointsToAForAbsolute = (one, two) => {\n const y1 = two.y - one.y;\n const x1 = two.x - one.x;\n let a = y1 / x1;\n if (two.x < one.x) {\n a = a * -1;\n }\n return a;\n};\n\n/**\n * y=a*abs(x-h)+k\n */\nexport const absolute = (a, h, k) => (x) => a * Math.abs(x - h) + k;\n\n/**\n * Exponential from two points on exponential graph.\n * @param root 1st point selected on graph\n * @param edge 2nd point selected on graph\n * https://www.desmos.com/calculator/3fisjexbvp\n */\nexport const exponentialFromTwoPoints = (root, edge) => {\n edge = edge || { ...root };\n const { a, b } = pointsToABForExponential(root, edge);\n return exponential(a, b);\n};\n\n/*\n * Finds value of a and b in y=a*(b)^x function\n * @param one 1st point\n * @param two 2nd point\n * */\nexport const pointsToABForExponential = (one, two) => {\n const p = one.y / two.y;\n const r = 1 / (one.x - two.x);\n const b = Math.pow(p, r);\n const a = one.y / Math.pow(b, one.x);\n return { a, b };\n};\n\n/**\n * y=a*(b)^x\n */\nexport const exponential = (a, b) => (x) => a * Math.pow(b, x);\n\n/**\n * Generate a set of data points, add spacing before min and after max if there is space between minx + min and maxX and max\n * @param {*} domain\n * @param {*} range\n * @param {*} root\n * @param {*} edge\n * @param {*} yFn\n * @param {*} excludeOutsidePoints\n */\nexport const buildDataPoints = (domain, range, root, edge, yFn, excludeOutsidePoints = false) => {\n log('[buildDataPoints] domain:', domain, 'range:', range, 'root:', root, 'edge:', edge);\n\n domain = { min: 0, max: 0, step: 1, ...domain };\n range = { min: 0, max: 0, step: 1, ...range };\n edge = edge ? edge : { ...root };\n\n const minX = Math.min(root.x, edge.x);\n const xPts = xPoints(minX, domain.step, domain.min - domain.step, domain.max + domain.step);\n\n log('[buildDataPoints]:xPts:', xPts);\n\n let startIndex = -1;\n let endIndex = -1;\n\n // generate points based on the yFn\n const points = xPts.map((v) => new Point(v, yFn(v)));\n\n if (!excludeOutsidePoints) {\n return points;\n }\n\n // exclude the points with y outside range min and max\n const filteredPoints = points.reduce((acc, val, index) => {\n if (val.y >= range.min - range.step && val.y <= range.max + range.step) {\n if (startIndex === -1) {\n startIndex = index;\n }\n\n if (endIndex < index) {\n endIndex = index;\n }\n\n return [...acc, val];\n }\n\n return acc;\n }, []);\n\n // add the first value outside range min and max smaller than range.min if exists\n if (startIndex - 1 >= 0) {\n filteredPoints.unshift(points[startIndex - 1]);\n }\n\n // add the first value outside range min and max greater than range.min if exists\n if (endIndex + 1 <= points.length - 1) {\n filteredPoints.push(points[endIndex + 1]);\n }\n\n return points;\n};\n\nexport default {\n FREQ_DIVIDER,\n getAmplitudeAndFreq,\n xPoints,\n sinY,\n parabolaFromTwoPoints,\n parabolaFromThreePoints,\n pointsToABC,\n parabola,\n absoluteFromTwoPoints,\n pointsToAForAbsolute,\n absolute,\n exponentialFromTwoPoints,\n pointsToABForExponential,\n exponential,\n buildDataPoints,\n};\n"],"file":"index.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/graphing-utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.34-next.1848+4ac095ca",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -14,6 +14,6 @@
|
|
|
14
14
|
"debug": "^4.1.1",
|
|
15
15
|
"lodash": "^4.17.11"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "4ac095ca931e5fe8f131f28f41dd61093bd55d98",
|
|
18
18
|
"scripts": {}
|
|
19
19
|
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { xPoints, sinY, buildDataPoints, pointsToABC, parabola, parabolaFromTwoPoints } from '../index';
|
|
2
|
+
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
|
|
5
|
+
const xy = (x, y) => ({ x, y });
|
|
6
|
+
|
|
7
|
+
describe('utils', () => {
|
|
8
|
+
describe('xPoints', () => {
|
|
9
|
+
const assertXPoints = (root, freq, min, max, expected) => {
|
|
10
|
+
it(`root: ${root}, freq: ${freq}, domain: ${min}<->${max} => ${expected}`, () => {
|
|
11
|
+
const result = xPoints(root, freq, min, max);
|
|
12
|
+
expect(result).toEqual(expected);
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
assertXPoints(0, 2, -5, 5, [-6, -4, -2, 0, 2, 4, 6]);
|
|
16
|
+
assertXPoints(2, 2, -5, 5, [-6, -4, -2, 0, 2, 4, 6]);
|
|
17
|
+
assertXPoints(3, 2, -5, 5, [-5, -3, -1, 1, 3, 5]);
|
|
18
|
+
assertXPoints(3, 2, 0, 10, [-1, 1, 3, 5, 7, 9, 11]);
|
|
19
|
+
assertXPoints(-2, 2, -10, -1, [-10, -8, -6, -4, -2, 0]);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('sinY', () => {
|
|
23
|
+
const assertSin = (amp, freq, shift) => (input, expected) => {
|
|
24
|
+
const p = shift ? shift.phase : 0;
|
|
25
|
+
const v = shift ? shift.vertical : 0;
|
|
26
|
+
it(` sin of ${input} (>${p} ^${v}) = ${expected}`, () => {
|
|
27
|
+
const fn = sinY(amp, freq, shift);
|
|
28
|
+
const result = Array.isArray(input) ? input.map((x) => fn(x)) : fn(input);
|
|
29
|
+
expect(result).toEqual(expected);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
const shift = (phase, vertical) => ({ phase, vertical });
|
|
33
|
+
const rng = (start, end, step) => _.range(start, end + step, step);
|
|
34
|
+
|
|
35
|
+
describe('amp: 1, freq: 1', () => {
|
|
36
|
+
assertSin(1, 1, shift(0, 0))(0, 0);
|
|
37
|
+
assertSin(1, 1, shift(0, 0))(0.25, 1);
|
|
38
|
+
assertSin(1, 1, shift(0, 0))(0.5, 0);
|
|
39
|
+
assertSin(1, 1, shift(0, 0))(0.75, -1);
|
|
40
|
+
assertSin(1, 1, shift(0, 0))(rng(0, 1, 0.25), [0, 1, 0, -1, 0]);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
describe('amp: 1, freq: 4', () => {
|
|
44
|
+
assertSin(1, 4, shift(0, 0))(rng(-4, 4, 1), [0, 1, 0, -1, 0, 1, 0, -1, 0]);
|
|
45
|
+
assertSin(1, 4, shift(0, 0))(rng(-1, 1, 1), [-1, 0, 1]);
|
|
46
|
+
assertSin(1, 4, shift(1, 0))(rng(-1, 1, 1), [0, -1, 0]);
|
|
47
|
+
assertSin(1, 4, shift(-1, 0))(rng(-1, 1, 1), [0, 1, 0]);
|
|
48
|
+
assertSin(1, 4, shift(0, 1))(rng(-1, 1, 1), [0, 1, 2]);
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
describe('buildDataPoints', () => {
|
|
53
|
+
it('generates points', () => {
|
|
54
|
+
const result = buildDataPoints(
|
|
55
|
+
{ min: -1, max: 1, step: 1 },
|
|
56
|
+
{ min: -1, max: 1, step: 1 },
|
|
57
|
+
{ x: 0, y: 0 },
|
|
58
|
+
{ x: 0, y: 0 },
|
|
59
|
+
(x) => x,
|
|
60
|
+
);
|
|
61
|
+
expect(result.map((p) => p.x)).toEqual([-2, -1, 0, 1, 2]);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const assertParabola = (
|
|
65
|
+
domain,
|
|
66
|
+
range,
|
|
67
|
+
root,
|
|
68
|
+
edge,
|
|
69
|
+
mirror,
|
|
70
|
+
existingPoint1,
|
|
71
|
+
existingPoint2,
|
|
72
|
+
nonExistingPointOutsideRange,
|
|
73
|
+
) => {
|
|
74
|
+
it('generates points for parabola', () => {
|
|
75
|
+
const result = buildDataPoints(domain, range, root, edge, parabolaFromTwoPoints(root, edge));
|
|
76
|
+
|
|
77
|
+
expect(result).toContainEqual(root);
|
|
78
|
+
expect(result).toContainEqual(edge);
|
|
79
|
+
expect(result).toContainEqual(mirror);
|
|
80
|
+
expect(result).toContainEqual(existingPoint1);
|
|
81
|
+
expect(result).toContainEqual(existingPoint2);
|
|
82
|
+
expect(result).not.toContainEqual(nonExistingPointOutsideRange);
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// a * x^2 + b * x + c
|
|
87
|
+
|
|
88
|
+
// a = 8, b = 4, c = 2
|
|
89
|
+
assertParabola(
|
|
90
|
+
{ min: -1, max: 1, step: 0.25 },
|
|
91
|
+
{ min: -1, max: -1, step: 1 },
|
|
92
|
+
{ x: -0.25, y: 1.5 },
|
|
93
|
+
{ x: 0.25, y: 3.5 },
|
|
94
|
+
{ x: -0.75, y: 3.5 },
|
|
95
|
+
{ x: -1, y: 6 },
|
|
96
|
+
{ x: 1, y: 14 },
|
|
97
|
+
{ x: 1.25, y: -19.5 },
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// a = -8, b = -4, c = -2
|
|
101
|
+
assertParabola(
|
|
102
|
+
{ min: -1, max: 1, step: 0.25 },
|
|
103
|
+
{ min: -1, max: -1, step: 1 },
|
|
104
|
+
{ x: -0.25, y: -1.5 },
|
|
105
|
+
{ x: 0.25, y: -3.5 },
|
|
106
|
+
{ x: -0.75, y: -3.5 },
|
|
107
|
+
{ x: -1, y: -6 },
|
|
108
|
+
{ x: 1, y: -14 },
|
|
109
|
+
{ x: 1.25, y: 19.5 },
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
// a = 10, b = 0, c = -2
|
|
113
|
+
assertParabola(
|
|
114
|
+
{ min: -1, max: 1, step: 0.25 },
|
|
115
|
+
{ min: -1, max: -1, step: 1 },
|
|
116
|
+
{ x: 0, y: -2 },
|
|
117
|
+
{ x: 0.5, y: 0.5 },
|
|
118
|
+
{ x: -0.5, y: 0.5 },
|
|
119
|
+
{ x: -1, y: 8 },
|
|
120
|
+
{ x: 1, y: 8 },
|
|
121
|
+
{ x: 3, y: 88 },
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
// a = 10, b = -10, c = 0
|
|
125
|
+
assertParabola(
|
|
126
|
+
{ min: -1, max: 1, step: 0.25 },
|
|
127
|
+
{ min: -1, max: -1, step: 1 },
|
|
128
|
+
{ x: 0.5, y: -2.5 },
|
|
129
|
+
{ x: 0, y: 0 },
|
|
130
|
+
{ x: 1, y: 0 },
|
|
131
|
+
{ x: -1, y: 20 },
|
|
132
|
+
{ x: 1.25, y: 3.125 },
|
|
133
|
+
{ x: 3, y: 60 },
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
// a = 10, b = -10, c = 0
|
|
137
|
+
assertParabola(
|
|
138
|
+
{ min: -1, max: 1, step: 0.5 },
|
|
139
|
+
{ min: -1, max: -1, step: 1 },
|
|
140
|
+
{ x: 0.5, y: -2.5 },
|
|
141
|
+
{ x: 0, y: 0 },
|
|
142
|
+
{ x: 1, y: 0 },
|
|
143
|
+
{ x: -1, y: 20 },
|
|
144
|
+
{ x: 1.5, y: 7.5 },
|
|
145
|
+
{ x: 3, y: 60 },
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
// a = -4, b = 4, c = 0
|
|
149
|
+
assertParabola(
|
|
150
|
+
{ min: -1, max: 5, step: 0.25 },
|
|
151
|
+
{ min: -1, max: -1, step: 1 },
|
|
152
|
+
{ x: 0.5, y: 1 },
|
|
153
|
+
{ x: 0, y: 0 },
|
|
154
|
+
{ x: 1, y: 0 },
|
|
155
|
+
{ x: -0.5, y: -3 },
|
|
156
|
+
{ x: 1.5, y: -3 },
|
|
157
|
+
{ x: 3, y: 60 },
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
describe('pointsToABC', () => {
|
|
162
|
+
const assertPointsToABC = (one, two, three, a, b, c) => {
|
|
163
|
+
it(`${one}, ${two}, ${three} => ${a}, ${b}, ${c}`, () => {
|
|
164
|
+
const result = pointsToABC(one, two, three);
|
|
165
|
+
expect(result.a).toBeCloseTo(a);
|
|
166
|
+
expect(result.b).toBeCloseTo(b);
|
|
167
|
+
expect(result.c).toBeCloseTo(c);
|
|
168
|
+
});
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
assertPointsToABC(xy(0, 0), xy(1, 1), xy(-1, 1), 1, 0, 0);
|
|
172
|
+
assertPointsToABC(xy(0, 0), xy(2, 1), xy(-2, 1), 0.25, 0, 0);
|
|
173
|
+
assertPointsToABC(xy(1, 0), xy(2, 1), xy(0, 1), 1, -2, 1);
|
|
174
|
+
assertPointsToABC(xy(1, 0), xy(4, 1), xy(-2, 1), 0.11111, -0.22222, 0.11111);
|
|
175
|
+
assertPointsToABC(xy(0, 0), xy(1, 2), xy(-1, 2), 2, 0, 0);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe('parabolaFromTwoPoints', () => {
|
|
179
|
+
describe('0,0 -> 1,2', () => {
|
|
180
|
+
const yVal = parabolaFromTwoPoints(xy(0, 0), xy(1, 1));
|
|
181
|
+
it('for x = 0, returns 0', () => expect(yVal(0)).toEqual(0));
|
|
182
|
+
it('for x = 1, returns 1', () => expect(yVal(1)).toEqual(1));
|
|
183
|
+
});
|
|
184
|
+
describe('0,0 -> 1,2', () => {
|
|
185
|
+
const yVal = parabolaFromTwoPoints(xy(0, 0), xy(1, 2));
|
|
186
|
+
it('for x = 0, returns 0', () => expect(yVal(0)).toEqual(0));
|
|
187
|
+
it('for x = 1, returns 2', () => expect(yVal(1)).toEqual(2));
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
describe('parabola', () => {
|
|
192
|
+
it('works', () => {
|
|
193
|
+
const fn = parabola(0.22222, -0.444444, 0.22222);
|
|
194
|
+
expect(fn(0)).toBeCloseTo(0.222222);
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
});
|
package/src/index.js
CHANGED
|
@@ -85,23 +85,143 @@ export const pointsToABC = (one, two, three) => {
|
|
|
85
85
|
*/
|
|
86
86
|
export const parabola = (a, b, c) => (x) => a * Math.pow(x, 2) + b * x + c;
|
|
87
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Absolute value from two points Root (Vertex) the point where the two rays intersect and edge One point on a ray.
|
|
90
|
+
* @param root 1st point selected on graph
|
|
91
|
+
* @param edge 2nd point selected on graph
|
|
92
|
+
* https://www.desmos.com/calculator/rarxiatpip
|
|
93
|
+
*/
|
|
94
|
+
export const absoluteFromTwoPoints = (root, edge) => {
|
|
95
|
+
edge = edge || { ...root };
|
|
96
|
+
const a = pointsToAForAbsolute(root, edge);
|
|
97
|
+
return absolute(a, root.x, root.y);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/*
|
|
101
|
+
* Finds value of a in y=a*abs(x-h)+k function
|
|
102
|
+
* @param one 1st point
|
|
103
|
+
* @param two 2nd point
|
|
104
|
+
* */
|
|
105
|
+
export const pointsToAForAbsolute = (one, two) => {
|
|
106
|
+
const y1 = two.y - one.y;
|
|
107
|
+
const x1 = two.x - one.x;
|
|
108
|
+
let a = y1 / x1;
|
|
109
|
+
if (two.x < one.x) {
|
|
110
|
+
a = a * -1;
|
|
111
|
+
}
|
|
112
|
+
return a;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* y=a*abs(x-h)+k
|
|
117
|
+
*/
|
|
118
|
+
export const absolute = (a, h, k) => (x) => a * Math.abs(x - h) + k;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Exponential from two points on exponential graph.
|
|
122
|
+
* @param root 1st point selected on graph
|
|
123
|
+
* @param edge 2nd point selected on graph
|
|
124
|
+
* https://www.desmos.com/calculator/3fisjexbvp
|
|
125
|
+
*/
|
|
126
|
+
export const exponentialFromTwoPoints = (root, edge) => {
|
|
127
|
+
edge = edge || { ...root };
|
|
128
|
+
const { a, b } = pointsToABForExponential(root, edge);
|
|
129
|
+
return exponential(a, b);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/*
|
|
133
|
+
* Finds value of a and b in y=a*(b)^x function
|
|
134
|
+
* @param one 1st point
|
|
135
|
+
* @param two 2nd point
|
|
136
|
+
* */
|
|
137
|
+
export const pointsToABForExponential = (one, two) => {
|
|
138
|
+
const p = one.y / two.y;
|
|
139
|
+
const r = 1 / (one.x - two.x);
|
|
140
|
+
const b = Math.pow(p, r);
|
|
141
|
+
const a = one.y / Math.pow(b, one.x);
|
|
142
|
+
return { a, b };
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* y=a*(b)^x
|
|
147
|
+
*/
|
|
148
|
+
export const exponential = (a, b) => (x) => a * Math.pow(b, x);
|
|
149
|
+
|
|
88
150
|
/**
|
|
89
151
|
* Generate a set of data points, add spacing before min and after max if there is space between minx + min and maxX and max
|
|
90
|
-
* @param {*}
|
|
91
|
-
* @param {*}
|
|
152
|
+
* @param {*} domain
|
|
153
|
+
* @param {*} range
|
|
92
154
|
* @param {*} root
|
|
93
155
|
* @param {*} edge
|
|
94
|
-
* @param {*} interval
|
|
95
156
|
* @param {*} yFn
|
|
157
|
+
* @param {*} excludeOutsidePoints
|
|
96
158
|
*/
|
|
97
|
-
export const buildDataPoints = (
|
|
98
|
-
log('[buildDataPoints]
|
|
159
|
+
export const buildDataPoints = (domain, range, root, edge, yFn, excludeOutsidePoints = false) => {
|
|
160
|
+
log('[buildDataPoints] domain:', domain, 'range:', range, 'root:', root, 'edge:', edge);
|
|
161
|
+
|
|
162
|
+
domain = { min: 0, max: 0, step: 1, ...domain };
|
|
163
|
+
range = { min: 0, max: 0, step: 1, ...range };
|
|
99
164
|
edge = edge ? edge : { ...root };
|
|
165
|
+
|
|
100
166
|
const minX = Math.min(root.x, edge.x);
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
167
|
+
const xPts = xPoints(minX, domain.step, domain.min - domain.step, domain.max + domain.step);
|
|
168
|
+
|
|
169
|
+
log('[buildDataPoints]:xPts:', xPts);
|
|
170
|
+
|
|
171
|
+
let startIndex = -1;
|
|
172
|
+
let endIndex = -1;
|
|
173
|
+
|
|
174
|
+
// generate points based on the yFn
|
|
175
|
+
const points = xPts.map((v) => new Point(v, yFn(v)));
|
|
176
|
+
|
|
177
|
+
if (!excludeOutsidePoints) {
|
|
178
|
+
return points;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// exclude the points with y outside range min and max
|
|
182
|
+
const filteredPoints = points.reduce((acc, val, index) => {
|
|
183
|
+
if (val.y >= range.min - range.step && val.y <= range.max + range.step) {
|
|
184
|
+
if (startIndex === -1) {
|
|
185
|
+
startIndex = index;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (endIndex < index) {
|
|
189
|
+
endIndex = index;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return [...acc, val];
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return acc;
|
|
196
|
+
}, []);
|
|
197
|
+
|
|
198
|
+
// add the first value outside range min and max smaller than range.min if exists
|
|
199
|
+
if (startIndex - 1 >= 0) {
|
|
200
|
+
filteredPoints.unshift(points[startIndex - 1]);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// add the first value outside range min and max greater than range.min if exists
|
|
204
|
+
if (endIndex + 1 <= points.length - 1) {
|
|
205
|
+
filteredPoints.push(points[endIndex + 1]);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return points;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
export default {
|
|
212
|
+
FREQ_DIVIDER,
|
|
213
|
+
getAmplitudeAndFreq,
|
|
214
|
+
xPoints,
|
|
215
|
+
sinY,
|
|
216
|
+
parabolaFromTwoPoints,
|
|
217
|
+
parabolaFromThreePoints,
|
|
218
|
+
pointsToABC,
|
|
219
|
+
parabola,
|
|
220
|
+
absoluteFromTwoPoints,
|
|
221
|
+
pointsToAForAbsolute,
|
|
222
|
+
absolute,
|
|
223
|
+
exponentialFromTwoPoints,
|
|
224
|
+
pointsToABForExponential,
|
|
225
|
+
exponential,
|
|
226
|
+
buildDataPoints,
|
|
107
227
|
};
|
package/README.md
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
# graphing-utils
|
|
2
|
-
|
|
3
|
-
`graphing-utils` is a small collection of tools and helper functions that facilitate testing for components of the PIE framework.
|
|
4
|
-
|
|
5
|
-
## Usage
|
|
6
|
-
|
|
7
|
-
### Install
|
|
8
|
-
|
|
9
|
-
npm install --save @pie-lib/graphing-utils
|
|
10
|
-
|
|
11
|
-
### Import
|
|
12
|
-
|
|
13
|
-
import utils from '@pie-lib/graphing-utils';
|