Skip to content

Commit 950cadb

Browse files
author
jiangtao.yang
committed
feat: add reverse
1 parent ce78338 commit 950cadb

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

apps/dsv/src/Chart.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const Chart: FC = () => {
2121
}
2222
const arrayBar = new ArrayBar<number>([...schema.structures[0].array], {
2323
id: schema.structures[0].id,
24-
interval: 300,
24+
interval: 1000,
2525
structure: {},
2626
});
2727
schema.actions.forEach((action) => {
@@ -35,6 +35,9 @@ export const Chart: FC = () => {
3535
if (action.type === 'appear') {
3636
arrayBar.appear();
3737
}
38+
if (action.type === 'reverse') {
39+
arrayBar.reverse();
40+
}
3841
}
3942
});
4043

packages/data-structure/src/data-structures/array-bar/array-bar.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,30 @@ export class ArrayBar<T> {
106106
});
107107
}
108108

109+
reverse() {
110+
this._data = this._data.reverse();
111+
const id = this._id;
112+
const dataId = this._dataId;
113+
const interval = this._interval;
114+
const length = this._actions.length;
115+
const action = {
116+
action: "update",
117+
startTime: interval * length,
118+
payload: {
119+
id: dataId,
120+
animation: {
121+
duration: interval,
122+
},
123+
values: cloneDeep(this._data),
124+
},
125+
};
126+
this._actions.push({
127+
characterId: id,
128+
characterActions: [action],
129+
});
130+
return this;
131+
}
132+
109133
appear() {
110134
this._actions.push({
111135
characterId: this._id,

0 commit comments

Comments
 (0)