Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@visactor/vrender-components",
"comment": "feat: arc markpoint support animation. close VisAct",
"type": "none"
}
],
"packageName": "@visactor/vrender-components"
}
43 changes: 41 additions & 2 deletions packages/vrender-components/__tests__/unit/marker/point.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { Group, IGraphic, Stage } from '@visactor/vrender-core';
import type { Tag, Segment } from '../../../src';
import { MarkPoint } from '../../../src';
import type { ArcSegment, Tag, Segment } from '../../../src';
import { MarkPoint, registerMarkPointAnimate } from '../../../src';
import { createCanvas } from '../../util/dom';
import { createStage } from '../../util/vrender';
import { initBrowserEnv } from '@visactor/vrender-kits';
initBrowserEnv();
registerMarkPointAnimate();

describe('Marker', () => {
let stage: Stage;
Expand Down Expand Up @@ -67,4 +68,42 @@ describe('Marker', () => {
.text
).toBe('mark point label text');
});

it('MarkPoint arc line callIn animation', () => {
const markPoint = new MarkPoint({
position: {
x: 100,
y: 250
},
itemLine: {
type: 'type-arc',
arcRatio: 0.8
},
itemContent: {
type: 'text',
offsetX: 100,
offsetY: 30,
style: {
text: 'mark point arc label text',
panel: {
visible: true
}
}
},
animationEnter: {
type: 'callIn',
duration: 500,
easing: 'linear'
}
});
stage.defaultLayer.add(markPoint as unknown as IGraphic);
stage.render();

const markPointContainer = markPoint.children[0] as unknown as Group;
const line = markPointContainer.children[0] as unknown as ArcSegment;

expect(line.key).toBe('arc-segment');
expect(line.line?.attribute.clipRange).toBe(0);
expect(line.line?.animates?.size).toBeGreaterThan(0);
});
});
2 changes: 1 addition & 1 deletion packages/vrender-components/src/marker/animate/animate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function markArcAreaAnimate(area: IArc, label: Tag | Tag[], animationconf
}

