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

Off-by-one fixes & other small changes: website playground, dist charts #2911

Merged
merged 5 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/proud-lamps-hope.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@quri/squiggle-components": patch
---

Fix dist chart legend positioning and how it affects the chart height
60 changes: 34 additions & 26 deletions packages/components/src/widgets/DistWidget/DistributionsChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,21 @@ const InnerDistributionsChart: FC<{
);

const legendItemHeight = 16;
const legendOffset = 2;

const legendHeight = isMulti ? legendItemHeight * shapes.length : 0;
const legendHeight = isMulti
? legendItemHeight * shapes.length + legendOffset
: 0;
const samplesFooterHeight = samplesBarSetting === "bottom" ? 20 : 0;

const height = innerHeight + legendHeight + samplesFooterHeight;
const bottomPadding = (!showXAxis ? 0 : 14) + samplesFooterHeight;

// full height of canvas
const height = Math.max(
innerHeight + samplesFooterHeight,
legendHeight + bottomPadding
);

const discreteRadius = distRadiusScalingFromHeight(height);

const sampleBarHeight =
Expand Down Expand Up @@ -183,7 +191,7 @@ const InnerDistributionsChart: FC<{
context,
width,
height,
suggestedPadding: suggestedPadding,
suggestedPadding,
xScale,
yScale,
showYAxis: false,
Expand All @@ -193,28 +201,6 @@ const InnerDistributionsChart: FC<{
showAxisLines: false,
});

if (isMulti) {
const radius = 5;
for (let i = 0; i < shapes.length; i++) {
context.save();
context.translate(padding.left, legendItemHeight * i);
context.fillStyle = getColor(i);
drawCircle({
context,
x: radius,
y: radius,
r: radius,
});

context.textAlign = "left";
context.textBaseline = "middle";
context.fillStyle = "black";
context.font = "12px sans-serif";
context.fillText(shapes[i].name, 16, radius);
context.restore();
}
}

// samplesBar
function samplesBarShowSettings(): { yOffset: number; color: string } {
if (samplesBarSetting === "behind") {
Expand Down Expand Up @@ -356,6 +342,28 @@ const InnerDistributionsChart: FC<{
frame.exit();
}

if (isMulti) {
const radius = 5;
for (let i = 0; i < shapes.length; i++) {
context.save();
context.translate(padding.left, legendItemHeight * i + legendOffset);
context.fillStyle = getColor(i);
drawCircle({
context,
x: radius,
y: radius,
r: radius,
});

context.textAlign = "left";
context.textBaseline = "middle";
context.fillStyle = "black";
context.font = "12px sans-serif";
context.fillText(shapes[i].name, 16, radius);
context.restore();
}
}

{
showCursorLine &&
drawCursorLines({
Expand Down Expand Up @@ -573,7 +581,7 @@ export const DistributionsChart: FC<DistributionsChartProps> = ({
/>
</div>
)}
{anyAreNonnormalized && (
{anyAreNonnormalized && height > 20 && (
<div className="flex-1 pt-2"> {nonNormalizedError()}</div>
)}
</div>
Expand Down
4 changes: 3 additions & 1 deletion packages/website/src/pages/playground.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ description: Squiggle Playground

import { PlaygroundPage } from "../components/PlaygroundPage";

<PlaygroundPage version={props.version} />
<div style={{ marginTop: 1 }}>
<PlaygroundPage version={props.version} />
</div>

export async function getServerSideProps({ query }) {
return { props: { version: query.v ?? null } };
Expand Down