Something went wrong. Try again.
COSMO is a tool for exploring astronomical data from the Gaia catalog. tedius.tngl.sh/cosmo
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081// The painted points of the 2D tab: their colors, and where a chart's frame puts them, a point left// out of the grid included.import { describe, expect, test } from "vite-plus/test";import { parseTable } from "@tedius-npm/newman";import { OUTSIDE, paintedPoints, pointAt, projectPoints, sameFrame, type ChartFrame, type ScatterInput,} from "../two-plot";import { paintColor, type ColorStops } from "@tedius-npm/vandelay";
const table = parseTable(new TextEncoder().encode("x,y,bprp\n1,10,0.5\n2,20,\n3,30,2.5\n4,40,1\n"));const stops: ColorStops[] = [ { stop: 0, color: [0, 0, 255] }, { stop: 3, color: [255, 0, 0] },];const input = (paint: ScatterInput["paint"]): ScatterInput => ({ table, rows: Uint32Array.from([0, 1, 2, 3]), x: 0, y: 1, paint, bounds: "rows",});
// x from 1 at the left edge, 10 pixels a unit, and y from 40 at the top edge, going down as y goes upconst frame: ChartFrame = { left: 100, top: 50, right: 130, bottom: 350, x0: 1, xScale: 10, y0: 40, yScale: -10 };
describe("paintedPoints", () => { test("is null with no paint", () => { expect(paintedPoints(input(null))).toBeNull(); });
test("holds the rows' values and paintColor's bytes, black with no paint value", () => { const points = paintedPoints(input({ column: 2, colorRGB: stops }))!; expect([...points.xs]).toEqual([1, 2, 3, 4]); expect([...points.ys]).toEqual([10, 20, 30, 40]); expect([...points.rgb]).toEqual([ ...paintColor(0.5, stops), 0, 0, 0, ...paintColor(2.5, stops), ...paintColor(1, stops), ]); });});
describe("projectPoints", () => { const points = paintedPoints(input({ column: 2, colorRGB: stops }))!;
test("puts each point where the frame maps its values, an inverted axis included", () => { const out = new Float32Array(8); projectPoints(points, frame, out); expect([...out]).toEqual([100, 350, 110, 250, 120, 150, 130, 50]); expect(pointAt(points, frame, 1)).toEqual([110, 250]); });
test("leaves out a point whose center is past the grid, as ECharts does, but keeps one a rounding past an edge", () => { // The right edge a hair short of x = 4, and x = 3 past a right edge moved in const edge = { ...frame, right: 129.95 }; const narrow = { ...frame, right: 115 }; expect(pointAt(points, edge, 3)).toEqual([130, 50]); expect(pointAt(points, narrow, 2)).toBeNull(); const out = new Float32Array(8); projectPoints(points, narrow, out); expect([out[4], out[5], out[6], out[7]]).toEqual([OUTSIDE, OUTSIDE, OUTSIDE, OUTSIDE]); });});
test("sameFrame compares every number, and two missing frames are the same", () => { expect(sameFrame(frame, { ...frame })).toBe(true); expect(sameFrame(frame, { ...frame, yScale: -11 })).toBe(false); expect(sameFrame(null, null)).toBe(true); expect(sameFrame(frame, null)).toBe(false);});