Skip to content

Commit

Permalink
docs(demo): add lottie #4221 (#4262)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoiver authored and hustcc committed Nov 14, 2022
1 parent 97e6e6d commit 6ce86ec
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions site/.dumi/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ if (window) {
(window as any).d3Array = require('d3-array');
(window as any).d3GeoProjection = require('d3-geo-projection');
(window as any).topojson = require('topojson');
(window as any).gLottiePlayer = require('@antv/g-lottie-player');
(window as any).webfontloader = require('webfontloader');
(
window as any
Expand Down
37 changes: 37 additions & 0 deletions site/examples/others/animation/demo/lottie.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Chart } from '@antv/g2';
import { loadAnimation } from '@antv/g-lottie-player';

const chart = new Chart({
container: 'container',
autoFit: true,
});

chart
.interval()
.data([
{ genre: 'Sports', sold: 275 },
{ genre: 'Strategy', sold: 115 },
{ genre: 'Action', sold: 120 },
{ genre: 'Shooter', sold: 350 },
{ genre: 'Other', sold: 150 },
])
.encode('x', 'genre')
.encode('y', 'sold')
.encode('color', 'genre')
.animate('enter', { type: 'fadeIn', duration: 1000 })
.animate('exit', { type: 'fadeOut', duration: 2000 });

chart.render();

(async () => {
const { canvas } = chart.context();
await canvas.ready;

const lottieJSON = await fetch(
'https://mdn.alipayobjects.com/huamei_qa8qxu/afts/file/A*C9f6TaadHikAAAAAAAAAAAAADmJ7AQ',
).then((res) => res.json());
const animation = loadAnimation(lottieJSON, { loop: true, autoplay: true });
const wrapper = animation.render(canvas);
wrapper.scale(0.5);
wrapper.translate(160, 100);
})();
10 changes: 9 additions & 1 deletion site/examples/others/animation/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
"en": "ZoomIn"
},
"screenshot": "https://gw.alipayobjects.com/zos/raptor/1667976930984/zoomIn.gif"
},
{
"filename": "lottie.ts",
"title": {
"zh": "Lottie",
"en": "Lottie"
},
"screenshot": "https://gw.alipayobjects.com/zos/raptor/1668077308397/Nov-10-2022%25252018-48-07.gif"
}
]
}
}
1 change: 1 addition & 0 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"dependencies": {
"@antv/dumi-theme-antv": "^0.3.0-beta.5",
"@antv/g-lottie-player": "^0.0.13",
"@antv/g-plugin-rough-canvas-renderer": "^1.7.27",
"@antv/g-plugin-a11y": "^0.4.27",
"d3-array": "^3.2.0",
Expand Down

0 comments on commit 6ce86ec

Please sign in to comment.