Skip to content

Commit 131f369

Browse files
authored
Merge pull request #335 from Dessia-tech/dev
v0.21.0
2 parents 144e4cc + 280ec02 commit 131f369

File tree

79 files changed

+3409
-624
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+3409
-624
lines changed

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ node_modules/
22
lib/
33
libdev/
44

5-
65
# CAD files
76
*.fcstd
87
*.fcstd1
@@ -60,6 +59,12 @@ coverage.xml
6059
*.cover
6160
.hypothesis/
6261
.pytest_cache/
62+
instrumented/
63+
coverage/
64+
libtest/
65+
.nycrc
66+
.nyc_output
67+
.vscode
6368

6469
# Translations
6570
*.mo

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
“files”: [“lib/**/*”]
22
/cypress
33
/build
4+
/instrumented
45
/doc
56
/lib/cypress
67
/libdev
8+
/libtest
79
/plot_data
810
/plot_data.egg-info
911
/script

.nycrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@istanbuljs/nyc-config-typescript"
3+
}

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.21.0]
9+
### Add
10+
- Tests of typescript app
11+
812
## [0.20.0]
913
### Add
14+
- Tests for most of important features
1015
- Toggle Axes
1116
- Customable axes names of Draw
1217

cypress.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defineConfig } from "cypress";
22
import getCompareSnapshotsPlugin from "cypress-visual-regression/dist/plugin";
33
import fs from 'fs'
44
import path from 'path'
5+
import registerCodeCoverageTasks from '@cypress/code-coverage/task'
56

67
const HEIGHT: number = 710;
78
const WIDTH: number = 1270;
@@ -26,8 +27,11 @@ export default defineConfig({
2627
type: 'actual' //'base',
2728
},
2829
e2e: {
30+
specPattern: 'cypress/e2e/*',
2931
experimentalStudio : true,
3032
setupNodeEvents(on, config) {
33+
registerCodeCoverageTasks(on, config);
34+
3135
getCompareSnapshotsPlugin(on, config);
3236

3337
on('before:browser:launch', (browser, launchOptions) => {
@@ -59,6 +63,8 @@ export default defineConfig({
5963
})
6064
})
6165
});
66+
67+
return config
6268
},
6369
}
6470
});

