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

D3 Negative Dists #3126

Merged
merged 3 commits into from
Mar 28, 2024
Merged

D3 Negative Dists #3126

merged 3 commits into from
Mar 28, 2024

Conversation

OAGr
Copy link
Contributor

@OAGr OAGr commented Mar 26, 2024

Before:
image

After:
image

Now it shows the full negative values.

Closes #3122

Copy link

changeset-bot bot commented Mar 26, 2024

⚠️ No Changeset found

Latest commit: 39cd527

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

vercel bot commented Mar 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
quri-hub ✅ Ready (Inspect) Visit Preview Mar 26, 2024 1:13pm
squiggle-components ✅ Ready (Inspect) Visit Preview Mar 26, 2024 1:13pm
squiggle-website ✅ Ready (Inspect) Visit Preview Mar 26, 2024 1:13pm
1 Ignored Deployment
Name Status Preview Updated (UTC)
quri-ui ⬜️ Ignored (Inspect) Visit Preview Mar 26, 2024 1:13pm

@@ -579,7 +601,9 @@ export const DistributionsChart: FC<DistributionsChartProps> = ({
height={height}
samplesBarSetting={samplesState}
showCursorLine={nonTitleHeight > 30}
showPercentileLines={nonTitleHeight > 30}
showPercentileLines={
!anyAreNonnormalized && nonTitleHeight > 30
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If any were nonnormalized, the percentileLines wouldn't make sense

@@ -341,6 +348,20 @@ const InnerDistributionsChart: FC<{
frame.exit();
}

drawAxes({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has to be at the end, to make sure that the axis is on top of the plot

@@ -242,14 +249,14 @@ const InnerDistributionsChart: FC<{

// continuous fill
//In the case of one distribution, we don't want it to be transparent, so that we can show the samples lines. In the case of multiple distributions, we want them to be transparent so that we can see the other distributions.
context.fillStyle = isMulti ? getColor(i, 0) : getColor(i, 0.7);
context.globalAlpha = isMulti ? 0.4 : 1;
context.fillStyle = isMulti ? getColor(i, 0.5) : getColor(i, 0.7);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

todo: revert

@@ -227,6 +232,8 @@ const InnerDistributionsChart: FC<{
context.restore();
}

context.globalCompositeOperation = "source-over";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

todo: revert

@@ -160,7 +162,12 @@ const InnerDistributionsChart: FC<{
]);

const yScale = sqScaleToD3(plot.yScale);
yScale.domain([0, Math.max(...domain.map((p) => p.y))]);
// yScale.domain([0, Math.max(...domain.map((p) => p.y))]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

todo: delete

if (yAxisTitle) {
padding.left = padding.left + 35;
}
const padding: Padding = calculatePadding({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

todo: Discuss the best way to refactor/organize this

Copy link
Collaborator

@berekuk berekuk left a comment

Choose a reason for hiding this comment

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

Kudos on fixing this, the output looks much better.

The implementation is making me nervous: there are a few implicit assumptions that you make (calculatePadding being consistent) that look like they hold right now but might break in the future.

I haven't verified it but I think if someone (1) enables y axis; (2) uses big numbers on y scale that would cause long ticks, then the chart would break.

I'll spend 30-60min on reorganize the code, and if it proves too hard then I'll add a few comments and then merge.

@OAGr OAGr merged commit 117a40f into main Mar 28, 2024
6 checks passed
@OAGr OAGr deleted the d3-negative-dists branch March 28, 2024 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Dist plots with negative mass get cut off
2 participants