Skip to content
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

feat: wiggle and silhouette stacks #751

Merged
merged 30 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1e21b8d
refactor: remove unnecessary code
markov00 Jul 15, 2020
a40fcc7
refactor: code cleanup on series counts
markov00 Jul 15, 2020
4240a01
refactor: remove scaleToExtent from format
markov00 Jul 16, 2020
d3d9b61
Merge branch 'master' into 2020_07_15-stack_mode
markov00 Jul 16, 2020
6220e49
refactor: add d3 stack order and stack mode on stacked charts
markov00 Jul 22, 2020
11b2abe
Merge branch 'master' into 2020_07_15-stack_mode
markov00 Jul 22, 2020
2b73892
docs: update API signature
markov00 Jul 23, 2020
cbb1ccd
refactor: fix typings
markov00 Jul 23, 2020
bb2191f
feat: add various stackModes to bar and area charts
markov00 Jul 23, 2020
57cca57
fix: add streamgraph example and fix few screenshots
markov00 Jul 27, 2020
434e225
fix: fitting function should respect new datum format
markov00 Jul 28, 2020
5d0072f
test: update screenshot tests
markov00 Jul 28, 2020
e7ced6c
Merge branch 'master' into 2020_07_15-stack_mode
markov00 Jul 28, 2020
2af6f80
refactor: reset playground to its default
markov00 Jul 28, 2020
d35f124
test: unskip test
markov00 Jul 28, 2020
4028d7c
refactor: rename file
markov00 Jul 28, 2020
3f3e5cd
refactor: moved new data sample to datasample folder
markov00 Jul 28, 2020
6c2b913
test: cleanup tests
markov00 Jul 28, 2020
fdb00ea
refactor: rename StackModes to StackMode
markov00 Jul 28, 2020
259efec
test: update screenshot based on StackMode name change
markov00 Jul 28, 2020
aff9ecd
test: update last two screenshots
markov00 Jul 28, 2020
6919182
refactor: remove comments and cleanup code
markov00 Jul 29, 2020
3d99441
refactor: add comments on getDatumYValue
markov00 Jul 29, 2020
5a8b6a0
refactor: hasOffsetDifferentThanZero fn rename
markov00 Jul 29, 2020
63b29a6
test: add storybook test for fitted stacked charts
markov00 Jul 29, 2020
7e50ea1
test: remove unused knob from story
markov00 Jul 29, 2020
0517701
refactor: rollback changes to playground
markov00 Jul 29, 2020
df312fd
refactor: align clipping ranges on line and areas
markov00 Jul 29, 2020
af500d8
refactor: dry up some code
markov00 Jul 29, 2020
0a39b18
test: remove unnecessary test
markov00 Jul 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions .playground/data.ts

This file was deleted.

4 changes: 2 additions & 2 deletions .playground/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
/*display: inline-block;
position: relative;
*/
width: 800px;
height: 400px;
width: 500px;
height: 200px;
overflow: auto;
}

Expand Down
72 changes: 2 additions & 70 deletions .playground/playground.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
Expand All @@ -20,80 +19,13 @@

import React from 'react';

import { Chart, AreaSeries, Axis, Position, Settings, StackModes } from '../src';
import { Example } from '../stories/sunburst/15_single_sunburst';

