Skip to content

Commit

Permalink
feat: 优化更新逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
zengyue committed Sep 24, 2021
1 parent 1ead15f commit 9e68a77
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 12 deletions.
3 changes: 2 additions & 1 deletion packages/f2-next/src/canvas/animation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Animation {
return new Animator(element, animation);
}

play(container) {
play(container, onAnimationEnd) {
const { canvas } = this;
const animators: Animator[] = [];
let maxDuration = 0;
Expand Down Expand Up @@ -95,6 +95,7 @@ class Animation {
element.remove(true);
}
canvas.draw();
onAnimationEnd && onAnimationEnd();
})
}

Expand Down
12 changes: 7 additions & 5 deletions packages/f2-next/src/canvas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ class Canvas extends Component implements IF2Canvas {
}

draw() {
const { canvas, container, animation } = this;
const { canvas, container, animation, props } = this;
const { onAnimationEnd } = props;
// 执行动画
if (animation) {
animation.abort();
animation.play(container);
animation.play(container, onAnimationEnd);
} else {
canvas.draw();
}
Expand All @@ -125,9 +126,10 @@ class Canvas extends Component implements IF2Canvas {

const componentTree = createComponentTree(children, { canvas: this, width, height, context, layout });

if (equal(this.componentTree, componentTree)) {
return;
}

// if (equal(this.componentTree, componentTree)) {
// return;
// }

component.update({ children: componentTree });
this.render();
Expand Down
4 changes: 3 additions & 1 deletion packages/f2-next/src/chart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,6 @@ class Chart extends Container implements IChart, ThemeMixin, CoordMixin, ScaleMi
// 多继承
applyMixins(Chart, [ ThemeMixin, CoordMixin, ScaleMixin ]);

export default Chart;
class ExportChart extends Chart {}

export default ExportChart;
8 changes: 6 additions & 2 deletions packages/f2-next/src/components/guide/withGuide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default (View) => {
canvas.on("click", (ev) => {
const { points } = ev;
const shape = this.triggerRef.current;
if (!shape) return;
if (!shape || shape.isDestroyed()) return;
const bbox = shape.getBBox();
if (isInBBox(bbox, points[0])) {
ev.shape = shape;
Expand Down Expand Up @@ -81,6 +81,10 @@ export default (View) => {
return coord.convertPoint({ x, y });
}

convertPoints(records) {
return records.map((record) => this.parsePoint(record));
}

getGuideTheme() {
const { theme } = this.chart;
return theme['guide'];
Expand All @@ -90,7 +94,7 @@ export default (View) => {
const { props, chart } = this;
const { records = [] } = props;
const { coord } = chart;
const points = records.map((record) => this.parsePoint(record));
const points = this.convertPoints(records);
const theme = this.getGuideTheme();

return <View
Expand Down
1 change: 1 addition & 0 deletions packages/f2-next/src/coord/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Base extends Layout {
x: left + (width / 2),
y: top + (height / 2),
};
return this;
}

// 是循环, 比如极坐标是以 2π 循环的
Expand Down
1 change: 1 addition & 0 deletions packages/f2-next/src/coord/polar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Polar extends Base {

this.x = x;
this.y = y;
return this;
}

isCyclic() {
Expand Down
1 change: 1 addition & 0 deletions packages/f2-next/src/coord/rect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Rect extends Base {

this.x = x;
this.y = y;
return this;
}

convertPoint(point) {
Expand Down
6 changes: 3 additions & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@ali/f2x-react",
"version": "0.2.7",
"name": "@ali/f2next-react",
"version": "0.0.1",
"main": "lib/index.js",
"module": "es/index.js",
"types": "es/index.d.ts",
"dependencies": {
"@ali/f2-next": "^0.0.1",
"@ali/f2-next": "*",
"@babel/runtime": "^7.12.5"
},
"devDependencies": {
Expand Down

0 comments on commit 9e68a77

Please sign in to comment.