π₯ Make videos programmatically with React
Elements: Replace data series chart with horizontal bar chart (#9510)
Igor Samokhovets05877eee5203
diff --git a/packages/docs/elements-sidebars.ts b/packages/docs/elements-sidebars.tsindex a45bbd16da..6ec614d89f 100644--- a/packages/docs/elements-sidebars.ts+++ b/packages/docs/elements-sidebars.ts@@ -30,7 +30,7 @@ const sidebars: SidebarsConfig = {link: {type: 'doc', id: 'data/index'},collapsed: false,items: [- 'data/data-series-chart/index',+ 'data/horizontal-bar-chart/index','data/number-counter/index','data/product-offer/index',],diff --git a/packages/docs/elements/data/data-series-chart/data-series-chart.tsx b/packages/docs/elements/data/data-series-chart/data-series-chart.tsxdeleted file mode 100644index f5d81da492..0000000000--- a/packages/docs/elements/data/data-series-chart/data-series-chart.tsx+++ /dev/null@@ -1,414 +0,0 @@-import {loadFont} from '@remotion/google-fonts/Inter';-import React, {useId} from 'react';-import {Easing, Interactive, interpolate, useCurrentFrame} from 'remotion';--loadFont('normal', {- subsets: ['latin'],- weights: ['400', '500', '600', '700'],-});--const DATA = [- {month: 'Jan', revenue: 8000, conversionRate: 2.1},- {month: 'Feb', revenue: 12000, conversionRate: 2.8},- {month: 'Mar', revenue: 15000, conversionRate: 3.2},- {month: 'Apr', revenue: 11000, conversionRate: 2.9},- {month: 'May', revenue: 18000, conversionRate: 3.8},- {month: 'Jun', revenue: 22000, conversionRate: 4.2},-] as const;--const COLORS = {- accent: '#0B84F3',- barBottom: '#A1A1AA',- barTop: '#F4F4F5',- grid: 'rgba(255, 255, 255, 0.09)',- heading: '#FAFAFA',- label: '#D4D4D8',- muted: '#A1A1AA',- onBar: '#18181B',-} as const;--const VIEWBOX_WIDTH = 1560;-const VIEWBOX_HEIGHT = 864;-const PLOT_LEFT = 165;-const PLOT_RIGHT = 1395;-const PLOT_TOP = 238;-const PLOT_BOTTOM = 716;-const PLOT_WIDTH = PLOT_RIGHT - PLOT_LEFT;-const PLOT_HEIGHT = PLOT_BOTTOM - PLOT_TOP;-const SLOT_WIDTH = PLOT_WIDTH / DATA.length;-const BAR_WIDTH = 122;--const linePoints = DATA.map((item, index) => ({- x: PLOT_LEFT + SLOT_WIDTH * (index + 0.5),- y: PLOT_BOTTOM - (item.conversionRate / 5) * PLOT_HEIGHT,-}));--const linePath = linePoints- .map((point, index) => `${index === 0 ? 'M' : 'L'} ${point.x} ${point.y}`)- .join(' ');--const segmentLengths = linePoints.slice(1).map((point, index) => {- const previous = linePoints[index];- return Math.hypot(point.x - previous.x, point.y - previous.y);-});--const totalLineLength = segmentLengths.reduce((sum, length) => sum + length, 0);--const getLineTip = (progress: number) => {- const targetLength = progress * totalLineLength;- let coveredLength = 0;-- for (let index = 0; index < segmentLengths.length; index++) {- const segmentLength = segmentLengths[index];- if (coveredLength + segmentLength >= targetLength) {- const segmentProgress = (targetLength - coveredLength) / segmentLength;- const start = linePoints[index];- const end = linePoints[index + 1];-- return {- x: start.x + (end.x - start.x) * segmentProgress,- y: start.y + (end.y - start.y) * segmentProgress,- };- }-- coveredLength += segmentLength;- }-- return linePoints[linePoints.length - 1];-};--export const DataSeriesChart: React.FC = () => {- const frame = useCurrentFrame();- const id = useId().replaceAll(':', '');- const barGradientId = `bar-gradient-${id}`;- const glowFilterId = `line-glow-${id}`;-- const lineProgress = interpolate(frame, [32, 88], [0, 1], {- extrapolateLeft: 'clamp',- extrapolateRight: 'clamp',- easing: Easing.inOut(Easing.cubic),- });- const lineTip = getLineTip(lineProgress);- const pulse = (Math.sin(frame * 0.32) + 1) / 2;-- return (- <Interactive.Div- name="Container"- style={{- backgroundColor: '#18181B',- border: '1px solid rgba(255, 255, 255, 0.08)',- borderRadius: 24,- boxShadow: '0 12px 30px rgba(24, 24, 27, 0.18)',- boxSizing: 'border-box',- fontFamily: 'Inter, sans-serif',- fontVariantNumeric: 'tabular-nums',- height: '100%',- opacity: interpolate(frame, [0, 10, 104, 119], [0, 1, 1, 0], {- easing: Easing.out(Easing.cubic),- extrapolateLeft: 'clamp',- extrapolateRight: 'clamp',- }),- overflow: 'hidden',- position: 'relative',- scale: interpolate(frame, [0, 14, 104, 119], [0.96, 1, 1, 0.97], {- easing: Easing.out(Easing.cubic),- extrapolateLeft: 'clamp',- extrapolateRight: 'clamp',- }),- transformOrigin: '50% 50%',- translate: interpolate(- frame,- [0, 18, 104, 119],- ['0px 18px', '0px 0px', '0px 0px', '0px -10px'],- {- easing: Easing.out(Easing.cubic),- extrapolateLeft: 'clamp',- extrapolateRight: 'clamp',- },- ),- width: '100%',- }}- >- <svg- aria-label="Monthly revenue and conversion rate from January to June"- role="img"- style={{display: 'block', height: '100%', width: '100%'}}- viewBox={`0 0 ${VIEWBOX_WIDTH} ${VIEWBOX_HEIGHT}`}- >- <defs>- <linearGradient id={barGradientId} x1="0" x2="0" y1="0" y2="1">- <stop offset="0%" stopColor={COLORS.barTop} />- <stop offset="100%" stopColor={COLORS.barBottom} />- </linearGradient>- <filter- height="220%"- id={glowFilterId}- width="220%"- x="-60%"- y="-60%"- >- <feGaussianBlur stdDeviation="8" />- </filter>- </defs>-- <g- opacity={interpolate(frame, [2, 16], [0, 1], {- extrapolateLeft: 'clamp',- extrapolateRight: 'clamp',- easing: Easing.out(Easing.cubic),- })}- >- <text- fill={COLORS.muted}- fontSize="20"- fontWeight="600"- x="82"- y="66"- >- Monthly performance- </text>- <text- fill={COLORS.heading}- fontSize="46"- fontWeight="600"- letterSpacing="-1.4"- x="82"- y="120"- >- Revenue & conversion- </text>- <text- fill={COLORS.muted}- fontSize="20"- fontWeight="500"- x="82"- y="158"- >- January β June- </text>-- <rect- fill={`url(#${barGradientId})`}- height="20"- rx="6"- width="20"- x="1100"- y="94"- />- <text- fill={COLORS.label}- fontSize="20"- fontWeight="500"- x="1136"- y="112"- >- Revenue- </text>- <line- stroke={COLORS.accent}- strokeLinecap="round"- strokeWidth="6"- x1="1268"- x2="1296"- y1="104"- y2="104"- />- <circle cx="1282" cy="104" fill={COLORS.accent} r="7" />- <text- fill={COLORS.label}- fontSize="20"- fontWeight="500"- x="1312"- y="112"- >- Conversion- </text>- </g>-- <g- opacity={interpolate(frame, [5, 20], [0, 1], {- extrapolateLeft: 'clamp',- extrapolateRight: 'clamp',- easing: Easing.out(Easing.cubic),- })}- >- {[0, 1, 2, 3, 4, 5].map((tick) => {- const y = PLOT_BOTTOM - (tick / 5) * PLOT_HEIGHT;- return (- <g key={tick}>- <line- stroke={COLORS.grid}- strokeWidth="1"- x1={PLOT_LEFT}- x2={PLOT_RIGHT}- y1={y}- y2={y}- />- <text- dominantBaseline="middle"- fill={COLORS.muted}- fontSize="18"- fontWeight="500"- textAnchor="end"- x={PLOT_LEFT - 22}- y={y}- >- {tick === 0 ? '$0' : `$${tick * 5}K`}- </text>- <text- dominantBaseline="middle"- fill={COLORS.muted}- fontSize="18"- fontWeight="500"- x={PLOT_RIGHT + 22}- y={y}- >- {tick}%- </text>- </g>- );- })}- <text- fill={COLORS.muted}- fontSize="16"- fontWeight="600"- letterSpacing="1.4"- textAnchor="middle"- transform="rotate(-90 50 477)"- x="50"- y="477"- >- Revenue- </text>- <text- fill={COLORS.muted}- fontSize="16"- fontWeight="600"- letterSpacing="1.4"- textAnchor="middle"- transform="rotate(90 1510 477)"- x="1510"- y="477"- >- Conversion rate- </text>- </g>-- {DATA.map((item, index) => {- const x = PLOT_LEFT + SLOT_WIDTH * (index + 0.5);- const targetHeight = (item.revenue / 25000) * PLOT_HEIGHT;- const barProgress = interpolate(- frame,- [10 + index * 6, 34 + index * 6],- [0, 1],- {- extrapolateLeft: 'clamp',- extrapolateRight: 'clamp',- easing: Easing.spring({- damping: 16,- mass: 0.65,- stiffness: 105,- }),- },- );- const barHeight = targetHeight * barProgress;- const barTop = PLOT_BOTTOM - barHeight;-- return (- <g key={item.month}>- <rect- fill={`url(#${barGradientId})`}- height={Math.max(0, barHeight)}- rx="16"- width={BAR_WIDTH}- x={x - BAR_WIDTH / 2}- y={barTop}- />- <text- fill={COLORS.onBar}- fontSize="21"- fontWeight="700"- opacity={interpolate(barProgress, [0.55, 0.9], [0, 1], {- extrapolateLeft: 'clamp',- extrapolateRight: 'clamp',- })}- textAnchor="middle"- x={x}- y={PLOT_BOTTOM - 24}- >- ${item.revenue / 1000}K- </text>- <text- fill={COLORS.label}- fontSize="21"- fontWeight="600"- opacity={interpolate(- frame,- [12 + index * 6, 24 + index * 6],- [0, 1],- {- extrapolateLeft: 'clamp',- extrapolateRight: 'clamp',- },- )}- textAnchor="middle"- x={x}- y={PLOT_BOTTOM + 48}- >- {item.month}- </text>- </g>- );- })}-- <path- d={linePath}- fill="none"- filter={`url(#${glowFilterId})`}- opacity="0.55"- pathLength="1"- stroke={COLORS.accent}- strokeDasharray="1"- strokeDashoffset={1 - lineProgress}- strokeLinecap="round"- strokeLinejoin="round"- strokeWidth="16"- />- <path- d={linePath}- fill="none"- pathLength="1"- stroke={COLORS.accent}- strokeDasharray="1"- strokeDashoffset={1 - lineProgress}- strokeLinecap="round"- strokeLinejoin="round"- strokeWidth="7"- />-- <g- opacity={interpolate(frame, [32, 38], [0, 1], {- extrapolateLeft: 'clamp',- extrapolateRight: 'clamp',- })}- >- <circle- cx={lineTip.x}- cy={lineTip.y}- fill={COLORS.accent}- opacity={0.14 + pulse * 0.1}- r={20 + pulse * 7}- />- <circle- cx={lineTip.x}- cy={lineTip.y}- fill={COLORS.accent}- r={10 + pulse * 1.5}- stroke={COLORS.heading}- strokeWidth="4"- />- </g>- </svg>- </Interactive.Div>- );-};diff --git a/packages/docs/elements/data/data-series-chart/index.mdx b/packages/docs/elements/data/data-series-chart/index.mdxdeleted file mode 100644index 1da0067da8..0000000000--- a/packages/docs/elements/data/data-series-chart/index.mdx+++ /dev/null@@ -1,11 +0,0 @@-----title: Data Series Chart-description: An animated combination chart with sequential bars and a glowing line.------import {ElementPage} from '@site/src/components/Elements/ElementPage';-import {elementDefinitions} from '@site/src/components/Elements/element-definitions';--# Data Series Chart--<ElementPage definition={elementDefinitions['data/data-series-chart']} sourceFile="./data-series-chart.tsx" />diff --git a/packages/docs/elements/data/horizontal-bar-chart/horizontal-bar-chart.tsx b/packages/docs/elements/data/horizontal-bar-chart/horizontal-bar-chart.tsxnew file mode 100644index 0000000000..1280f22755--- /dev/null+++ b/packages/docs/elements/data/horizontal-bar-chart/horizontal-bar-chart.tsx@@ -0,0 +1,222 @@+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'],+});++export const HorizontalBarChart: React.FC = () => {+ const frame = useCurrentFrame();++ return (+ <Interactive.Div+ name="Chart"+ style={{+ backgroundColor: '#f7f4ec',+ borderRadius: 28,+ boxSizing: 'border-box',+ color: '#111827',+ display: 'flex',+ flexDirection: 'column',+ fontFamily,+ fontVariantNumeric: 'tabular-nums',+ height: '100%',+ opacity: interpolate(frame, [0, 8, 108, 119], [0, 1, 1, 0], {+ easing: Easing.out(Easing.cubic),+ extrapolateLeft: 'clamp',+ extrapolateRight: 'clamp',+ }),+ overflow: 'hidden',+ padding: '72px 80px',+ width: '100%',+ }}+ >+ <Interactive.H1+ name="Title"+ style={{+ fontSize: 76,+ fontWeight: 800,+ letterSpacing: -3.8,+ lineHeight: 0.95,+ margin: 0,+ }}+ >+ Revenue by channel+ </Interactive.H1>++ <div+ style={{+ display: 'flex',+ flex: 1,+ flexDirection: 'column',+ gap: 42,+ justifyContent: 'flex-end',+ }}+ >+ <Interactive.Div+ name="Direct bar"+ style={{+ alignItems: 'center',+ backgroundColor: '#2858e8',+ borderRadius: 12,+ boxSizing: 'border-box',+ clipPath: `inset(0 ${interpolate(frame, [8, 32], [100, 0], {+ easing: Easing.out(Easing.cubic),+ extrapolateLeft: 'clamp',+ extrapolateRight: 'clamp',+ })}% 0 0)`,+ color: '#ffffff',+ display: 'flex',+ height: 136,+ justifyContent: 'space-between',+ overflow: 'hidden',+ padding: '0 34px',+ width: '100%',+ }}+ >+ <Interactive.Div+ name="Direct label"+ style={{+ fontSize: 40,+ fontWeight: 700,+ lineHeight: 1,+ opacity: interpolate(frame, [24, 30], [0, 1], {+ extrapolateLeft: 'clamp',+ extrapolateRight: 'clamp',+ }),+ whiteSpace: 'nowrap',+ }}+ >+ Direct+ </Interactive.Div>+ <Interactive.Div+ name="Direct value"+ style={{+ fontSize: 48,+ fontWeight: 800,+ letterSpacing: -1.6,+ lineHeight: 1,+ opacity: interpolate(frame, [25, 31], [0, 1], {+ extrapolateLeft: 'clamp',+ extrapolateRight: 'clamp',+ }),+ whiteSpace: 'nowrap',+ }}+ >+ $24M+ </Interactive.Div>+ </Interactive.Div>++ <Interactive.Div+ name="Retail bar"+ style={{+ alignItems: 'center',+ backgroundColor: '#2858e8',+ borderRadius: 12,+ boxSizing: 'border-box',+ clipPath: `inset(0 ${interpolate(frame, [14, 38], [100, 0], {+ easing: Easing.out(Easing.cubic),+ extrapolateLeft: 'clamp',+ extrapolateRight: 'clamp',+ })}% 0 0)`,+ color: '#ffffff',+ display: 'flex',+ height: 136,+ justifyContent: 'space-between',+ overflow: 'hidden',+ padding: '0 34px',+ width: '67%',+ }}+ >+ <Interactive.Div+ name="Retail label"+ style={{+ fontSize: 40,+ fontWeight: 700,+ lineHeight: 1,+ opacity: interpolate(frame, [30, 36], [0, 1], {+ extrapolateLeft: 'clamp',+ extrapolateRight: 'clamp',+ }),+ whiteSpace: 'nowrap',+ }}+ >+ Retail+ </Interactive.Div>+ <Interactive.Div+ name="Retail value"+ style={{+ fontSize: 48,+ fontWeight: 800,+ letterSpacing: -1.6,+ lineHeight: 1,+ opacity: interpolate(frame, [31, 37], [0, 1], {+ extrapolateLeft: 'clamp',+ extrapolateRight: 'clamp',+ }),+ whiteSpace: 'nowrap',+ }}+ >+ $16M+ </Interactive.Div>+ </Interactive.Div>++ <Interactive.Div+ name="Partners bar"+ style={{+ alignItems: 'center',+ backgroundColor: '#2858e8',+ borderRadius: 12,+ boxSizing: 'border-box',+ clipPath: `inset(0 ${interpolate(frame, [20, 44], [100, 0], {+ easing: Easing.out(Easing.cubic),+ extrapolateLeft: 'clamp',+ extrapolateRight: 'clamp',+ })}% 0 0)`,+ color: '#ffffff',+ display: 'flex',+ height: 136,+ justifyContent: 'space-between',+ overflow: 'hidden',+ padding: '0 34px',+ width: '38%',+ }}+ >+ <Interactive.Div+ name="Partners label"+ style={{+ fontSize: 40,+ fontWeight: 700,+ lineHeight: 1,+ opacity: interpolate(frame, [36, 42], [0, 1], {+ extrapolateLeft: 'clamp',+ extrapolateRight: 'clamp',+ }),+ whiteSpace: 'nowrap',+ }}+ >+ Partners+ </Interactive.Div>+ <Interactive.Div+ name="Partners value"+ style={{+ fontSize: 48,+ fontWeight: 800,+ letterSpacing: -1.6,+ lineHeight: 1,+ opacity: interpolate(frame, [37, 43], [0, 1], {+ extrapolateLeft: 'clamp',+ extrapolateRight: 'clamp',+ }),+ whiteSpace: 'nowrap',+ }}+ >+ $9M+ </Interactive.Div>+ </Interactive.Div>+ </div>+ </Interactive.Div>+ );+};diff --git a/packages/docs/elements/data/horizontal-bar-chart/index.mdx b/packages/docs/elements/data/horizontal-bar-chart/index.mdxnew file mode 100644index 0000000000..b5b4f39f80--- /dev/null+++ b/packages/docs/elements/data/horizontal-bar-chart/index.mdx@@ -0,0 +1,11 @@+---+title: Horizontal Bar Chart+description: A bold bar chart card with three directly labeled data points.+---++import {ElementPage} from '@site/src/components/Elements/ElementPage';+import {elementDefinitions} from '@site/src/components/Elements/element-definitions';++# Horizontal Bar Chart++<ElementPage definition={elementDefinitions['data/horizontal-bar-chart']} sourceFile="./horizontal-bar-chart.tsx" />diff --git a/packages/docs/elements/data/index.mdx b/packages/docs/elements/data/index.mdxindex f4eb333f8c..f64ff6cc25 100644--- a/packages/docs/elements/data/index.mdx+++ b/packages/docs/elements/data/index.mdx@@ -7,6 +7,6 @@ description: Animated data visualization Elements for Remotion videos.Elements:-- [Data Series Chart](/elements/data/data-series-chart/)+- [Horizontal Bar Chart](/elements/data/horizontal-bar-chart/)- [Number Counter](/elements/data/number-counter/)- [Product Offer](/elements/data/product-offer/)diff --git a/packages/docs/src/components/Elements/element-definitions.ts b/packages/docs/src/components/Elements/element-definitions.tsindex 226a258dd2..7e24bfdb9b 100644--- a/packages/docs/src/components/Elements/element-definitions.ts+++ b/packages/docs/src/components/Elements/element-definitions.ts@@ -3,7 +3,7 @@ import {LiquidContours} from '../../../elements/backgrounds/liquid-contours/liquimport {NotebookPaper} from '../../../elements/backgrounds/notebook-paper/notebook-paper';import {PaperTexture} from '../../../elements/backgrounds/paper-texture/paper-texture';import {RotatingStarburst} from '../../../elements/backgrounds/rotating-starburst/rotating-starburst';-import {DataSeriesChart} from '../../../elements/data/data-series-chart/data-series-chart';+import {HorizontalBarChart} from '../../../elements/data/horizontal-bar-chart/horizontal-bar-chart';import {NumberCounter} from '../../../elements/data/number-counter/number-counter';import {ProductOffer} from '../../../elements/data/product-offer/product-offer';import {LocationLowerThird} from '../../../elements/overlays/location-lower-third/location-lower-third';@@ -139,22 +139,22 @@ export const elementDefinitions = {transparentPreview: false,width: 1920,},- 'data/data-series-chart': {+ 'data/horizontal-bar-chart': {category: 'data',- component: DataSeriesChart,+ component: HorizontalBarChart,contributors: [],description:- 'An animated combination chart with sequential revenue bars and a glowing conversion line.',- displayName: 'Data Series Chart',+ 'A bold bar chart card with three directly labeled data points.',+ displayName: 'Horizontal Bar Chart',durationInFrames: 120,elementHeight: 864,elementWidth: 1560,fps: 30,height: 1080,- posterFrame: 88,+ posterFrame: 48,previewPadding: 56,- slug: 'data/data-series-chart',- transparentPreview: false,+ slug: 'data/horizontal-bar-chart',+ transparentPreview: true,width: 1920,},'data/number-counter': {diff --git a/packages/docs/src/test/elements.test.ts b/packages/docs/src/test/elements.test.tsindex 408a4e074f..d50c921d0e 100644--- a/packages/docs/src/test/elements.test.ts+++ b/packages/docs/src/test/elements.test.ts@@ -305,7 +305,7 @@ describe('Element preview definitions', () => {elementDefinitionList.filter((definition) => definition.transparentPreview).map((definition) => definition.slug),- ).toEqual(['data/product-offer']);+ ).toEqual(['data/horizontal-bar-chart', 'data/product-offer']);});test('registers Element compositions in a Folder', () => {