-
-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Bar chart custom value offset #4431
Open
bivant
wants to merge
13
commits into
ChartsOrg:master
Choose a base branch
from
bivant:BarChart_CustomValueOffset
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
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
Additionally add an option to fallback to the outside value placement in case of the internal placement logic of the bar values + too low height of the bar to fit in the value
…ndle position fallback for the top edge Rename fallback value placement parameter name to the "isDrawValueSideFlexible". Handle fallback value placement for the bars those reach top edge (was only for the bottom/zero line). Add new options to the demo bar controllers (BarChar, PositiveNegativeBarChar)
…ue colors Move the value display code to a function. Stacked bar chart: correct text color (was using a dataSet index instead of a bar index), enable new features in the demo controller
…ked and non-stacked bar chart
# Conflicts: # Source/Charts/Renderers/BarChartRenderer.swift
Seems like the reference images for the new tests need to be updated, that was done for existing tests in master already after the merge with 4.0 branch. |
# Conflicts: # Source/Charts/Renderers/BarChartRenderer.swift
# Conflicts: # Tests/ChartsTests/BarChartTests.swift # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testDefaultNotDrawValueAboveBarsFlexibleInvertColor_iOS_375_0_667_0@2x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testDefaultNotDrawValueAboveBarsFlexibleInvertColor_tvOS_1920_0_1080_0@1x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testDefaultNotDrawValueAboveBarsFlexibleSecondaryColor_iOS_375_0_667_0@2x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testDefaultNotDrawValueAboveBarsFlexibleSecondaryColor_tvOS_1920_0_1080_0@1x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/[email protected] # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testDefaultNotDrawValueAboveBarsFlexible_tvOS_1920_0_1080_0@1x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/[email protected] # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testDefaultValuesFlexibleSecondaryColor_tvOS_1920_0_1080_0@1x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/[email protected] # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/[email protected] # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/[email protected] # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testNegativeValuesFlexibleSecondaryColor_tvOS_1920_0_1080_0@1x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testNotDrawValueAboveBarsNegativeValuesFlexibleSecondaryColor_iOS_375_0_667_0@2x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testNotDrawValueAboveBarsNegativeValuesFlexibleSecondaryColor_tvOS_1920_0_1080_0@1x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/[email protected] # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/[email protected] # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/[email protected] # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testStackedAndRegularNegativeDrawValues_tvOS_1920_0_1080_0@1x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/[email protected] # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testStackedAndRegularPositiveDrawValues_tvOS_1920_0_1080_0@1x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/[email protected] # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testStackedAndRegularsDrawValuesFlexible_tvOS_1920_0_1080_0@1x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testStackedAndRegularsNotDrawValueAboveBarsFlexible_iOS_375_0_667_0@2x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testStackedAndRegularsNotDrawValueAboveBarsFlexible_tvOS_1920_0_1080_0@1x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testStackedAndStackSingleNegativeDrawValues_iOS_375_0_667_0@2x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testStackedAndStackSingleNegativeDrawValues_tvOS_1920_0_1080_0@1x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testStackedAndStackSinglePositiveDrawValues_iOS_375_0_667_0@2x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testStackedAndStackSinglePositiveDrawValues_tvOS_1920_0_1080_0@1x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testStackedAndStackSinglesDrawValueInvertColors_iOS_375_0_667_0@2x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testStackedAndStackSinglesDrawValueInvertColors_tvOS_1920_0_1080_0@1x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testStackedAndStackSinglesDrawValuesFlexible_iOS_375_0_667_0@2x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testStackedAndStackSinglesDrawValuesFlexible_tvOS_1920_0_1080_0@1x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testStackedAndStackSinglesNotDrawValueAboveBarsFlexibleInvertColors_iOS_375_0_667_0@2x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testStackedAndStackSinglesNotDrawValueAboveBarsFlexibleInvertColors_tvOS_1920_0_1080_0@1x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testStackedAndStackSinglesNotDrawValueAboveBarsFlexible_iOS_375_0_667_0@2x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testStackedAndStackSinglesNotDrawValueAboveBarsFlexible_tvOS_1920_0_1080_0@1x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/[email protected] # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/testStackedDrawValuesFlexibleInvertColors_tvOS_1920_0_1080_0@1x.png # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/[email protected] # Tests/ChartsTests/__Snapshots__x86__/BarChartTests/[email protected]
# Conflicts: # Source/Charts/Renderers/BarChartRenderer.swift
… into BarChart_CustomValueOffset # Conflicts: # Source/Charts/Renderers/BarChartRenderer.swift
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue Link 🔗
Vertical version the HorizontalBarChartView issue #124
Possibly (in future) #777
Goals ⚽
Scope: BarChart (no horizontal bar logic for now)
Add ability to specify custom value offset for a value label (prior value is 4.5, what is still true by default)
When was implementing this feature I faced with the issue with low bars - text was unreadable when it has the same color as the background. So secondary value colors were added. After that I realized that inverting the value text color would be more universal and require almost no additional logic (except stacked, but that was later), so added this feature also.
Although coloring logic can be a separate PR, I have no interest in it without custom/flexible value positioning, so please not send me to split it right away.
While I need a non-stacked version I saw that drawing logic is very similar to "single bar" so added support of the features to it as well.
Implementation Details 🚧
BarChartDataProvider (affecting BarChartView):
BarChartView
valuesOffset
for a value label has same default value as before (4.5).Setting a
isDrawValueSideFlexible
value resets the offset of vertical bars to zero as the padding is not needed because of the flexible positionChartBaseDataSet:
valueColorsSecondary
are applied for the values affected byisDrawValueSideFlexible
only.valueColorsAdjustment
in effect for all value labels in the chart if enabledTesting Details 🔍
Tried to add tests for all the edge cases I could think of: custom value offset, flexible positioning, colors inverting+secondary, combination of them. Stacked and non-stacked versions.