Skip to content

Commit

Permalink
feat: add area chart demo
Browse files Browse the repository at this point in the history
  • Loading branch information
El-Chiang committed Oct 27, 2021
1 parent 0bfd5dd commit b9c5209
Show file tree
Hide file tree
Showing 2 changed files with 714 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/f2-next/src/components/area/withArea.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ export default (View) => {
}

parsePoints(dataArray) {
const { coord } = this.props;
// 1. 添加 points
const withPoints = dataArray.map((data) => {
const points = data;
if (coord.isPolar) {
points.push(data[0]);
}
const lineStyle = this.mergeStyle(data[0]);
return {
...lineStyle,
Expand Down Expand Up @@ -63,18 +67,21 @@ export default (View) => {
_generatePolygonPoints(mappedArray) {
const y0 = this.getY0Value();
const { coord } = this.props;
// 零点映射到绝对坐标
const p = coord.convertPoint({ x: 0, y: y0 });
// 如果 startOnZero,则取 yStart 坐标,否则取零点 y 坐标
const y = this.props.startOnZero ? coord.y[0] : p.y;
each(mappedArray, function (obj) {
const { dataArray } = obj;
if (dataArray?.length) {
each(dataArray, function (data) {
const start = {
x: data[0].x,
y: p.y,
y,
};
const end = {
x: data[data.length - 1].x,
y: p.y,
y,
};
// 插入头尾坐标
data.unshift(start);
Expand All @@ -86,6 +93,7 @@ export default (View) => {
return mappedArray;
}

// TODO: smooth
render() {
const { props } = this;
const mapped = this.mapping();
Expand Down
Loading

0 comments on commit b9c5209

Please sign in to comment.