Fix default colors for stacked bars #118
Open
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.
This addresses #101 .
Summary
Within stacked bar charts, each stack was being reversed, which resulted in the colors being reversed in that stack if the default colors were used. I removed the
List.reverse
and updated the downstream code to work correctly with the adjusted indexes.Research Details
I determined that the
List.reverse
was being used in order to make each bar have the "correct"sectionIndex
in thetoBarItem
function. Thus, if thetoBarItem
function could be updated to use the original indexes (instead of the reversed indexes), then theList.reverse
could be removed and the colors would be automatically fixed.Q: What does
toBarItem
usesectionIndex
for? A:toBarItem
usessectionIndex
in three ways:section.extra
to determine the final visual attributes to apply to the item.config.tooltipInfo
in theI.Rendered
value that this function returns.Usage 1 is safe to update as long as we simply swap which condition we consider to be the "top" and which the "bottom". I have done this and changed the helper values to be named
isTop
/isBottom
instead ofisFirst
/isLast
.For usages 2 and 3, it does not actually matter what the index is for each item, as long as these two usages match. To support this claim:
First sub-claim: Usage 2 will not cause any problems as long as usage 3 is in sync.
extra
field is part of theConfig
data type, from theInternal.Property
module. It is a function that takes quite a few things and returns a list of visual modifications to make.Internal.Property.property
.Internal.Property.variation
function.Internal.Property
module is not exposed to library users; thus, as long asInternal.Property.variation
is not exposed to users by public modules or used in a way that cares about the index, then it is safe.Internal.Property.variation
function is only used byChart.variation
andChart.amongst
.Chart.variation
adds a function that ignores thesectionIndex
Chart.amongst
adds a function that uses thesectionIndex
, but only to compare to the value fromItem.getStackIndex
.Item.getStackIndex
gets theconfig.tooltipInfo.stack
value, which is the exact value that usage 3 is writing.sectionIndex
as long as usage 3 is also updated.Second sub-claim: Usage 3 will not cause any problems as long as usage 2 is in sync.
config.tooltipInfo.stack
value is not exposed to library users, and thus this is safe as long as internal library usage is safe.config.tooltipInfo.stack
value is only used by theInternal.Item.getStackIndex
function.Internal.Item.getStackIndex
function is only used byInternal.Item.isSame
andChart.amongst
functionsInternal.Item.isSame
is checking for equality between two values. This is safe for the update that we want to make.Chart.amongst
is the same function that we examined above, and is safe as long as Usage 2 is updated to be in sync because it is doing equality comparison.In conclusion, the index that was being modified by the
List.reverse
call (stackIndex
) was being used in three ways. One required us to make a small local change, which was made. The other two do not require any changes. Once theList.reverse
is removed, the default colors start working automatically.