-
Notifications
You must be signed in to change notification settings - Fork 136
Clean up streaming category ordering #850
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
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
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
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
98 changes: 98 additions & 0 deletions
98
src/components/charts/ordinal/DotPlot.streaming-order.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,98 @@ | ||
| import { describe, it, expect, beforeEach, afterEach } from "vitest" | ||
| import React from "react" | ||
| import { render, act } from "@testing-library/react" | ||
| import { DotPlot } from "./DotPlot" | ||
| import { TooltipProvider } from "../../store/TooltipStore" | ||
| import { setupCanvasMock } from "../../../test-utils/canvasMock" | ||
|
|
||
| // Mock ResizeObserver for jsdom | ||
| if (typeof globalThis.ResizeObserver === "undefined") { | ||
| (globalThis as any).ResizeObserver = class { | ||
| observe() {} | ||
| unobserve() {} | ||
| disconnect() {} | ||
| } | ||
| } | ||
|
|
||
| // End-to-end test (real StreamOrdinalFrame) for DotPlot's default | ||
| // `sort="auto"` behavior: insertion order while streaming, value-desc | ||
| // when static. The sibling DotPlot.test.tsx mocks the frame and can | ||
| // only inspect props — it can't verify the scene actually renders in | ||
| // the expected order. | ||
|
|
||
| describe("DotPlot streaming category order", () => { | ||
| let cleanup: () => void | ||
| beforeEach(() => { cleanup = setupCanvasMock() }) | ||
| afterEach(() => { cleanup() }) | ||
|
|
||
| it("default sort='auto' preserves insertion order under streaming", async () => { | ||
| const ref = React.createRef<any>() | ||
| render( | ||
| <TooltipProvider> | ||
| <DotPlot ref={ref} categoryAccessor="category" valueAccessor="value" /> | ||
| </TooltipProvider> | ||
| ) | ||
|
|
||
| // Push categories in the order C → A → B — if the store value-sorted | ||
| // (the pre-"auto" default of `sort=true`), the domain would come | ||
| // out ["B", "A", "C"]. "auto" under streaming should preserve FIFO. | ||
| await act(async () => { | ||
| ref.current.push({ category: "C", value: 10 }) | ||
| }) | ||
| await act(async () => { | ||
| ref.current.push({ category: "A", value: 30 }) | ||
| }) | ||
| await act(async () => { | ||
| ref.current.push({ category: "B", value: 20 }) | ||
| }) | ||
|
|
||
| const domain = ref.current.getScales()?.o.domain() | ||
| expect(domain).toEqual(["C", "A", "B"]) | ||
| }) | ||
|
|
||
| it("default sort='auto' falls through to value-desc on static data", () => { | ||
| const ref = React.createRef<any>() | ||
| render( | ||
| <TooltipProvider> | ||
| <DotPlot | ||
| ref={ref} | ||
| data={[ | ||
| { category: "Small", value: 1 }, | ||
| { category: "Big", value: 100 }, | ||
| { category: "Medium", value: 50 }, | ||
| ]} | ||
| categoryAccessor="category" | ||
| valueAccessor="value" | ||
| /> | ||
| </TooltipProvider> | ||
| ) | ||
| // No push — purely static data. sort="auto" should behave like the | ||
| // old default of sort=true: value-descending. | ||
| const domain = ref.current.getScales()?.o.domain() | ||
| expect(domain).toEqual(["Big", "Medium", "Small"]) | ||
| }) | ||
|
|
||
| it("explicit sort='desc' wins over auto even during streaming", async () => { | ||
| // Regression guard: users who opt into value-sort during streaming | ||
| // (e.g. "I want this to always value-sort, shuffle be damned") must | ||
| // get that behavior. "auto" applies only when sort is unset or | ||
| // explicitly "auto". | ||
| const ref = React.createRef<any>() | ||
| render( | ||
| <TooltipProvider> | ||
| <DotPlot | ||
| ref={ref} | ||
| categoryAccessor="category" | ||
| valueAccessor="value" | ||
| sort="desc" | ||
| /> | ||
| </TooltipProvider> | ||
| ) | ||
| await act(async () => { ref.current.push({ category: "Low", value: 10 }) }) | ||
| await act(async () => { ref.current.push({ category: "High", value: 100 }) }) | ||
| await act(async () => { ref.current.push({ category: "Mid", value: 50 }) }) | ||
|
|
||
| const domain = ref.current.getScales()?.o.domain() | ||
| expect(domain).toEqual(["High", "Mid", "Low"]) | ||
| }) | ||
| }) |
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
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
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
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
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
115 changes: 115 additions & 0 deletions
115
src/components/charts/ordinal/LikertChart.streaming-order.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,115 @@ | ||
| import { describe, it, expect, beforeEach, afterEach } from "vitest" | ||
| import React from "react" | ||
| import { render, act } from "@testing-library/react" | ||
| import { LikertChart } from "./LikertChart" | ||
| import { TooltipProvider } from "../../store/TooltipStore" | ||
| import { setupCanvasMock } from "../../../test-utils/canvasMock" | ||
|
|
||
| // Mock ResizeObserver for jsdom | ||
| if (typeof globalThis.ResizeObserver === "undefined") { | ||
| (globalThis as any).ResizeObserver = class { | ||
| observe() {} | ||
| unobserve() {} | ||
| disconnect() {} | ||
| } | ||
| } | ||
|
|
||
| // This file tests LikertChart end-to-end with the real StreamOrdinalFrame | ||
| // (unlike LikertChart.test.tsx, which mocks the frame to inspect props). | ||
| // Purpose: lock down the streaming category-ordering contract that | ||
| // regressed when `replace()` cleared the category Set on every | ||
| // aggregation. Each push should leave the question order stable even | ||
| // when the per-question value ordering shifts dramatically. | ||
|
|
||
| describe("LikertChart streaming category order", () => { | ||
| let cleanup: () => void | ||
| beforeEach(() => { cleanup = setupCanvasMock() }) | ||
| afterEach(() => { cleanup() }) | ||
|
|
||
| const levels = ["Strongly Disagree", "Disagree", "Neutral", "Agree", "Strongly Agree"] | ||
|
|
||
| it("preserves question order across pushes where the value-ranked order changes", async () => { | ||
| const ref = React.createRef<any>() | ||
| render( | ||
| <TooltipProvider> | ||
| <LikertChart | ||
| ref={ref} | ||
| levels={levels} | ||
| valueAccessor="score" | ||
| categoryAccessor="question" | ||
| /> | ||
| </TooltipProvider> | ||
| ) | ||
|
|
||
| // Seed with responses across three questions in insertion order Q1 → Q2 → Q3. | ||
| await act(async () => { | ||
| ref.current.pushMany([ | ||
| { question: "Q1", score: 3 }, | ||
| { question: "Q1", score: 4 }, | ||
| { question: "Q2", score: 2 }, | ||
| { question: "Q3", score: 5 }, | ||
| ]) | ||
| }) | ||
| await new Promise(r => queueMicrotask(() => r(null))) // let adapter microtask flush | ||
|
|
||
| const firstDomain = ref.current.getScales()?.o.domain() | ||
| expect(firstDomain).toEqual(["Q1", "Q2", "Q3"]) | ||
|
|
||
| // Push a batch that flips the per-question total-response counts — | ||
| // Q3 now has by far the most responses, Q1 the fewest. Under the | ||
| // old value-desc ordering this would put Q3 first and Q1 last. | ||
| // preserveCategoryOrder should keep Q1 → Q2 → Q3. | ||
| await act(async () => { | ||
| ref.current.pushMany([ | ||
| { question: "Q3", score: 5 }, | ||
| { question: "Q3", score: 4 }, | ||
| { question: "Q3", score: 5 }, | ||
| { question: "Q3", score: 4 }, | ||
| { question: "Q2", score: 3 }, | ||
| { question: "Q2", score: 3 }, | ||
| ]) | ||
| }) | ||
| await new Promise(r => queueMicrotask(() => r(null))) | ||
|
|
||
| const secondDomain = ref.current.getScales()?.o.domain() | ||
| expect(secondDomain).toEqual(["Q1", "Q2", "Q3"]) | ||
| }) | ||
|
|
||
| it("appends a newly-arriving question at the end, not at the top by value", async () => { | ||
| const ref = React.createRef<any>() | ||
| render( | ||
| <TooltipProvider> | ||
| <LikertChart | ||
| ref={ref} | ||
| levels={levels} | ||
| valueAccessor="score" | ||
| categoryAccessor="question" | ||
| /> | ||
| </TooltipProvider> | ||
| ) | ||
|
|
||
| await act(async () => { | ||
| ref.current.pushMany([ | ||
| { question: "Q1", score: 3 }, | ||
| { question: "Q2", score: 4 }, | ||
| ]) | ||
| }) | ||
| await new Promise(r => queueMicrotask(() => r(null))) | ||
| expect(ref.current.getScales()?.o.domain()).toEqual(["Q1", "Q2"]) | ||
|
|
||
| // Q3 arrives late but gets a huge number of responses. It should | ||
| // still land at the end of the axis (FIFO), not at the front. | ||
| await act(async () => { | ||
| ref.current.pushMany([ | ||
| { question: "Q3", score: 5 }, | ||
| { question: "Q3", score: 5 }, | ||
| { question: "Q3", score: 5 }, | ||
| { question: "Q3", score: 5 }, | ||
| { question: "Q3", score: 5 }, | ||
| ]) | ||
| }) | ||
| await new Promise(r => queueMicrotask(() => r(null))) | ||
|
|
||
| expect(ref.current.getScales()?.o.domain()).toEqual(["Q1", "Q2", "Q3"]) | ||
| }) | ||
| }) |
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
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.
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.
Uh oh!
There was an error while loading. Please reload this page.