Skip to content
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

new(mock-data, demo): add stable randomness #1033

Merged
merged 5 commits into from
Jan 26, 2021

Conversation

williaster
Copy link
Collaborator

This PR builds on #1030 and is all about making randomness in demos / happo snapshots stable so that happo diffs don't break on every PR. After it's approved I'll merge it into the chris--happo-ii branch, and then chris--happo-ii into master.

🚀 Enhancements

This PR

  • adds getSeededRandom to @visx/mock-data to support deterministic random number generation
  • adds support for stable randomness via seeds to all @visx/mock-data generator functions
    • genRandomNormalPoints: now accepts seed param
    • genDateValue: now accepts seed + startTimeMs params
    • genStats: now accepts override of random + randomOffset functions which can use getSeededRandom
    • genBin/genBins: already take custom count + bin functions which can use getSeededRandom
    • genPhyllotaxis is already deterministic
  • exports d3-random's getRandomNormal generator from @visx/mock-data
  • adds tests for deterministic behavior

🏠 Internal

  • refactors all @visx/demo examples that rely on the ^above generators or Math.random to use seeded randomness. These were all tested by refreshing the page and ensuring data did not change.
    • axis
    • curve
    • dots
    • drag-i
    • glyph
    • voronoi
    • responsive
    • statsplot
    • streamgraph
    • heatmaps

@hshoff @kristw
cc @lencioni

"@types/d3-random": "^1.1.2",
"d3-random": "^1.0.3"
"@types/d3-random": "^2.2.0",
"d3-random": "^2.2.2"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

support for seeds was just added 🎉

Copy link
Collaborator

@kristw kristw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@williaster williaster merged commit e0a5e61 into chris--happo-ii Jan 26, 2021
@williaster williaster deleted the chris--seedrandom branch January 26, 2021 19:53
williaster added a commit that referenced this pull request Jan 26, 2021
* new(github/workflows): add happo job, split out test and lint jobs

* deps(demo): add happo deps

* new(demo/Gallery): export tiles

* fix(demo): ensure unique sandbox names, ensure correct example package.json import

* new(demo/happo): add happo config

* new(demo/happo): add snapshots for all gallery examples

* github(workflow): add runs-on to all jobs

* fix(happo): use .happo.js asyncTimeout for max timeout in snapshots

* fix(happo): use better variable name, T => Example

* fix(demo/annotation): remove unneeded deps

* fix(workflows/happo): fix working-directory syntax

* fix(workflows/ci): merge back into one job with multiple steps

* fix(workflows/ci/happo): try overriding HAPPO_COMMAND

* fix(happo): move asyncTimeout to separate file

* fix(happo): fix timeout filepath

* new(mock-data, demo): add stable randomness (#1033)

* deps(mock-data): d3-random@^2.2.2 for seeded random

* new(mock-data): add getSeededRandom, support seeds in all generators

* test(mock-data): add tests for seeded random across generators

* new(mock-data): export getRandomNormal

* internal(demo): use stable randomness for all demos

* internal(happo/gallery): factor out reusable renderWithTimeout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants