-
Notifications
You must be signed in to change notification settings - Fork 121
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
fix(xy): stacked polarity #1502
Conversation
packages/charts/src/chart_types/xy_chart/utils/stacked_series_utils.ts
Outdated
Show resolved
Hide resolved
@@ -40,7 +40,7 @@ | |||
"d3-collection": "^1.0.7", | |||
"d3-interpolate": "^1.4.0", | |||
"d3-scale": "^1.0.7", | |||
"d3-shape": "^1.3.4", | |||
"d3-shape": "^2.0.0", |
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.
what was the issue on upgrading to the latest version?
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.
The jest tests were throwing an error similar to https://stackoverflow.com/questions/49263429/jest-gives-an-error-syntaxerror-unexpected-token-export. I tried to fix it but couldn't see any difference between the 2 so I gave up for now.
@@ -111,7 +112,7 @@ export function computeLegend( | |||
|
|||
dataSeries.forEach((series) => { | |||
const { specId, yAccessor } = series; | |||
const banded = isDataSeriesBanded(series); | |||
const banded = isDataSeriesBanded(series) && !isStackedSpec(series.spec, false); |
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.
since isDataSeriesBanded
is only used here and it name is really specific we can probably include the non-stacked
check within that function so we have a clear and specific definition of what banded mean
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.
@@ -47,6 +47,7 @@ export function renderArea( | |||
areaGeometry: AreaGeometry; | |||
indexedGeometryMap: IndexedGeometryMap; | |||
} { | |||
const isBandChart = hasY0Accessors && !isStacked; |
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.
can we reuse isDataSeriesBanded
here?
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.
@@ -130,6 +130,13 @@ export function splitSeriesDataByAccessors( | |||
const dataSeries = new Map<SeriesKey, DataSeries>(); | |||
const xValues: Array<string | number> = []; | |||
const nonNumericValues: any[] = []; | |||
const hasStackedBands = isStacked && Boolean(y0Accessors?.length); |
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.
reuse isDataSeriesBanded
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.
/> | ||
</Chart> |
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.
If you add a zero baseline it will look better in some cases:
<LineAnnotation
id="zeroBaseline"
domainType={AnnotationDomainType.YDomain}
dataValues={[{ dataValue: 0 }]}
style={{ line: { ...baseTheme.axes.axisLine, opacity: 1 } }}
zIndex={-1}
/>
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.
const polarity = select('data polarity', ['Mixed', 'Positive', 'Negative'], 'Mixed'); | ||
const customDomain = boolean('custom domain', false); | ||
const stackMode = | ||
select<StackMode | undefined>( | ||
'stackMode', | ||
{ | ||
None: undefined, | ||
Silhouette: StackMode.Silhouette, | ||
Wiggle: StackMode.Wiggle, | ||
Percentage: StackMode.Percentage, | ||
}, | ||
undefined, | ||
) ?? undefined; | ||
const [Series] = getXYSeriesKnob('SeriesType', SeriesType.Bar, undefined, { | ||
ignore: [SeriesType.Bubble, SeriesType.Line], | ||
}); |
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.
Area chart with mixed polarity values is not a good practice. Adding a warning on the console or as a text below the example can be useful.
I'm also not sure if it is worth having such cases in VRTs
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.
A warning is good. I added the VRT thinking we could fix this in the future with the split series we had discussed. If you think that is not going to happen I can remove the case for mixed polarity stacked areas.
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.
Added the warning in f06db8a. I'll keep the vrt for mixed area for now and we can decide if/when to support that later.
# [40.2.0](v40.1.0...v40.2.0) (2021-12-09) ### Bug Fixes * **partition:** linkLabel textColor override ([#1498](#1498)) ([3013310](3013310)) * **waffle:** use descend sortPredicate by default ([#1510](#1510)) ([763e2e3](763e2e3)) * **xy:** stacked polarity ([#1502](#1502)) ([920666a](920666a)), closes [#1280](#1280) ### Features * **xy:** expose style for interpolation fit functions ([#1505](#1505)) ([3071457](3071457))
Resolves issue with stacking a mix of negative and positive bars and areas for any `StackMode`. Key changes include: - Disallowing stacked band charts (i.e. using `stackAccessors` with `y0Accessors`). Now shows `console.warn` when used and ignores `y0Accessor` for rendering but still adds to `initialY0` value. - Blocks showing banded legend and tooltip values for banded stacks, see case above. - Prevents percentage domain constraining when no `stackAccessors` are specified. fix elastic#1280 # Conflicts: # packages/charts/src/chart_types/xy_chart/rendering/area.ts
Resolves issue with stacking a mix of negative and positive bars and areas for any `StackMode`. Key changes include: - Disallowing stacked band charts (i.e. using `stackAccessors` with `y0Accessors`). Now shows `console.warn` when used and ignores `y0Accessor` for rendering but still adds to `initialY0` value. - Blocks showing banded legend and tooltip values for banded stacks, see case above. - Prevents percentage domain constraining when no `stackAccessors` are specified. fix #1280
Resolves issue with stacking a mix of negative and positive bars and areas for any `StackMode`. Key changes include: - Disallowing stacked band charts (i.e. using `stackAccessors` with `y0Accessors`). Now shows `console.warn` when used and ignores `y0Accessor` for rendering but still adds to `initialY0` value. - Blocks showing banded legend and tooltip values for banded stacks, see case above. - Prevents percentage domain constraining when no `stackAccessors` are specified. fix elastic#1280 # Conflicts: # integration/tests/__image_snapshots__/axis-stories-test-ts-axis-stories-should-switch-to-a-30-minute-raster-1-snap.png # packages/charts/src/chart_types/xy_chart/rendering/area.ts # packages/charts/src/chart_types/xy_chart/utils/stacked_series_utils.ts
Summary
Resolves issue with stacking a mix of negative and positive bars and areas for any
StackMode
. Key changes include:stackAccessors
withy0Accessors
). Now showsconsole.warn
when used and ignoresy0Accessor
for rendering but still adds toinitialY0
value. See fix(xy): stacked polarity #1502 (comment).stackAccessors
are specified, see fix(xy): stacked polarity #1502 (comment)No offset
Wiggle offset
Silhouette offset
Percentage offset
Details
Stacked offsets was implemented to be grouped by series. This creates issues when attempting to sort values differently based on their polarity for a given x value grouping. Thus this logic has been changed to group and stack by x values as demonstrated in this example, which allows for using
d3.stackOffsetDiverging
.Additionally, the logic had an intermediate step to group by
y0
ory1
values that is no longer needed. This is handled by using they0
series as a placeholder during stacking and ignoring it when structuring the final geometry data. Though not advisable to stack when usingy0Accessors
.Issues
fix #1280
Checklist
:xy
,:partition
):interactions
,:axis
)closes #123
,fixes #123
)packages/charts/src/index.ts