cypress/e2e/axes.cy.ts

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
import { Vertex } from "../../instrumented/baseShape";
2+
import { Rect } from "../../instrumented/primitives";
3+
import { Axis, ParallelAxis } from "../../instrumented/axes";
4+
5+
const vector = [1, 2, 3, 4, 5];
6+
const boundingBox = new Rect(new Vertex(0, 0), new Vertex(500, 500));
7+
const origin = new Vertex(0, 0);
8+
const end = new Vertex(0, 100);
9+
const name = "";
10+
const initScale = new Vertex(1, 1);
11+
const nTicks = 5;
12+
13+
describe('Axis', function() {
14+
it('should draw the axis on the canvas', function() {
15+
const canvas = document.createElement('canvas');
16+
const context = canvas.getContext('2d');
17+
const axis = new Axis(vector, boundingBox, origin, end, name, initScale, nTicks);
18+
19+
cy.spy(context, 'fill');
20+
cy.spy(context, 'stroke');
21+
22+
axis.draw(context);
23+
24+
cy.wrap(context.fill).should('have.been.calledWith', axis.drawPath);
25+
cy.wrap(context.stroke).should('have.been.calledWith', axis.drawPath);
26+
});
27+
28+
it('should be well created without vector features', function() {
29+
const axis = new Axis(null, boundingBox, origin, end, name, initScale, nTicks);
30+
const ticks = [-1, 0, 1, 2]
31+
expect(axis.ticks).to.deep.equal(ticks);
32+
expect(axis.isDiscrete, `isDiscrete`).to.be.true;
33+
});
34+
35+
it('should be well created with empty vector features', function() {
36+
const axis = new Axis([], boundingBox, origin, end, name, initScale, nTicks);
37+
const ticks = [-1, 0, 1, 2]
38+
axis.ticks.forEach((tick, index) => expect(tick, `tick ${index}`).to.equal(ticks[index]));
39+
expect(axis.isDiscrete, `isDiscrete`).to.be.true;
40+
});
41+
42+
it('should be well created without only one feature', function() {
43+
const axis = new Axis([1], boundingBox, origin, end, name, initScale, nTicks);
44+
expect(axis.ticks.length, `length ticks`).to.equal(7);
45+
});
46+
47+
it("should scale axis with another one", function() {
48+
const axis = new Axis(vector, boundingBox, origin, end, name, initScale, nTicks);
49+
const otherVector = [10, 11, 12, 13, 14, 32.4];
50+
const otherAxis = new Axis(otherVector, boundingBox, origin, end, name, initScale, nTicks);
51+
axis.otherAxisScaling(otherAxis);
52+
expect(axis.minValue, "minValue").to.be.closeTo(-9.3, 0.1);
53+
expect(axis.maxValue, "maxValue").to.be.closeTo(15.3, 0.1);
54+
expect((axis.maxValue - axis.minValue) / axis.drawLength, "ratio").to.be.closeTo((otherAxis.maxValue - otherAxis.minValue) / otherAxis.drawLength, 0.01);
55+
})
56+
57+
it('should update the origin and end points of the axis', function() {
58+
const axis = new Axis(vector, boundingBox, origin, end, name, initScale, nTicks);
59+
const newOrigin = new Vertex(100, 100);
60+
const newEnd = new Vertex(100, 200);
61+
axis.transform(newOrigin, newEnd);
62+
63+
expect(axis.origin.x, "origin.x").to.equal(newOrigin.x);
64+
expect(axis.end.y, "end.y").to.equal(newEnd.y);
65+
});
66+
67+
it('should change axis scale', function() {
68+
const axis = new Axis(vector, boundingBox, origin, end, name, initScale, nTicks);
69+
const viewPoint = new Vertex(20, 20);
70+
const scaling = new Vertex(2, 0.5);
71+
const translation = new Vertex();
72+
axis.updateScale(viewPoint, scaling, translation);
73+
74+
expect(axis.minValue, "minValue").to.be.closeTo(-0.08, 0.005);
75+
expect(axis.maxValue, "maxValue").to.be.closeTo(8.7, 0.05);
76+
});
77+
78+
it('should update axis with translation and style', function() {
79+
const axis = new Axis(vector, boundingBox, origin, end, name, initScale, nTicks);
80+
const viewPoint = new Vertex(0, 0);
81+
const scaling = new Vertex(1, 1);
82+
const translation = new Vertex(4 * axis.transformMatrix.a, 4 * axis.transformMatrix.a);
83+
const axisStyle = new Map<string, any>([
84+
["lineWidth", 3],
85+
["strokeStyle", "hsl(12, 45%, 80%)"]
86+
])
87+
axis.update(axisStyle, viewPoint, scaling, translation);
88+
89+
expect(axis.minValue, "minValue").to.be.closeTo(-3.2, 0.1);
90+
expect(axis.maxValue, "maxValue").to.be.closeTo(1.2, 0.1);
91+
expect(axis.lineWidth, "lineWidth").to.be.equal(3);
92+
expect(axis.strokeStyle, "strokeStyle").to.equal("hsl(12, 45%, 80%)")
93+
});
94+
95+
it('should reset scale and translation', function() {
96+
const axis = new Axis(vector, boundingBox, origin, end, name, initScale, nTicks);
97+
axis.updateScale(new Vertex(20, 20), new Vertex(2, 0.5), new Vertex());
98+
axis.updateScale(new Vertex(), new Vertex(1, 1), new Vertex(25, 25));
99+
axis.resetScale();
100+
101+
expect(axis.minValue, "minValue").to.be.equal(0.8);
102+
expect(axis.maxValue, "maxValue").to.be.equal(5.2);
103+
});
104+
105+
it("should transform a string array into values array for ticks to be drawn", function() {
106+
const stringVector = ["z", "e", "z", "y", "o", "u", "p", "i", "p", "p"];
107+
const stringAxis = new Axis(stringVector, boundingBox, origin, end, name, initScale, nTicks);
108+
const numberVector = [1, 1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 5];
109+
const numberAxis = new Axis(numberVector, boundingBox, origin, end, name, initScale, nTicks);
110+
const numericStringVector = stringAxis.stringsToValues(stringVector);
111+
const numericNumberVector = numberAxis.stringsToValues(numberVector);
112+
113+
numericStringVector.forEach((value, index) => expect(stringAxis.labels[value], `string value ${index}`).to.equal(stringVector[index]));
114+
numericNumberVector.forEach((value, index) => expect(value, `number value ${index}`).to.equal(numberVector[index]));
115+
})
116+
});
117+
118+
describe("RubberBand", function() {
119+
const canvas = document.createElement('canvas');
120+
const context = canvas.getContext('2d');
121+
const axis = new Axis(vector, boundingBox, origin, end, name, initScale, nTicks);
122+
const mouseClick = new Vertex(0, 50);
123+
axis.mouseMove(context, mouseClick);
124+
axis.mouseDown(mouseClick);
125+
axis.mouseMove(context, new Vertex(0, 75));
126+
axis.mouseUp(false);
127+
128+
it("should draw rubberBand", function() {
129+
expect(axis.rubberBand.minValue, "rubberBand minValue").to.be.closeTo(3, 0.001);
130+
expect(axis.rubberBand.maxValue, "rubberBand maxValue").to.be.closeTo(4.1, 0.001);
131+
});
132+
133+
it("should translate rubberBand", function () {
134+
const mouseClickInRubberBand = new Vertex(0, 60);
135+
const previousMinValue = axis.rubberBand.minValue;
136+
const previousMaxValue = axis.rubberBand.maxValue;
137+
axis.mouseMove(context, mouseClickInRubberBand);
138+
axis.mouseDown(mouseClickInRubberBand);
139+
axis.mouseMove(context, new Vertex(0, 90));
140+
axis.mouseUp(false);
141+
expect(axis.rubberBand.minValue, "translated rubberBand minValue").to.not.be.equal(previousMinValue);
142+
expect(axis.rubberBand.maxValue, "translated rubberBand maxValue").to.not.be.equal(previousMaxValue);
143+
expect(axis.rubberBand.length, "translated rubberBand maxValue").to.be.closeTo(Math.abs(previousMaxValue - previousMinValue), 0.00001);
144+
});
145+
146+
it("should reset rubberBand", function () {
147+
axis.reset();
148+
expect(axis.rubberBand.minValue, "reset rubberBand minValue").to.equal(0);
149+
expect(axis.rubberBand.maxValue, "reset rubberBand maxValue").to.equal(0);
150+
});
151+
});
152+
153+
describe('ParallelAxis', function() {
154+
155+
const vector = [1, 2, 3, 4, 5];
156+
const boundingBox = new Rect(new Vertex(-50, 0), new Vertex(50, 150));
157+
const origin = new Vertex(0, 0);
158+
const end = new Vertex(0, 100);
159+
const name = "parallel axis";
160+
const initScale = new Vertex(1, 1);
161+
const nTicks = 5;
162+
163+
it('should draw a vertical axis on the canvas', function() {
164+
const canvas = document.createElement('canvas');
165+
const context = canvas.getContext('2d');
166+
const parallelAxis = new ParallelAxis(vector, boundingBox, origin, end, name, initScale, nTicks);
167+
168+
parallelAxis.computeTitle(0, 1);
169+
170+
expect(parallelAxis.titleSettings.baseline, "default baseline").to.be.null;
171+
expect(parallelAxis.titleSettings.orientation, "default orientation").to.be.null;
172+
173+
parallelAxis.draw(context);
174+
175+
expect(parallelAxis.titleSettings.baseline, "updated baseline").to.be.equal("top");
176+
expect(parallelAxis.titleSettings.orientation, "updated orientation").to.be.equal(0);
177+
});
178+
179+
it('should draw a horizontal axis on the canvas', function() {
180+
const canvas = document.createElement('canvas');
181+
const context = canvas.getContext('2d');
182+
const parallelAxis = new ParallelAxis(vector, boundingBox, new Vertex(0, 0), new Vertex(100, 0), name, initScale, nTicks);
183+
184+
parallelAxis.computeTitle(0, 1);
185+
186+
expect(parallelAxis.titleSettings.baseline, "default baseline").to.be.null;
187+
188+
parallelAxis.draw(context);
189+
190+
expect(parallelAxis.titleSettings.baseline, "updated baseline").to.be.equal("bottom");
191+
});
192+
193+
it('should move when title is moved', function() {
194+
const canvas = document.createElement('canvas');
195+
const context = canvas.getContext('2d');
196+
const parallelAxis = new ParallelAxis(vector, boundingBox, new Vertex(0, 0), new Vertex(100, 0), name, initScale, nTicks);
197+
const newLocation = new Vertex(25, 25);
198+
parallelAxis.computeTitle(0, 1);
199+
parallelAxis.draw(context);
200+
parallelAxis.mouseMove(context, parallelAxis.title.boundingBox.center);
201+
parallelAxis.mouseDown(parallelAxis.title.boundingBox.center);
202+
parallelAxis.mouseMove(context, newLocation);
203+
204+
expect(parallelAxis.origin.x, "origin x").to.be.closeTo(18.15, 0.01);
205+
expect(parallelAxis.origin.y, "origin y").to.be.closeTo(55, 0.01);
206+
207+
parallelAxis.mouseUp(false);
208+
209+
expect(parallelAxis.isClicked, "isClicked").to.be.false;
210+
});
211+
212+
it('should flip when title is clicked', function() {
213+
const canvas = document.createElement('canvas');
214+
const context = canvas.getContext('2d');
215+
const parallelAxis = new ParallelAxis(vector, boundingBox, new Vertex(0, 0), new Vertex(100, 0), name, initScale, nTicks);
216+
let emittedAxis;
217+
parallelAxis.emitter.on("axisStateChange", (updatedAxis) => emittedAxis = updatedAxis);
218+
parallelAxis.computeTitle(0, 1);
219+
parallelAxis.draw(context);
220+
parallelAxis.mouseMove(context, parallelAxis.title.boundingBox.center);
221+
parallelAxis.mouseDown(parallelAxis.title.boundingBox.center);
222+
parallelAxis.mouseUp(false);
223+
224+
expect(parallelAxis.isInverted, "isInverted").to.be.true;
225+
expect(emittedAxis).to.deep.equal(parallelAxis);
226+
});
227+
228+
});

0 commit comments

Comments
 (0)