Skip to content

Commit

Permalink
Merge pull request #3097 from VisActor/feat/player-api-changePlayerIndex
Browse files Browse the repository at this point in the history
feat: add `changePlayerIndex` API into player component
  • Loading branch information
xile611 authored Aug 20, 2024
2 parents 3236b25 + a89ce77 commit df6ff91
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions packages/vchart/src/component/player/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,21 @@ export class Player extends BaseComponent<IPlayer> implements IComponent {
return 0;
};

changePlayerIndex(index: number) {
const spec = this._specs[index];
(array(spec.data) as IDataValues[]).forEach(data => {
this._option?.globalInstance?.updateData(data.id, data.values);
});
this.event.emit(ChartEvent.playerChange, {
model: this,
value: {
spec: spec,
index: index,
specs: this._specs
}
});
}

/**
* 事件
*/
Expand Down Expand Up @@ -361,19 +376,7 @@ export class Player extends BaseComponent<IPlayer> implements IComponent {
this._playerComponent.addEventListener(PlayerEventEnum.change, (e: { detail: { index: number } }) => {
// 更新data
const { index } = e.detail;
const spec = this._specs[index];
(array(spec.data) as IDataValues[]).forEach(data => {
this._option?.globalInstance?.updateData(data.id, data.values);
});

this.event.emit(ChartEvent.playerChange, {
model: this,
value: {
spec: spec,
index: index,
specs: this._specs
}
});
this.changePlayerIndex(index);
});

// 后退
Expand Down

0 comments on commit df6ff91

Please sign in to comment.