-
Notifications
You must be signed in to change notification settings - Fork 18
feat(diff-views): per-bar histogram colors, sparkline rendering, color_static parity #958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
paddymul
wants to merge
1
commit into
main
Choose a base branch
from
feat/diff-view-pinned-plots
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
packages/buckaroo-js-core/src/components/DFViewerParts/ChartCell.render.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /** | ||
| * Sparkline rendering contract for the chart cell (pinned rows and data | ||
| * columns): | ||
| * - every line series draws at 1px with per-point dots disabled — the | ||
| * 100x24 chart gets CSS-scaled to fill its grid cell, which turns the | ||
| * recharts defaults (dots + scaled stroke) into a fat blobby squiggle | ||
| * - a hidden YAxis pads the plot by 2px top and bottom so a series whose | ||
| * values sit exactly at dataMin/dataMax (e.g. the "after" side of a | ||
| * diff whose values collapsed) isn't drawn on the plot border where | ||
| * the clip rect swallows half the stroke | ||
| */ | ||
| jest.mock("react", () => { | ||
| const actual = jest.requireActual("react"); | ||
| return { __esModule: true, default: actual, ...actual }; | ||
| }); | ||
|
|
||
| import { render } from "@testing-library/react"; | ||
| import { getChartCell, LineObservation } from "./ChartCell"; | ||
|
|
||
| // recharts pulls in DOM-measurement code that doesn't run cleanly under | ||
| // jsdom — stub the exports ChartCell touches, keeping Line/YAxis props | ||
| // inspectable in the rendered tree. | ||
| jest.mock("recharts", () => { | ||
| const React = require("react"); | ||
| return { | ||
| Area: () => null, | ||
| Bar: () => null, | ||
| Line: ({ dataKey, dot, strokeWidth }: any) => | ||
| React.createElement("div", { | ||
| "data-testid": `line-${dataKey}`, | ||
| "data-dot": String(dot), | ||
| "data-stroke-width": String(strokeWidth), | ||
| }), | ||
| Tooltip: () => null, | ||
| YAxis: ({ hide, padding }: any) => | ||
| React.createElement("div", { | ||
| "data-testid": "yaxis-mock", | ||
| "data-hide": String(hide), | ||
| "data-padding-top": String(padding?.top), | ||
| "data-padding-bottom": String(padding?.bottom), | ||
| }), | ||
| ComposedChart: ({ children }: any) => | ||
| React.createElement("div", { "data-testid": "composedchart-mock" }, children), | ||
| }; | ||
| }); | ||
|
|
||
| const ChartCell = getChartCell({ displayer: "chart" }); | ||
|
|
||
| const validChart: LineObservation[] = [{ lineRed: 10 }, { lineRed: 20 }]; | ||
|
|
||
| const mkProps = (value: any) => ({ | ||
| value, | ||
| api: {} as any, | ||
| colDef: { cellClass: "" } as any, | ||
| column: {} as any, | ||
| context: {}, | ||
| }); | ||
|
|
||
| describe("ChartCell sparkline rendering", () => { | ||
| it("draws every line series at 1px with dots disabled", () => { | ||
| const { container } = render(<ChartCell {...mkProps(validChart)} />); | ||
| const lines = container.querySelectorAll('[data-testid^="line-"]'); | ||
| expect(lines.length).toBeGreaterThan(0); | ||
| lines.forEach((line) => { | ||
| expect(line.getAttribute("data-dot")).toBe("false"); | ||
| expect(line.getAttribute("data-stroke-width")).toBe("1"); | ||
| }); | ||
| }); | ||
|
|
||
| it("pads the y domain via a hidden axis so edge-hugging series are not clipped", () => { | ||
| const { getByTestId } = render(<ChartCell {...mkProps(validChart)} />); | ||
| const axis = getByTestId("yaxis-mock"); | ||
| expect(axis.getAttribute("data-hide")).toBe("true"); | ||
| expect(axis.getAttribute("data-padding-top")).toBe("2"); | ||
| expect(axis.getAttribute("data-padding-bottom")).toBe("2"); | ||
| }); | ||
| }); |
79 changes: 79 additions & 0 deletions
79
packages/buckaroo-js-core/src/components/DFViewerParts/HistogramCell.colors.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /** | ||
| * Per-bar color support on the histogram cell: a HistogramBar may carry | ||
| * `color`, and the population Bar renders one recharts Cell per datum so | ||
| * the color lands on that individual bar. Diff views use this to paint the | ||
| * change-distribution histogram with the same color key as the data cells; | ||
| * bars without a color keep the scheme default. | ||
| */ | ||
| // jsdom's `crypto` lacks `randomUUID`; HistogramCell's gensym() uses it. | ||
| { | ||
| let n = 0; | ||
| const existing: any = (globalThis as any).crypto || {}; | ||
| if (typeof existing.randomUUID !== "function") { | ||
| try { | ||
| Object.defineProperty(existing, "randomUUID", { | ||
| configurable: true, | ||
| value: () => `test-uuid-${++n}`, | ||
| }); | ||
| } catch { | ||
| Object.defineProperty(globalThis, "crypto", { | ||
| configurable: true, | ||
| value: { ...existing, randomUUID: () => `test-uuid-${++n}` }, | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // ts-jest in this repo doesn't apply esModuleInterop, so the default import | ||
| // `import React from "react"` in HistogramCell.tsx resolves to `undefined` | ||
| // at runtime without a `.default` on the mock. | ||
| jest.mock("react", () => { | ||
| const actual = jest.requireActual("react"); | ||
| return { __esModule: true, default: actual, ...actual }; | ||
| }); | ||
|
|
||
| import { render } from "@testing-library/react"; | ||
| import type { ColDef, Column, Context, GridApi } from "ag-grid-community"; | ||
| import { HistogramCell } from "./HistogramCell"; | ||
|
|
||
| // recharts pulls in DOM-measurement code that doesn't run cleanly under | ||
| // jsdom — stub the exports HistogramCell touches, keeping Bar/Cell props | ||
| // inspectable in the rendered tree. | ||
| jest.mock("recharts", () => { | ||
| const React = require("react"); | ||
| return { | ||
| Bar: ({ children, dataKey }: any) => | ||
| React.createElement("div", { "data-testid": `bar-${dataKey}` }, children), | ||
| BarChart: ({ children }: any) => | ||
| React.createElement("div", { "data-testid": "barchart-mock" }, children), | ||
| Cell: ({ fill }: any) => | ||
| React.createElement("div", { "data-testid": "cell-mock", "data-fill": fill }), | ||
| Tooltip: () => null, | ||
| }; | ||
| }); | ||
|
|
||
| const mkProps = (value: any) => ({ | ||
| value, | ||
| api: {} as GridApi, | ||
| colDef: { cellClass: "" } as ColDef, | ||
| column: {} as Column, | ||
| context: {} as Context, | ||
| }); | ||
|
|
||
| describe("HistogramCell per-bar colors", () => { | ||
| it("renders one Cell per datum on the population bar, honoring bar.color", () => { | ||
| const bars = [ | ||
| { name: "<-50%", population: 20, color: "#d62728" }, | ||
| { name: "~0%", population: 80 }, | ||
| ]; | ||
| const { getByTestId } = render(<HistogramCell {...mkProps(bars)} />); | ||
| const popBar = getByTestId("bar-population"); | ||
| const cells = popBar.querySelectorAll('[data-testid="cell-mock"]'); | ||
| expect(cells).toHaveLength(2); | ||
| expect(cells[0].getAttribute("data-fill")).toBe("#d62728"); | ||
| // Uncolored bars keep the scheme default fill — set, and not the | ||
| // colored bar's value. | ||
| expect(cells[1].getAttribute("data-fill")).toBeTruthy(); | ||
| expect(cells[1].getAttribute("data-fill")).not.toBe("#d62728"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this commit is reviewed by itself, this assertion makes the suite fail:
col_join_dfsstill returns{"color_rule": "color_categorical", ...}for join keys inbuckaroo/compare.py, and the same commit also adds JS assertions forChartCell/HistogramCellbehavior that those components still do not render. Because only tests changed here, CI will stay red for every run that includes these tests; include the corresponding implementation in this commit or keep these red tests out of the mergeable change.Useful? React with 👍 / 👎.