Skip to content

Commit

Permalink
refactor: remove comments and cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
markov00 committed Jul 29, 2020
1 parent aff9ecd commit 6919182
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 38 deletions.
30 changes: 21 additions & 9 deletions src/chart_types/xy_chart/rendering/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function renderPoints(
: () => 0;
const geometryType = spatial ? GeometryType.spatial : GeometryType.linear;
const pointGeometries = dataSeries.data.reduce((acc, datum) => {
const { x: xValue, y0, y1, initialY0, initialY1, filled, mark } = datum;
const { x: xValue, y0, y1, filled, mark } = datum;
// don't create the point if not within the xScale domain
if (!xScale.isValueInDomain(xValue)) {
return acc;
Expand Down Expand Up @@ -220,14 +220,7 @@ function renderPoints(
if (y === null) {
return acc;
}
// const hasY0 = hasY0Accessors && index === 0;
let originalY: null | number = null;
if (hasY0Accessors) {
originalY = stackMode === StackMode.Percentage ? (index === 0 ? y0 : y1) : (index === 0 ? initialY0 : initialY1);
} else {
originalY = stackMode === StackMode.Percentage ? (y1 - (y0 ?? 0)) : initialY1;
}
// const originalY = hasY0Accessors && index === 0 ? initialY0 : initialY1;
const originalY = getDatumYValue(datum, index, hasY0Accessors, stackMode);

This comment has been minimized.

Copy link
@nickofthyme

nickofthyme Jul 29, 2020

Collaborator

You read my mind....I was going to suggest this

const seriesIdentifier: XYChartSeriesIdentifier = {
key: dataSeries.key,
specId: dataSeries.specId,
Expand Down Expand Up @@ -269,6 +262,25 @@ function renderPoints(
};
}

function getDatumYValue(
{ y1, y0, initialY1, initialY0 }: DataSeriesDatum,
index: number,
hasY0Accessors: boolean,
stackMode?: StackMode
) {
if (hasY0Accessors) {
return stackMode === StackMode.Percentage
? (index === 0
? y0
: y1)
: (index === 0
? initialY0
: initialY1);
}
return stackMode === StackMode.Percentage ? (y1 ?? 0) - (y0 ?? 0) : initialY1;
}


/** @internal */
export function renderBars(
orderIndex: number,
Expand Down
2 changes: 0 additions & 2 deletions src/chart_types/xy_chart/utils/fit_function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ export const fitFunction = (
return data;
}

// const { data } = dataSeries;

if (type === Fit.Zero) {
return data.map((datum) => ({
...datum,
Expand Down
27 changes: 0 additions & 27 deletions src/chart_types/xy_chart/utils/series.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,33 +203,6 @@ describe('Series', () => {
],
}), store);
const { formattedDataSeries: { stacked } } = computeSeriesDomainsSelector(store.getState());
// const dataSeries: DataSeries[] = [
// {
// specId: 'spec1',
// yAccessor: 'y1',
// splitAccessors: new Map(),
// seriesKeys: ['a'],
// key: 'a',
// data: [
// { x: 1, y1: 1, mark: null, y0: null, initialY1: 1, initialY0: null, datum: undefined },
// { x: 4, y1: 4, mark: null, y0: null, initialY1: 4, initialY0: null, datum: undefined },
// { x: 2, y1: 2, mark: null, y0: null, initialY1: 2, initialY0: null, datum: undefined },
// ],
// },
// {
// specId: 'spec1',
// yAccessor: 'y1',
// splitAccessors: new Map(),
// seriesKeys: ['b'],
// key: 'b',
// data: [
// { x: 3, y1: 23, mark: null, y0: null, initialY1: 23, initialY0: null, datum: undefined },
// { x: 1, y1: 21, mark: null, y0: null, initialY1: 21, initialY0: null, datum: undefined },
// ],
// },
// ];
// const xValues = new Set([1, 2, 3, 4]);
// const stackedValues = formatStackedDataSeriesValues(dataSeries, xValues);

expect(stacked[0].dataSeries).toMatchSnapshot();
});
Expand Down

0 comments on commit 6919182

Please sign in to comment.