fix(xy): stacked polarity#1502
Conversation
packages/charts/src/chart_types/xy_chart/utils/stacked_series_utils.ts
Outdated
Show resolved
Hide resolved
| "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.
what was the issue on upgrading to the latest version?
There was a problem hiding this comment.
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.
| 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.
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
| areaGeometry: AreaGeometry; | ||
| indexedGeometryMap: IndexedGeometryMap; | ||
| } { | ||
| const isBandChart = hasY0Accessors && !isStacked; |
There was a problem hiding this comment.
can we reuse isDataSeriesBanded here?
| const dataSeries = new Map<SeriesKey, DataSeries>(); | ||
| const xValues: Array<string | number> = []; | ||
| const nonNumericValues: any[] = []; | ||
| const hasStackedBands = isStacked && Boolean(y0Accessors?.length); |
| /> | ||
| </Chart> |
There was a problem hiding this comment.
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}
/>
| 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.
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.
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.
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:stackAccessorswithy0Accessors). Now showsconsole.warnwhen used and ignoresy0Accessorfor rendering but still adds toinitialY0value. See fix(xy): stacked polarity #1502 (comment).stackAccessorsare 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
y0ory1values that is no longer needed. This is handled by using they0series 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