Skip to content

🎥 Make videos programmatically with React

Elements: Add vertical bar chart element (#10381)

Igor Samokhovets4e459b8b3aee
diff --git a/packages/docs/elements-sidebars.ts b/packages/docs/elements-sidebars.ts
index 5bd9b7ac83..8c64d7d158 100644
--- a/packages/docs/elements-sidebars.ts
+++ b/packages/docs/elements-sidebars.ts
@@ -54,6 +54,7 @@ const sidebars: SidebarsConfig = {
'data/horizontal-bar-chart/index',
'data/number-counter/index',
'data/pie-chart/index',
+ 'data/vertical-bar-chart/index',
],
},
{
diff --git a/packages/docs/elements/data/vertical-bar-chart/index.mdx b/packages/docs/elements/data/vertical-bar-chart/index.mdx
new file mode 100644
index 0000000000..84baf60e96
--- /dev/null
+++ b/packages/docs/elements/data/vertical-bar-chart/index.mdx
@@ -0,0 +1,12 @@
+---
+title: Vertical Bar Chart
+description: A bold vertical bar chart with three directly labeled data points.
+image: https://remotion.media/elements/data-vertical-bar-chart-preview.png
+---
+
+import {ElementPage} from '@site/src/components/Elements/ElementPage';
+import {elementDefinitions} from '@site/src/components/Elements/element-definitions';
+
+# Vertical Bar Chart
+
+<ElementPage definition={elementDefinitions['data/vertical-bar-chart']} sourceFile="./vertical-bar-chart.tsx" />
diff --git a/packages/docs/elements/data/vertical-bar-chart/vertical-bar-chart.tsx b/packages/docs/elements/data/vertical-bar-chart/vertical-bar-chart.tsx
new file mode 100644
index 0000000000..50919ac9fa
--- /dev/null
+++ b/packages/docs/elements/data/vertical-bar-chart/vertical-bar-chart.tsx
@@ -0,0 +1,236 @@
+import {loadFont} from '@remotion/google-fonts/Inter';
+import React from 'react';
+import {Easing, Interactive, interpolate, useCurrentFrame} from 'remotion';
+
+const {fontFamily} = loadFont('normal', {
+ subsets: ['latin'],
+ weights: ['700', '800'],
+});
+
+const data = [
+ {highlighted: false, label: 'Jonny', value: 34},
+ {highlighted: false, label: 'Igor', value: 89},
+ {highlighted: true, label: 'Mehmet', value: 163},
+];
+
+const maxValue = Math.max(...data.map(({value}) => value));
+
+const growthEasing = Easing.spring({
+ damping: 14.5,
+ mass: 0.8,
+ overshootClamping: false,
+ stiffness: 100,
+});
+
+const Bar: React.FC<{
+ readonly animationDelay: number;
+ readonly highlighted: boolean;
+ readonly label: string;
+ readonly value: number;
+}> = ({animationDelay, highlighted, label, value}) => {
+ const frame = useCurrentFrame();
+ const barAnimationStart = 22 + animationDelay;
+ const barAnimationEnd =
+ barAnimationStart + 16 + Math.round((value / maxValue) * 8);
+ const growthProgress =
+ frame >= barAnimationEnd
+ ? 1
+ : interpolate(frame, [barAnimationStart, barAnimationEnd], [0, 1], {
+ easing: [growthEasing],
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ });
+ const valueAnimationStart = barAnimationEnd - 8;
+ const valueAnimationEnd = barAnimationEnd + 2;
+ const valueProgress = interpolate(
+ frame,
+ [valueAnimationStart, valueAnimationEnd],
+ [0, 1],
+ {
+ easing: growthEasing,
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ },
+ );
+
+ return (
+ <div
+ style={{
+ display: 'flex',
+ flexDirection: 'column',
+ gap: 20,
+ height: '100%',
+ margin: '0 auto',
+ width: 280,
+ }}
+ >
+ <div
+ style={{
+ alignItems: 'flex-end',
+ display: 'flex',
+ flex: 1,
+ }}
+ >
+ <div
+ style={{
+ height: `${(value / maxValue) * 90}%`,
+ position: 'relative',
+ width: '100%',
+ }}
+ >
+ <div
+ style={{
+ bottom: `calc(${growthProgress * 100}% + 12px)`,
+ left: 0,
+ overflow: frame < valueAnimationEnd ? 'hidden' : 'visible',
+ position: 'absolute',
+ visibility: frame <= valueAnimationStart ? 'hidden' : 'visible',
+ width: '100%',
+ }}
+ >
+ <div
+ style={{
+ transform: 'perspective(100px)',
+ translate: `0 ${(1 - valueProgress) * 100}%`,
+ willChange: 'transform',
+ }}
+ >
+ <Interactive.Div
+ name="Value"
+ style={{
+ color: '#111827',
+ fontSize: 48,
+ fontWeight: 800,
+ letterSpacing: -1.6,
+ lineHeight: 1,
+ textAlign: 'center',
+ whiteSpace: 'nowrap',
+ width: '100%',
+ }}
+ >
+ {value}
+ </Interactive.Div>
+ </div>
+ </div>
+ <div
+ style={{
+ bottom: 0,
+ height: `${growthProgress * 100}%`,
+ position: 'absolute',
+ width: '100%',
+ }}
+ >
+ <Interactive.Div
+ name="Bar"
+ style={{
+ backgroundColor: highlighted ? '#2858e8' : '#b9c0ca',
+ borderRadius: '12px 12px 0 0',
+ height: '100%',
+ width: '100%',
+ }}
+ />
+ </div>
+ </div>
+ </div>
+ <div
+ style={{
+ overflow: frame < barAnimationEnd ? 'hidden' : 'visible',
+ }}
+ >
+ <div
+ style={{
+ transform: 'perspective(100px)',
+ translate: `0 ${(1 - growthProgress) * 100}%`,
+ willChange: 'transform',
+ }}
+ >
+ <Interactive.Div
+ name="Label"
+ style={{
+ color: '#111827',
+ fontSize: 40,
+ fontWeight: 700,
+ lineHeight: 1.2,
+ textAlign: 'center',
+ whiteSpace: 'nowrap',
+ }}
+ >
+ {label}
+ </Interactive.Div>
+ </div>
+ </div>
+ </div>
+ );
+};
+
+export const VerticalBarChart: React.FC = () => {
+ return (
+ <Interactive.Div
+ name="Chart"
+ style={{
+ display: 'flex',
+ flexDirection: 'column',
+ fontFamily,
+ fontVariantNumeric: 'tabular-nums',
+ gap: 42,
+ height: '100%',
+ justifyContent: 'center',
+ }}
+ >
+ <Interactive.H1
+ name="Title"
+ style={{
+ color: '#111827',
+ fontSize: 76,
+ fontWeight: 800,
+ letterSpacing: -3.8,
+ lineHeight: 0.95,
+ margin: 0,
+ }}
+ >
+ Browser tabs open
+ </Interactive.H1>
+ <div
+ style={{
+ alignSelf: 'center',
+ display: 'flex',
+ flex: 1,
+ justifyContent: 'space-between',
+ minHeight: 0,
+ position: 'relative',
+ width: 1080,
+ }}
+ >
+ <Interactive.Div
+ name="Baseline"
+ style={{
+ backgroundColor: '#c5cad2',
+ bottom: 68,
+ height: 3,
+ left: '50%',
+ position: 'absolute',
+ translate: '-50% 50%',
+ width: '100%',
+ zIndex: 1,
+ }}
+ />
+ {data.map(({highlighted, label, value}, index) => (
+ <div
+ key={label}
+ style={{
+ flex: '0 0 280px',
+ height: '100%',
+ }}
+ >
+ <Bar
+ animationDelay={index * 24}
+ highlighted={highlighted}
+ label={label}
+ value={value}
+ />
+ </div>
+ ))}
+ </div>
+ </Interactive.Div>
+ );
+};
diff --git a/packages/docs/src/components/Elements/element-definitions.ts b/packages/docs/src/components/Elements/element-definitions.ts
index 3bbeb15bda..f9a91c39ab 100644
--- a/packages/docs/src/components/Elements/element-definitions.ts
+++ b/packages/docs/src/components/Elements/element-definitions.ts
@@ -15,6 +15,7 @@ import {ProductOffer} from '../../../elements/commerce/product-offer/product-off
import {HorizontalBarChart} from '../../../elements/data/horizontal-bar-chart/horizontal-bar-chart';
import {NumberCounter} from '../../../elements/data/number-counter/number-counter';
import {PieChart} from '../../../elements/data/pie-chart/pie-chart';
+import {VerticalBarChart} from '../../../elements/data/vertical-bar-chart/vertical-bar-chart';
import {MapFlyover} from '../../../elements/maps/map-flyover/a-to-b-map-flyover';
import {LocationLowerThird} from '../../../elements/overlays/location-lower-third/location-lower-third';
import {NameLowerThird} from '../../../elements/overlays/name-lower-third/name-lower-third';
@@ -332,6 +333,31 @@ export const elementDefinitions = {
installationMode: 'wrapped',
width: 1920,
},
+ 'data/vertical-bar-chart': {
+ category: 'data',
+ component: VerticalBarChart,
+ contributors: [],
+ description:
+ 'A bold vertical bar chart with three directly labeled data points.',
+ dependencies: [{name: '@remotion/google-fonts', version: null}],
+ displayName: 'Vertical Bar Chart',
+ durationInFrames: 120,
+ elementHeight: 864,
+ elementWidth: 1560,
+ fps: 30,
+ height: 1080,
+ posterFrame: 115,
+ preview: {
+ posterUrl:
+ 'https://remotion.media/elements/data-vertical-bar-chart-preview.png',
+ videoUrl:
+ 'https://remotion.media/elements/data-vertical-bar-chart-preview.mp4',
+ },
+ previewPadding: 56,
+ slug: 'data/vertical-bar-chart',
+ installationMode: 'wrapped',
+ width: 1920,
+ },
'commerce/product-discount-callout': {
category: 'commerce',
component: ProductDiscountCallout,