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: add band area chart #157

Merged
merged 11 commits into from
Apr 11, 2019
24 changes: 15 additions & 9 deletions src/components/highlighter.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { inject, observer } from 'mobx-react';
import React from 'react';
import { isPointGeometry } from '../lib/series/rendering';
import { ChartStore } from '../state/chart_state';

interface HighlighterProps {
Expand All @@ -21,26 +22,31 @@ class HighlighterComponent extends React.Component<HighlighterProps> {
return (
<svg className="elasticChartsHighlighter">
<g transform={`translate(${left}, ${top}) rotate(${chartRotation})`}>
{highlightedGeometries.map((highlightedGeometry, i) => {
const {
color,
geom: { x, y, width, height, isPoint },
} = highlightedGeometry;
if (isPoint) {
{highlightedGeometries.map((geom, i) => {
const { color, x, y } = geom;
if (isPointGeometry(geom)) {
return (
<circle
key={i}
cx={x}
cx={x + geom.transform.x}
cy={y}
r={width}
r={geom.radius}
stroke={color}
strokeWidth={4}
fill="transparent"
/>
);
}
return (
<rect key={i} x={x} y={y} width={width} height={height} fill="white" opacity={0.4} />
<rect
key={i}
x={x}
y={y}
width={geom.width}
height={geom.height}
fill="white"
opacity={0.4}
/>
);
})}
</g>
Expand Down
59 changes: 32 additions & 27 deletions src/components/react_canvas/area_geometries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class AreaGeometries extends React.PureComponent<
return (
<Group ref={this.barSeriesRef} key={'bar_series'}>
{area.visible && this.renderAreaGeoms()}
{line.visible && this.renderAreaLine()}
{line.visible && this.renderAreaLines()}
{point.visible && this.renderAreaPoints()}
</Group>
);
Expand Down Expand Up @@ -132,46 +132,51 @@ export class AreaGeometries extends React.PureComponent<
}
});
}
private renderAreaLine = (): JSX.Element[] => {
private renderAreaLines = (): JSX.Element[] => {
const { areas, sharedStyle } = this.props;
const { strokeWidth } = this.props.style.line;

return areas.map((glyph, i) => {
const { line, color, transform, geometryId } = glyph;
const linesToRender: JSX.Element[] = [];
areas.forEach((glyph, areaIndex) => {
const { lines, color, geometryId } = glyph;

const geometryStyle = getGeometryStyle(
geometryId,
this.props.highlightedLegendItem,
sharedStyle,
);

if (this.props.animated) {
return (
<Group key={`area-line-group-${i}`} x={transform.x}>
<Spring native from={{ line }} to={{ line }}>
{(props: { line: string }) => {
const lineProps = buildAreaLineProps({
index: i,
linePath: props.line,
color,
strokeWidth,
geometryStyle,
});
return <animated.Path {...lineProps} />;
}}
</Spring>
</Group>
);
} else {
lines.forEach((linePath, lineIndex) => {
const lineProps = buildAreaLineProps({
index: i,
linePath: line,
areaIndex,
lineIndex,
linePath,
color,
strokeWidth,
geometryStyle,
});
return <Path {...lineProps} />;
}
linesToRender.push(<Path {...lineProps} />);
});
});
return linesToRender;
// if (this.props.animated) {
// return (
// <Group key={`area-line-group-${i}`} x={transform.x}>
// <Spring native from={{ line }} to={{ line }}>
// {(props: { line: string }) => {
// const lineProps = buildAreaLineProps({
// index: i,
// linePath: props.line,
// color,
// strokeWidth,
// geometryStyle,
// });
// return <animated.Path {...lineProps} />;
// }}
// </Spring>
// </Group>
// );
// } else {

// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ describe('[canvas] Area Geometries props', () => {
});
test('can build area line path props', () => {
const props = buildAreaLineProps({
index: 1,
areaIndex: 1,
lineIndex: 2,
linePath: 'M0,0L10,10Z',
color: 'red',
strokeWidth: 1,
Expand All @@ -89,7 +90,7 @@ describe('[canvas] Area Geometries props', () => {
},
});
expect(props).toEqual({
key: `area-line-1`,
key: `area-1-line-2`,
data: 'M0,0L10,10Z',
stroke: 'red',
strokeWidth: 1,
Expand Down
8 changes: 5 additions & 3 deletions src/components/react_canvas/utils/rendering_props_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,22 @@ export function buildAreaProps({
}

export function buildAreaLineProps({
index,
areaIndex,
lineIndex,
linePath,
color,
strokeWidth,
geometryStyle,
}: {
index: number;
areaIndex: number;
lineIndex: number;
linePath: string;
color: string;
strokeWidth: number;
geometryStyle: GeometryStyle;
}) {
return {
key: `area-line-${index}`,
key: `area-${areaIndex}-line-${lineIndex}`,
data: linePath,
stroke: color,
strokeWidth,
Expand Down
Loading