export class Playground extends React.Component {
render() {
return (
<div className="testing">
<div className="chart">
<Chart>
<Settings showLegend showLegendExtra />

<Axis
id="y"
position={Position.Left}
/>
<Axis
id="x"
position={Position.Bottom}
// tickFormat={timeFormatter(niceTimeFormatByDay(365 * 10))}
/>

<AreaSeries
id="spec1"
// xAccessor="date"
// yAccessors={['count']}
// // y0Accessors={['metric0']}
// splitSeriesAccessors={['series']}
// stackAccessors={['date']}
// xScaleType={ScaleType.Time}
// fit={Fit.Lookahead}
// curve={CurveType.CURVE_MONOTONE_X}
// // areaSeriesStyle={{ point: { visible: true } }}
// // stackAsPercentage
// data={data.filter((d) => d.year !== 2006 || d.series !== 'Manufacturing')}
stackMode={StackModes.Percentage}
splitSeriesAccessors={['g']}
yAccessors={['y1']}
stackAccessors={['x']}
y0Accessors={['y0']}
data={[
{ x: 1, y0: 1, y1: 2, g: 'a' },
{ x: 2, y0: 2, y1: 2.5, g: 'a' },
{ x: 3, y0: 1, y1: 4, g: 'a' },
{ x: 4, y0: 1, y1: 2, g: 'a' },
{ x: 1, y0: 2, y1: 4, g: 'b' },
{ x: 2, y0: 2, y1: 5, g: 'b' },
{ x: 3, y0: 2, y1: 3, g: 'b' },
{ x: 4, y0: 2, y1: 5, g: 'b' },
]}
/>

{/* <AreaSeries
id="spec2"
yAccessors={['y1']}
splitSeriesAccessors={['g']}
// stackAccessors={['x']}
xScaleType={ScaleType.Linear}
fit={Fit.Carry}
areaSeriesStyle={{
point: {
visible: true,
},
}}
data={[
{ x: 1, y1: 1, g: 'a' },
{ x: 2, y1: 2, g: 'a' },
{ x: 3, y1: 2, g: 'a' },
{ x: 4, y1: 4, g: 'a' },
// { x: 1, y1: 21, g: 'b' },
// { x: 2, y1: 5, g: 'b' },
// { x: 3, y1: 23, g: 'b' },
]}
/> */}
</Chart>
</div>
<div className="chart">{Example()}</div>
</div>
);
}
Expand Down
16 changes: 12 additions & 4 deletions api/charts.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export type AreaSeriesSpec = BasicSeriesSpec & HistogramConfig & Postfixes & {
seriesType: typeof SeriesTypes.Area;
curve?: CurveType;
areaSeriesStyle?: RecursivePartial<AreaSeriesStyle>;
stackAsPercentage?: boolean;
stackMode?: StackMode;
pointStyleAccessor?: PointStyleAccessor;
fit?: Exclude<Fit, 'explicit'> | FitConfig;
};
Expand Down Expand Up @@ -208,7 +208,7 @@ export type BarSeriesSpec = BasicSeriesSpec & Postfixes & {
seriesType: typeof SeriesTypes.Bar;
enableHistogramMode?: boolean;
barSeriesStyle?: RecursivePartial<BarSeriesStyle>;
stackAsPercentage?: boolean;
stackMode?: StackMode;
styleAccessor?: BarStyleAccessor;
minBarHeight?: number;
};
Expand Down Expand Up @@ -1271,8 +1271,6 @@ export interface SeriesSpec extends Spec {
// @public (undocumented)
export type SeriesSpecs<S extends BasicSeriesSpec = BasicSeriesSpec> = Array<S>;

// Warning: (ae-missing-release-tag) "SeriesTypes" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export const SeriesTypes: Readonly<{
Area: "area";
Expand Down Expand Up @@ -1401,6 +1399,16 @@ export const SpecTypes: Readonly<{
// @public (undocumented)
export type SpecTypes = $Values<typeof SpecTypes>;

// @public
export const StackMode: Readonly<{
Percentage: "percentage";
Wiggle: "wiggle";
Silhouette: "silhouette";
}>;

// @public
export type StackMode = $Values<typeof StackMode>;

// @public
export interface StrokeDashArray {
dash: number[];
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
8 changes: 0 additions & 8 deletions integration/tests/area_stories.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ describe('Area series stories', () => {
it('should show correct extents - Banded', async() => {
await common.expectChartAtUrlToMatchScreenshot(trueUrl);
});

it('should show correct extents - stacked', async() => {
await common.expectChartAtUrlToMatchScreenshot(trueUrl);
});
});

describe('domain.fit is false', () => {
Expand All @@ -52,10 +48,6 @@ describe('Area series stories', () => {
it('should show correct extents - Banded', async() => {
await common.expectChartAtUrlToMatchScreenshot(falseUrl);
});

it('should show correct extents - stacked', async() => {
await common.expectChartAtUrlToMatchScreenshot(falseUrl);
});
});
});
});
6 changes: 3 additions & 3 deletions src/chart_types/xy_chart/domains/y_domain.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { SpecTypes } from '../../../specs/constants';
import { Position } from '../../../utils/commons';
import { BARCHART_1Y0G } from '../../../utils/data_samples/test_dataset';
import { computeSeriesDomainsSelector } from '../state/selectors/compute_series_domains';
import { BasicSeriesSpec, SeriesTypes, DEFAULT_GLOBAL_ID, StackModes } from '../utils/specs';
import { BasicSeriesSpec, SeriesTypes, DEFAULT_GLOBAL_ID, StackMode } from '../utils/specs';
import {
coerceYScaleTypes,
splitSpecsByGroupId,
Expand Down Expand Up @@ -486,7 +486,7 @@ describe('Y Domain', () => {
MockStore.addSpecs([
MockSeriesSpec.area({
...DEMO_AREA_SPEC_1,
stackMode: StackModes.Percentage,
stackMode: StackMode.Percentage,
}),
MockSeriesSpec.area({
...DEMO_AREA_SPEC_2,
Expand Down Expand Up @@ -517,7 +517,7 @@ describe('Y Domain', () => {
}),
MockSeriesSpec.area({
...DEMO_AREA_SPEC_1,
stackMode: StackModes.Percentage,
stackMode: StackMode.Percentage,
}),
], store);
const { yDomain } = computeSeriesDomainsSelector(store.getState());
Expand Down
10 changes: 5 additions & 5 deletions src/chart_types/xy_chart/domains/y_domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ import { GroupId } from '../../../utils/ids';
import { Logger } from '../../../utils/logger';
import { isCompleteBound, isLowerBound, isUpperBound } from '../utils/axis_type_utils';
import { DataSeries, FormattedDataSeries } from '../utils/series';
import { BasicSeriesSpec, YDomainRange, DEFAULT_GLOBAL_ID, SeriesTypes, StackModes } from '../utils/specs';
import { BasicSeriesSpec, YDomainRange, DEFAULT_GLOBAL_ID, SeriesTypes, StackMode } from '../utils/specs';
import { YDomain } from './types';

export type YBasicSeriesSpec = Pick<
BasicSeriesSpec,
'id' | 'seriesType' | 'yScaleType' | 'groupId' | 'stackAccessors' | 'yScaleToDataExtent' | 'useDefaultGroupDomain'
> & { stackMode?: StackModes; enableHistogramMode?: boolean };
> & { stackMode?: StackMode; enableHistogramMode?: boolean };

interface GroupSpecs {
stackMode?: StackModes;
stackMode?: StackMode;
stacked: YBasicSeriesSpec[];
nonStacked: YBasicSeriesSpec[];
}
Expand Down Expand Up @@ -102,7 +102,7 @@ function mergeYDomainForGroup(
const { stackMode } = groupSpecs;

let domain: number[];
if (stackMode === StackModes.Percentage) {
if (stackMode === StackMode.Percentage) {
domain = computeContinuousDataDomain([0, 1], identity, customDomain);
} else {
// TODO remove when removing yScaleToDataExtent
Expand Down Expand Up @@ -174,7 +174,7 @@ function computeYDomain(dataseries: DataSeries[], hasZeroBaselineSpecs: boolean)
export function splitSpecsByGroupId(specs: YBasicSeriesSpec[]) {
const specsByGroupIds = new Map<
GroupId,
{ stackMode: StackModes | undefined; stacked: YBasicSeriesSpec[]; nonStacked: YBasicSeriesSpec[] }
{ stackMode: StackMode | undefined; stacked: YBasicSeriesSpec[]; nonStacked: YBasicSeriesSpec[] }
>();
// After mobx->redux https://github.com/elastic/elastic-charts/pull/281 we keep the specs untouched on mount
// in MobX version, the stackAccessors was programmatically added to every histogram specs
Expand Down
6 changes: 3 additions & 3 deletions src/chart_types/xy_chart/rendering/rendering.areas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { LIGHT_THEME } from '../../../utils/themes/light_theme';
import { computeSeriesDomains } from '../state/utils/utils';
import { IndexedGeometryMap } from '../utils/indexed_geometry_map';
import { computeXScale, computeYScales } from '../utils/scales';
import { AreaSeriesSpec, SeriesTypes, StackModes } from '../utils/specs';
import { AreaSeriesSpec, SeriesTypes, StackMode } from '../utils/specs';
import { renderArea } from './rendering';

const SPEC_ID = 'spec_1';
Expand Down Expand Up @@ -1136,7 +1136,7 @@ describe('Rendering points - areas', () => {
xScaleType: ScaleType.Time,
yScaleType: ScaleType.Linear,
stackAccessors: [0],
stackMode: StackModes.Percentage,
stackMode: StackMode.Percentage,
});
const pointSeriesSpec2: AreaSeriesSpec = MockSeriesSpec.area({
id: 'spec_2',
Expand All @@ -1149,7 +1149,7 @@ describe('Rendering points - areas', () => {
xScaleType: ScaleType.Time,
yScaleType: ScaleType.Linear,
stackAccessors: [0],
stackMode: StackModes.Percentage,
stackMode: StackMode.Percentage,
});
const pointSeriesDomains = computeSeriesDomains([pointSeriesSpec1, pointSeriesSpec2]);
expect(pointSeriesDomains.formattedDataSeries.stacked[0].dataSeries[0].data).toMatchObject([
Expand Down
2 changes: 1 addition & 1 deletion src/chart_types/xy_chart/rendering/rendering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ describe('Rendering utils', () => {
});
});

describe.skip('getClippedRanges', () => {
describe('getClippedRanges', () => {
markov00 marked this conversation as resolved.
Show resolved Hide resolved
const dataSeries = MockDataSeries.fitFunction({ shuffle: false });

const xScale = MockScale.default({
Expand Down
14 changes: 7 additions & 7 deletions src/chart_types/xy_chart/rendering/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { LegendItem } from '../../../commons/legend';
import { Scale } from '../../../scales';
import { ScaleType } from '../../../scales/constants';
import { isLogarithmicScale } from '../../../scales/types';
import { MarkBuffer, StackModes } from '../../../specs';
import { MarkBuffer, StackMode } from '../../../specs';
import { CanvasTextBBoxCalculator } from '../../../utils/bbox/canvas_text_bbox_calculator';
import { mergePartial, Color, getDistance } from '../../../utils/commons';
import { CurveType, getCurveFactory } from '../../../utils/curves';
Expand Down Expand Up @@ -172,7 +172,7 @@ function renderPoints(
markSizeOptions: MarkSizeOptions,
styleAccessor?: PointStyleAccessor,
spatial = false,
stackMode?: StackModes,
stackMode?: StackMode,
): {
pointGeometries: PointGeometry[];
indexedGeometryMap: IndexedGeometryMap;
Expand Down Expand Up @@ -223,9 +223,9 @@ function renderPoints(
// const hasY0 = hasY0Accessors && index === 0;
nickofthyme marked this conversation as resolved.
Show resolved Hide resolved
let originalY: null | number = null;
nickofthyme marked this conversation as resolved.
Show resolved Hide resolved
if (hasY0Accessors) {
originalY = stackMode === StackModes.Percentage ? (index === 0 ? y0 : y1) : (index === 0 ? initialY0 : initialY1);
originalY = stackMode === StackMode.Percentage ? (index === 0 ? y0 : y1) : (index === 0 ? initialY0 : initialY1);
} else {
originalY = stackMode === StackModes.Percentage ? (y1 - (y0 ?? 0)) : initialY1;
originalY = stackMode === StackMode.Percentage ? (y1 - (y0 ?? 0)) : initialY1;
}
// const originalY = hasY0Accessors && index === 0 ? initialY0 : initialY1;
nickofthyme marked this conversation as resolved.
Show resolved Hide resolved
const seriesIdentifier: XYChartSeriesIdentifier = {
Expand Down Expand Up @@ -280,7 +280,7 @@ export function renderBars(
displayValueSettings?: DisplayValueSpec,
styleAccessor?: BarStyleAccessor,
minBarHeight?: number,
stackMode?: StackModes,
stackMode?: StackMode,
): {
barGeometries: BarGeometry[];
indexedGeometryMap: IndexedGeometryMap;
Expand Down Expand Up @@ -351,7 +351,7 @@ export function renderBars(

const x = xScaled + xScale.bandwidth * orderIndex;
const width = xScale.bandwidth;
const originalY1Value = stackMode === StackModes.Percentage ? (y1 - (y0 ?? 0)) : initialY1;
const originalY1Value = stackMode === StackMode.Percentage ? (y1 - (y0 ?? 0)) : initialY1;
const formattedDisplayValue = displayValueSettings && displayValueSettings.valueFormatter
? displayValueSettings.valueFormatter(originalY1Value)
: undefined;
Expand Down Expand Up @@ -567,7 +567,7 @@ export function renderArea(
isStacked = false,
pointStyleAccessor?: PointStyleAccessor,
hasFit?: boolean,
stackMode?: StackModes
stackMode?: StackMode
): {
areaGeometry: AreaGeometry;
indexedGeometryMap: IndexedGeometryMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ Array [
},
],
"groupId": "group2",
"stackMode": undefined,
},
]
`;
Expand Down
8 changes: 4 additions & 4 deletions src/chart_types/xy_chart/state/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import {
isBubbleSeriesSpec,
YDomainRange,
SeriesTypes,
StackModes,
StackMode,
hasOffsetDifferentThanZero,
} from '../../utils/specs';
import { getSpecsById, getAxesSpecForSpecId } from './spec';
Expand Down Expand Up @@ -145,7 +145,7 @@ function getLastValues(formattedDataSeries: {
if (last !== null) {
let y0: null | number = last.initialY0;
let y1: null | number = last.initialY1;
if (stackMode === StackModes.Percentage) {
if (stackMode === StackMode.Percentage) {
y1 = (last.y1 ?? 0) - (last.y0 ?? 0);
nickofthyme marked this conversation as resolved.
Show resolved Hide resolved
y0 = last.y0;
}
Expand Down Expand Up @@ -357,7 +357,7 @@ export function computeSeriesGeometries(
chartTheme,
enableHistogramMode,
);
orderIndex = counts.barSeries > 0 ? orderIndex + counts.barSeries : orderIndex;
orderIndex = counts[SeriesTypes.Bar] > 0 ? orderIndex + counts[SeriesTypes.Bar] : orderIndex;

areas.push(...geometries.areas);
lines.push(...geometries.lines);
Expand Down Expand Up @@ -457,7 +457,7 @@ function renderGeometries(
axesSpecs: AxisSpec[],
chartTheme: Theme,
enableHistogramMode: boolean,
stackMode?: StackModes,
stackMode?: StackMode,
): {
points: PointGeometry[];
bars: BarGeometry[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24113,6 +24113,7 @@ Array [
},
],
"groupId": "group2",
"stackMode": undefined,
},
]
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { MockStore } from '../../../mocks/store';
import { ScaleType } from '../../../scales/constants';
import { computeSeriesDomainsSelector } from '../state/selectors/compute_series_domains';
import * as fitFunctionModule from './fit_function';
import * as testModule from './nonstacked_series_utils';
import * as testModule from './fit_function_utils';
import { Fit } from './specs';

const EMPTY_DATA_SET = MockSeriesSpec.area({
Expand Down
Loading