MCPcopy
hub / github.com/plotly/plotly.js / assertPos

Function assertPos

test/jasmine/tests/draw_newselection_test.js:45–87  ·  view source on GitHub ↗
(actual, expected, tolerance)

Source from the content-addressed store, hash-verified

43}
44
45function assertPos(actual, expected, tolerance) {
46 if(tolerance === undefined) tolerance = 2;
47
48 expect(typeof actual).toEqual(typeof expected);
49
50 if(typeof actual === 'string') {
51 if(expected.indexOf('_') !== -1) {
52 actual = fixDates(actual);
53 expected = fixDates(expected);
54 }
55
56 var cmd1 = parseSvgPath(actual);
57 var cmd2 = parseSvgPath(expected);
58
59 expect(cmd1.length).toEqual(cmd2.length);
60 for(var i = 0; i < cmd1.length; i++) {
61 var A = cmd1[i];
62 var B = cmd2[i];
63 expect(A.length).toEqual(B.length); // svg letters should be identical
64 expect(A[0]).toEqual(B[0]);
65 for(var k = 1; k < A.length; k++) {
66 expect(A[k]).toBeCloseTo(B[k], tolerance);
67 }
68 }
69 } else {
70 var o1 = Object.keys(actual);
71 var o2 = Object.keys(expected);
72 expect(o1.length === o2.length);
73 for(var j = 0; j < o1.length; j++) {
74 var key = o1[j];
75
76 var posA = actual[key];
77 var posB = expected[key];
78
79 if(typeof posA === 'string') {
80 posA = fixDates(posA);
81 posB = fixDates(posB);
82 }
83
84 expect(posA).toBeCloseTo(posB, tolerance);
85 }
86 }
87}
88
89function fixDates(str) {
90 // hack to conver date axes to some numbers to parse with parse-svg-path

Callers 1

Calls 1

fixDatesFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…