MCPcopy
hub / github.com/palantir/plottable / assertPathEqualToDataPoints

Function assertPathEqualToDataPoints

test/testMethods.ts:421–452  ·  view source on GitHub ↗
(path: string, data: {x: number, y: number}[],
                                            xScale: Plottable.QuantitativeScale<any>, yScale: Plottable.QuantitativeScale<any>)

Source from the content-addressed store, hash-verified

419}
420
421export function assertPathEqualToDataPoints(path: string, data: {x: number, y: number}[],
422 xScale: Plottable.QuantitativeScale<any>, yScale: Plottable.QuantitativeScale<any>) {
423 const EPSILON = 0.0001;
424 const lineEdges = normalizePath(path).match(/([MmLl](\-?\d+\.?\d*)(,|\s)(-?\d+\.?\d*)|([HhVv](\-?\d+\.?\d*)))/g);
425 assert.strictEqual(lineEdges.length, data.length, "correct number of edges drawn");
426 lineEdges.forEach((edge, i) => {
427 const command = edge[0];
428 const coordinates = edge.slice(1).split(/,|\s/);
429 switch (command) {
430 case "M":
431 case "m":
432 case "L":
433 case "l":
434 assert.strictEqual(coordinates.length, 2, "There is an x coordinate and a y coordinate");
435 assertPointsClose({ x: xScale.invert(+coordinates[0]), y: yScale.invert(+coordinates[1]) },
436 data[i], EPSILON, `Point ${i} drawn, has correct coordinates`);
437 break;
438 case "H":
439 case "h":
440 assert.strictEqual(coordinates.length, 1, "There is an x coordinate");
441 assert.closeTo(xScale.invert(+coordinates[0]), data[i].x, EPSILON,
442 `Point ${i} drawn, has correct x coordinate`);
443 break;
444 case "V":
445 case "v":
446 assert.strictEqual(coordinates.length, 1, "There is a y coordinate");
447 assert.closeTo(yScale.invert(+coordinates[0]), data[i].y, EPSILON,
448 `Point ${i} drawn, has correct y coordinate`);
449 break;
450 }
451 });
452}

Callers

nothing calls this directly

Calls 5

normalizePathFunction · 0.85
assertPointsCloseFunction · 0.85
forEachMethod · 0.45
splitMethod · 0.45
invertMethod · 0.45

Tested by

no test coverage detected