-
Notifications
You must be signed in to change notification settings - Fork 5
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
Scalebar: Refactor ViewModel #715
Closed
eri9000
wants to merge
29
commits into
feature-branches/scalebar
from
Erick/scalebar-internals-refactor
Closed
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
38eea4e
WIP
puneet-pdx c72fab4
WIP
puneet-pdx dad7ec5
Update tests
puneet-pdx 317352c
update maxLength calc
puneet-pdx fe2ec0b
update test
puneet-pdx 72de31b
fix bug where the scalebar was not displaying fraction values
puneet-pdx 387b32e
optimize imports
puneet-pdx fd887a7
Refactor fun names
puneet-pdx ff0c93c
add doc
puneet-pdx 7ed31a2
address code review comments
puneet-pdx ef93e8b
make measureMinSegmentWidth private
puneet-pdx a62a3d1
remove showScalebar fun
puneet-pdx 824558e
optimize import
puneet-pdx 698603c
Revert "optimize import"
puneet-pdx 4c61fae
Revert "remove showScalebar fun"
puneet-pdx b589861
Revert "make measureMinSegmentWidth private"
puneet-pdx 2a7bd00
working proto
eri9000 b75e62c
Merge branch 'feature-branches/scalebar' into Erick/copyOf_5189
eri9000 34cfa11
Update Scalebar.kt
eri9000 cbbc8a5
working protto 2
eri9000 2c4b125
updates test
eri9000 6858d1d
rename a few properties
eri9000 5d6dd45
update method signature
eri9000 f2317b6
update names
eri9000 adc6cd5
rename composable to match guidelines
eri9000 f6cac20
update retrieval of last label or empty if there's none
eri9000 783b76e
refactor names
eri9000 50d56d0
Merge branch 'feature-branches/scalebar' into Erick/scalebar-internal…
eri9000 46767d8
additional merge fixes
eri9000 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 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
141 changes: 141 additions & 0 deletions
141
.../scalebar/src/androidTest/java/com/arcgismaps/toolkit/scalebar/ScalebarComputationTest.kt
This file contains 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,141 @@ | ||
/* | ||
* Copyright 2025 Esri | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.arcgismaps.toolkit.scalebar | ||
|
||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.text.TextStyle | ||
import androidx.compose.ui.unit.sp | ||
import com.arcgismaps.geometry.Point | ||
import com.arcgismaps.geometry.SpatialReference | ||
import com.arcgismaps.mapping.Viewpoint | ||
import com.arcgismaps.toolkit.scalebar.theme.LabelTypography | ||
import com.google.common.truth.Truth.assertThat | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class ScalebarCalculationsTest { | ||
@get:Rule | ||
val composeTestRule = createComposeRule() | ||
|
||
private val esriRedlands = Point(-13046081.04434825, 4036489.208008117, SpatialReference.webMercator()) | ||
private val defaultLabelTypography = LabelTypography(labelStyle = TextStyle(fontSize = 11.sp)) | ||
|
||
/** | ||
* Given map properties and device properties | ||
* When the properties of a line style scalebar are computed | ||
* Then the display length and labels should be correct | ||
* | ||
* @since 200.7.0 | ||
*/ | ||
@Test | ||
fun testLineStyle() { | ||
testScalebarCalculations( | ||
point = esriRedlands, | ||
style = ScalebarStyle.Line, | ||
maxWidth = 175.0, | ||
units = ScalebarUnits.METRIC, | ||
scale = 10000000.0, | ||
unitsPerDip = 2645.833333330476, | ||
labelTypography = defaultLabelTypography, | ||
expectedDisplayLength = 171.0, | ||
expectedLabels = listOf("375 km") | ||
) | ||
} | ||
|
||
/** | ||
* Given map properties and device properties | ||
* When the properties of a bar scalebar are calculated | ||
* Then the display length and labels should be correct | ||
* | ||
* @since 200.7.0 | ||
*/ | ||
@Test | ||
fun testBarStyle() = runTest { | ||
testScalebarCalculations( | ||
point = esriRedlands, | ||
style = ScalebarStyle.Bar, | ||
maxWidth = 175.0, | ||
units = ScalebarUnits.METRIC, | ||
scale = 10000000.0, | ||
unitsPerDip = 2645.833333330476, | ||
labelTypography = defaultLabelTypography, | ||
expectedDisplayLength = 171.0, | ||
expectedLabels = listOf("375 km") | ||
) | ||
} | ||
|
||
|
||
/** | ||
* Executes the scalebar calculations and verifies the results. | ||
* | ||
* @since 200.7.0 | ||
*/ | ||
private fun testScalebarCalculations( | ||
point: Point, | ||
style: ScalebarStyle, | ||
maxWidth: Double, | ||
units: ScalebarUnits, | ||
scale: Double, | ||
unitsPerDip: Double, | ||
labelTypography: LabelTypography, | ||
expectedDisplayLength: Double, | ||
expectedLabels: List<String>, | ||
spatialReference: SpatialReference = SpatialReference.webMercator(), | ||
useGeodeticCalculations: Boolean = true, | ||
) { | ||
composeTestRule.setContent { | ||
|
||
val viewpoint = Viewpoint( | ||
center = Point( | ||
x = point.x, | ||
y = point.y, | ||
spatialReference = spatialReference | ||
), | ||
scale = scale | ||
) | ||
|
||
val scalebarProperties = calculateScalebarProperties( | ||
minScale = 0.0, | ||
useGeodeticCalculations = useGeodeticCalculations, | ||
scalebarUnits = units, | ||
spatialReference = spatialReference, | ||
viewpoint = viewpoint, | ||
unitsPerDip = unitsPerDip, | ||
maxDisplayLength = maxWidth, | ||
) | ||
val minSegmentWidth = measureMinSegmentWidth( | ||
scalebarLineLength = scalebarProperties?.lineLength ?: 0.0, | ||
labelTypography = labelTypography, | ||
) | ||
val scalebarLabels = generateScalebarLabels( | ||
minSegmentWidth = minSegmentWidth, | ||
displayLength = scalebarProperties?.displayLength ?: 0.0, | ||
scalebarLineLength = scalebarProperties?.lineLength ?: 0.0, | ||
displayUnit = scalebarProperties?.displayUnit, | ||
style = style, | ||
labelTypography = labelTypography, | ||
) | ||
|
||
assertThat(scalebarProperties?.displayLength).isWithin(.5).of(expectedDisplayLength) | ||
assertThat(scalebarLabels.size).isEqualTo(expectedLabels.size) | ||
for (i in expectedLabels.indices) { | ||
assertThat(scalebarLabels[i].label).isEqualTo(expectedLabels[i]) | ||
} | ||
} | ||
} | ||
} |
This file contains 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
161 changes: 0 additions & 161 deletions
161
...t/scalebar/src/androidTest/java/com/arcgismaps/toolkit/scalebar/ScalebarViewModelTests.kt
This file was deleted.
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.
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.
this should just be
maxWidth
as the user is only concerned with what is shown on the display. From the user perspective there is only the width of the Scalebar being shown on the screen. I think this should simply bemaxWidth