Skip to content

Commit

Permalink
feat: add arrange demo, support line growPoint animate
Browse files Browse the repository at this point in the history
  • Loading branch information
neuqzxy committed Dec 24, 2024
1 parent e90489c commit 13135be
Show file tree
Hide file tree
Showing 23 changed files with 592 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vstory-animate",
"comment": "feat: add arrange demo, support line growPoint animate",
"type": "none"
}
],
"packageName": "@visactor/vstory-animate"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vstory-core",
"comment": "feat: add arrange demo, support line growPoint animate",
"type": "none"
}
],
"packageName": "@visactor/vstory-core"
}
13 changes: 11 additions & 2 deletions packages/vstory-core/src/core/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class StoryCanvas implements IStoryCanvas {
) {
this._story = story;
this._container = params.container;
this._canvas = params.canvas as any;

const {
canvas,
Expand Down Expand Up @@ -127,8 +128,16 @@ export class StoryCanvas implements IStoryCanvas {
if (!Number.isFinite(width) || !Number.isFinite(height)) {
scaleX = scaleY = 1;
} else {
const clipWidth = this._container ? this._container.clientWidth : this._canvas.width / this.getDpr();
const clipHeight = this._container ? this._container.clientHeight : this._canvas.height / this.getDpr();
const clipWidth = this._container
? this._container.clientWidth
: this._canvas?.width / vglobal.devicePixelRatio;
const clipHeight = this._container
? this._container.clientHeight
: this._canvas?.height / vglobal.devicePixelRatio;
if (!isValidNumber(clipWidth) || !isValidNumber(clipHeight)) {
scaleX = scaleY = 1;
return { scaleX, scaleY, width, height };
}

const clipAspectRatio = clipWidth / clipHeight;
const contentAspectRatio = width / height;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
import type VChart from '@visactor/vchart';
import { commonFade, commonGrow } from './commonTransformMarkAppear';
import type { IChartVisibilityPayload } from '../../interface';
import type { ICharacter } from '@visactor/vstory-core';
import { getCustomParams } from './utils';

export const growPoints = (
instance: VChart,
animation: IChartVisibilityPayload['animation'],
option: { markIndex: number; disappear: boolean; character?: ICharacter }
) => {
const { duration, oneByOne, easing } = getCustomParams(
animation,
animation.delayPerTime ?? 30,
animation.enterPerTime ?? 200
);
const { params = {} } = animation;
const { disappear, character } = option;
if (disappear || !character) {
return commonFade(instance, animation, option);
}

return {
type: params.direction === 'horizontal' ? 'growPointsXIn' : 'growPointsYIn',
options: {
orient: params.direction === 'horizontal' ? 'positive' : 'negative'
},
duration,
oneByOne,
easing
};
};

export const transformLineVisibility = (
instance: VChart,
Expand All @@ -14,6 +43,9 @@ export const transformLineVisibility = (
case 'fade': {
return commonFade(instance, animation, option);
}
case 'growPoints': {
return growPoints(instance, animation, option);
}
default: {
return commonFade(instance, animation, option);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vstory-player/src/processor/chart/visibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class VChartVisibilityActionProcessor extends VChartBaseActionProcessor {
payload: IChartVisibilityPayload,
isRun: boolean
) {
const vrenderComponents = component.getVRenderComponents();
const vrenderComponents = component.getVRenderComponents().filter((item: any) => !!item);
const appearTransformFunc = transformMap.appear.legends;
const defaultPayload = VChartVisibilityActionProcessor.fadePayload;
vrenderComponents.forEach(group => {
Expand Down
10 changes: 10 additions & 0 deletions packages/vstory/demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import { MarketingWordcloud } from './demos/infographic/marking-wordcloud';
// VchartEditor Runtime
import { RuntimeSeriesMark } from './demos/runtime/series-mark';
import { RuntimeLabelStyle } from './demos/runtime/label-style';
import { LineChartArrange } from './demos/arrange/LineChart';
import { PieChart } from './demos/arrange/PieChart';

type MenusType = (
| {
Expand Down Expand Up @@ -99,6 +101,14 @@ const App = () => {
name: 'BarChart1',
component: BarChart1
},
{
name: 'LineChartArrange',
component: LineChartArrange
},
{
name: 'PieChart',
component: PieChart
},
{
name: 'BarChart2',
component: BarChart2
Expand Down
1 change: 1 addition & 0 deletions packages/vstory/demo/src/demos/API.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const API = () => {
useEffect(() => {
const container = document.getElementById(id);
const canvas = document.createElement('canvas');

container?.appendChild(canvas);

const story = new Story(null, { canvas, width: 800, height: 500, background: 'pink' });
Expand Down
8 changes: 4 additions & 4 deletions packages/vstory/demo/src/demos/arrange/BarChart2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,26 @@ export const BarChart2 = () => {
]
},
{
startTime: 2000,
startTime: 3000,
action: 'appear',
payload: [
{
selector: 'bar',
animation: {
duration: 2000,
duration: 800,
easing: 'linear'
}
}
]
},
{
startTime: 2000,
startTime: 3000,
action: 'appear',
payload: [
{
selector: '#axes-right',
animation: {
duration: 2000,
duration: 800,
easing: 'linear'
}
}
Expand Down
Loading

0 comments on commit 13135be

Please sign in to comment.