-
Notifications
You must be signed in to change notification settings - Fork 0
Canvas fit: decouple logical from physical dimensions (closes #17) #63
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
ea9e7a3
Decouple chart dims from canvas with renderToFit and renderWithFit, u…
71e1bcd
Add resize/redraw rendering helpers and switch sandboxes to renderToR…
b475e75
Add pure resize rendering test and apply formatting changes
50aa023
Rename canvas helpers for clarity renderFillCanvas and renderFillCanv…
b19c328
Remove non-uniform fill helpers and docs, keep redraw-only API (rende…
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,18 +7,16 @@ | |
| let | ||
| pkgs = import nixpkgs { inherit system; }; | ||
| jdkToUse = pkgs.jdk17; | ||
| sbtWithJRE = pkgs.sbt.override { jre = jdkToUse; }; | ||
| millWithJRE = pkgs.mill.override { jre = jdkToUse; }; | ||
| in | ||
| { | ||
| devShells.default = pkgs.mkShell { | ||
| packages = [ | ||
| jdkToUse | ||
| sbtWithJRE | ||
| millWithJRE | ||
| pkgs.git | ||
| pkgs.nodejs | ||
| pkgs.yarn | ||
| pkgs.nodePackages_latest.http-server | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed unused package |
||
| ]; | ||
| }; | ||
| } | ||
|
|
||
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
57 changes: 57 additions & 0 deletions
57
florence/test/src/florence/renderer/ResizeRenderingTests.scala
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,57 @@ | ||
| package florence | ||
|
|
||
| import munit.FunSuite | ||
|
|
||
| import florence.core.dsl.LineChartDsl.* | ||
| import florence.core.dsl.styling.LineChartStylingDsl.* | ||
| import florence.core.model.* | ||
| import florence.core.model.styling.* | ||
| import florence.core.model.shared.StyleTypes.* | ||
| import florence.core.rendering.* | ||
|
|
||
| class ResizeRenderingTests extends FunSuite: | ||
|
|
||
| private def hasXAxisAt(ops: List[DrawOp], width: Int, height: Int, margins: Margins): Boolean = | ||
| ops.exists { | ||
| case LineOp(x1, y1, x2, y2, style) => | ||
| val expectedY = height - margins.bottom | ||
| val expectedX1 = margins.left | ||
| val expectedX2 = width - margins.right | ||
| y1 == expectedY && y2 == expectedY && x1 == expectedX1 && x2 == expectedX2 && style.width == 2.0 | ||
| case _ => false | ||
| } | ||
|
|
||
| private def hasYAxisAt(ops: List[DrawOp], height: Int, margins: Margins): Boolean = | ||
| ops.exists { | ||
| case LineOp(x1, y1, x2, y2, style) => | ||
| val expectedX = margins.left | ||
| val expectedY1 = margins.top | ||
| val expectedY2 = height - margins.bottom | ||
| x1 == expectedX && x2 == expectedX && y1 == expectedY1 && y2 == expectedY2 && style.width == 2.0 | ||
| case _ => false | ||
| } | ||
|
|
||
| private def resizedStyle(base: ChartStyle.LineChartStyle, w: Int, h: Int, margins: Margins): ChartStyle.LineChartStyle = | ||
| base | ||
| .withWidth(w) | ||
| .withHeight(h) | ||
| .withMargins(margins) | ||
| .withXAxis(base.xAxis.copy(gridLines = false)) | ||
| .withYAxis(base.yAxis.copy(gridLines = false)) | ||
|
|
||
| private def simpleChart: Chart.LineChart = | ||
| lineChart("t", pointsSeries("s", (1.0, 1.0), (2.0, 2.0))) | ||
|
|
||
| test("axes respect resized width/height at 600x200"): | ||
| val margins = Margins(20, 40, 30, 50) | ||
| val style = resizedStyle(lineChartStyle(), 600, 200, margins) | ||
| val drawing = LineChartInterpreter.interpretLineChart(simpleChart, style) | ||
| assert(hasXAxisAt(drawing.ops, 600, 200, margins)) | ||
| assert(hasYAxisAt(drawing.ops, 200, margins)) | ||
|
|
||
| test("axes respect resized width/height at 1300x300"): | ||
| val margins = Margins(30, 60, 40, 70) | ||
| val style = resizedStyle(lineChartStyle(), 1300, 300, margins) | ||
| val drawing = LineChartInterpreter.interpretLineChart(simpleChart, style) | ||
| assert(hasXAxisAt(drawing.ops, 1300, 300, margins)) | ||
| assert(hasYAxisAt(drawing.ops, 300, margins)) |
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.
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.
removed sbt since we are not using it