export function markPointAnimate(
lines: [Segment, ILine],
lines: [Segment | ArcSegment, ILine],
item: Tag | IRichText | ISymbol | IImage,
animationconfig: any,
state: MarkerAnimationState
Expand Down
13 changes: 7 additions & 6 deletions packages/vrender-components/src/marker/animate/call-in.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { EasingType, IImage, ILine, IRichText, ISymbol } from '@visactor/vrender-core';
import type { Segment } from '../../segment';
import type { ArcSegment, Segment } from '../../segment';
import type { Tag } from '../../tag';
import { graphicFadeIn } from './common';
import { getSegmentLineGraphics, graphicFadeIn } from './common';

export function pointCallIn(
itemLine: Segment,
itemLine: Segment | ArcSegment,
decorativeLine: ILine,
item: Tag | IRichText | ISymbol | IImage,
duration: number,
Expand All @@ -21,9 +21,10 @@ export function pointCallIn(
graphicFadeIn(itemLine.startSymbol, delay, startSymbolDuration, easing);

// line
itemLine.lines.forEach(line => line.setAttribute('clipRange', 0));
itemLine.lines.forEach((l, index) => {
const stepDuration = lineDuration / itemLine.lines.length;
const lines = getSegmentLineGraphics(itemLine);
lines.forEach(line => line.setAttribute('clipRange', 0));
lines.forEach((l, index) => {
const stepDuration = lineDuration / lines.length;
l.animate()
.wait(delay + startSymbolDuration + index * stepDuration)
.to({ clipRange: 1 }, stepDuration, easing);
Expand Down
9 changes: 5 additions & 4 deletions packages/vrender-components/src/marker/animate/clip-in.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { EasingType } from '@visactor/vrender-core';
import type { ArcSegment, Segment } from '../../segment';
import type { Tag } from '../../tag';
import { graphicFadeIn } from './common';
import { getSegmentLineGraphics, graphicFadeIn } from './common';
import { array } from '@visactor/vutils';

export function commonLineClipIn(
Expand All @@ -20,9 +20,10 @@ export function commonLineClipIn(
graphicFadeIn(line.startSymbol, delay, startSymbolDuration, easing);

// line
line.lines.forEach(line => line.setAttribute('clipRange', 0));
line.lines.forEach((l, index) => {
const stepDuration = lineDuration / line.lines.length;
const lines = getSegmentLineGraphics(line);
lines.forEach(line => line.setAttribute('clipRange', 0));
lines.forEach((l, index) => {
const stepDuration = lineDuration / lines.length;
l.animate()
.wait(delay + startSymbolDuration + index * stepDuration)
.to({ clipRange: 1 }, stepDuration, easing);
Expand Down
13 changes: 9 additions & 4 deletions packages/vrender-components/src/marker/animate/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import type { EasingType, IGraphic } from '@visactor/vrender-core';
import type { ArcSegment, Segment } from '../../segment';
import type { Tag } from '../../tag';

export function getSegmentLineGraphics(segment: Segment | ArcSegment): IGraphic[] {
if (!segment) {
return [];
}
return [...(segment.lines ?? []), (segment as ArcSegment).line].filter(Boolean) as IGraphic[];
}

/** fade-in */
export function graphicFadeIn(graphic: IGraphic, delay: number, duration: number, easing: EasingType) {
if (!graphic) {
Expand Down Expand Up @@ -35,8 +42,7 @@ export function segmentFadeIn(segment: Segment, delay: number, duration: number,
graphicFadeIn(segment.startSymbol, delay, duration, easing);

// line
segment.lines.forEach(line => graphicFadeIn(line, delay, duration, easing));
graphicFadeIn((segment as ArcSegment).line, delay, duration, easing);
getSegmentLineGraphics(segment).forEach(line => graphicFadeIn(line, delay, duration, easing));

// end symbol
graphicFadeIn(segment.endSymbol, delay, duration, easing);
Expand Down Expand Up @@ -77,8 +83,7 @@ export function segmentFadeOut(segment: Segment | ArcSegment, delay: number, dur
graphicFadeOut(segment.startSymbol, delay, duration, easing);

// line
segment.lines.forEach(line => graphicFadeOut(line, delay, duration, easing));
graphicFadeOut((segment as ArcSegment).line, delay, duration, easing);
getSegmentLineGraphics(segment).forEach(line => graphicFadeOut(line, delay, duration, easing));

// end symbol
graphicFadeOut(segment.endSymbol, delay, duration, easing);
Expand Down
2 changes: 1 addition & 1 deletion packages/vrender-components/src/marker/animate/fade-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function arcAreaFadeIn(area: IArc, label: Tag | Tag[], duration: number,
}

export function pointFadeIn(
itemLine: Segment,
itemLine: Segment | ArcSegment,
decorativeLine: ILine,
item: Tag | IRichText | ISymbol | IImage,
duration: number,
Expand Down
2 changes: 1 addition & 1 deletion packages/vrender-components/src/marker/animate/fade-out.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function arcAreaFadeOut(area: IArc, label: Tag | Tag[], duration: number,
}

export function pointFadeOut(
itemLine: Segment,
itemLine: Segment | ArcSegment,
decorativeLine: ILine,
item: Tag | IRichText | ISymbol | IImage,
duration: number,
Expand Down
17 changes: 10 additions & 7 deletions packages/vrender-components/src/marker/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,26 +195,22 @@ export type BaseMarkerAnimation<T> = {
*/
animationExit?: MarkerExitAnimation;
};
export type MarkerAnimation<T> = MarkerUpdateAnimation<T> | MarkerUpdateAnimation<T>;
export type MarkerAnimation<T> = MarkerUpdateAnimation<T> | MarkerExitAnimation;

export type MarkerUpdateAnimation<T> = {
/**
* 设置动画的类型
*/
type: T;
} & MarkerExitAnimation;
} & MarkerAnimationBase;

export type MarkCommonLineAnimationType = 'clipIn' | 'fadeIn';

export type CommonMarkAreaAnimationType = 'fadeIn';

export type MarkPointAnimationType = 'callIn' | 'fadeIn';

export type MarkerExitAnimation = {
/**
* 设置离场动画的类型为fadeOut,即淡出
*/
type: 'fadeOut';
export type MarkerAnimationBase = {
/**
* 动画的时长
*/
Expand All @@ -229,6 +225,13 @@ export type MarkerExitAnimation = {
easing?: EasingType;
};

export type MarkerExitAnimation = MarkerAnimationBase & {
/**
* 设置离场动画的类型为fadeOut,即淡出
*/
type: 'fadeOut';
};

export type MarkerAnimationState = 'enter' | 'update' | 'exit';

/** state type */
Expand Down
8 changes: 5 additions & 3 deletions packages/vrender-core/src/graphic/arc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const ARC_UPDATE_TAG_KEY = [
'cornerRadius',
'padAngle',
'padRadius',
'clipRange',
'cap',
...GRAPHIC_UPDATE_TAG_KEY
];
Expand Down Expand Up @@ -146,15 +147,16 @@ export class Arc extends Graphic<IArcGraphicAttribute> implements IArc {
getParsedAngle() {
const arcTheme = this.getGraphicTheme();
let { startAngle = arcTheme.startAngle, endAngle = arcTheme.endAngle } = this.attribute;
const { cap = arcTheme.cap } = this.attribute;
const { cap = arcTheme.cap, clipRange = arcTheme.clipRange } = this.attribute;

const sign = endAngle - startAngle >= 0 ? 1 : -1;
const deltaAngle = endAngle - startAngle;
let deltaAngle = endAngle - startAngle;
deltaAngle *= Math.max(0, Math.min(clipRange, 1));

startAngle = clampAngleByRadian(startAngle);
endAngle = startAngle + deltaAngle;

if (cap && abs(deltaAngle) < pi2 - epsilon) {
if (cap && abs(deltaAngle) > epsilon && abs(deltaAngle) < pi2 - epsilon) {
let startCap = 1;
let endCap = 1;
if ((cap as boolean[]).length) {
Expand Down
1 change: 1 addition & 0 deletions packages/vrender-core/src/graphic/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export const DefaultArcAttribute: Required<IArcGraphicAttribute> = {
cornerRadius: 0,
padRadius: 0,
padAngle: 0,
clipRange: 1,
cap: false,
forceShowCap: false
};
Expand Down
4 changes: 4 additions & 0 deletions packages/vrender-core/src/interface/graphic/arc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export type IArcAttribute = {
* 当cap = true 并且 使用了渐变填充的时候,自动实现conical渐变,也就是环形的渐变
*/
forceShowCap: boolean;
/**
* 按角度范围裁剪绘制比例,0 表示不绘制,1 表示完整绘制。
*/
clipRange: number;
};
/**
* 内部缓存,用于存储一些内部变量
Expand Down
Loading