Skip to content

Commit 89fdffc

Browse files
committed
CHARTS-81: Add sales by product story.
1 parent 57ad605 commit 89fdffc

File tree

2 files changed

+88
-9
lines changed

2 files changed

+88
-9
lines changed

projects/js-packages/charts/src/components/leaderboard-chart/stories/index.stories.tsx

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import { ThemeProvider, jetpackTheme, wooTheme } from '../../../providers/theme';
22
import { formatMetricValue } from '../../shared/format-metric-value';
33
import { LeaderboardChart } from '../leaderboard-chart';
4-
import { sampleData, smallDataset, largeValues, negativeGrowth } from './sample-data';
4+
import {
5+
sampleData,
6+
smallDataset,
7+
largeValues,
8+
negativeGrowth,
9+
salesByProduct,
10+
} from './sample-data';
511
import type { Meta, StoryObj } from '@storybook/react';
612

713
const meta: Meta< typeof LeaderboardChart > = {
@@ -378,14 +384,9 @@ export const CustomLabel: Story = {
378384
data: smallDataset.map( entry => ( {
379385
...entry,
380386
label: (
381-
<div style={ { display: 'flex', alignItems: 'center', gap: '8px' } }>
382-
<img
383-
src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23e25555' viewBox='0 0 24 24'%3E%3Cpath d='M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41 0.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z'/%3E%3C/svg%3E"
384-
alt="icon"
385-
style={ { width: '32px', height: '32px', marginLeft: '8px', verticalAlign: 'middle' } }
386-
/>
387-
<span style={ { fontSize: '24px' } }>{ entry.label }</span>
388-
</div>
387+
<span style={ { fontSize: '24px', padding: '8px 16px', color: '#EEEEEE' } }>
388+
{ entry.label }
389+
</span>
389390
),
390391
} ) ),
391392
withComparison: false,
@@ -455,3 +456,48 @@ export const WooCommerceTheme: Story = {
455456
),
456457
],
457458
};
459+
460+
export const WooAnalyticsSalesByProduct: Story = {
461+
args: {
462+
data: salesByProduct.map( entry => ( {
463+
...entry,
464+
label: (
465+
<div
466+
style={ {
467+
display: 'flex',
468+
alignItems: 'center',
469+
gap: '8px',
470+
padding: '6px',
471+
} }
472+
>
473+
<img
474+
src={ `data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='50' height='50'><rect width='50' height='50' fill='${ entry.color }'/></svg>` }
475+
alt="icon"
476+
style={ {
477+
width: '28px',
478+
height: '28px',
479+
verticalAlign: 'middle',
480+
borderRadius: '4px',
481+
} }
482+
/>
483+
<span style={ { fontSize: '13px' } }>{ entry.label }</span>
484+
</div>
485+
),
486+
} ) ),
487+
primaryColor: '#F0F2FD',
488+
withComparison: true,
489+
withOverlayLabel: true,
490+
loading: false,
491+
style: {
492+
'--bar-border-radius': '4px',
493+
fontFamily: `"SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif`,
494+
},
495+
},
496+
decorators: [
497+
Story => (
498+
<ThemeProvider theme={ wooTheme }>
499+
<Story />
500+
</ThemeProvider>
501+
),
502+
],
503+
};

projects/js-packages/charts/src/components/leaderboard-chart/stories/sample-data.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,36 @@ export const negativeGrowth: LeaderboardEntry[] = [
119119
delta: -6.25,
120120
},
121121
];
122+
123+
export const salesByProduct: ( LeaderboardEntry & { color: string } )[] = [
124+
{
125+
id: 'direct',
126+
label: 'Direct',
127+
currentValue: 12500,
128+
previousValue: 10000,
129+
currentShare: 100,
130+
previousShare: 80,
131+
delta: 25,
132+
color: '%23007aff',
133+
},
134+
{
135+
id: 'social',
136+
label: 'Social Media',
137+
currentValue: 8750,
138+
previousValue: 9500,
139+
currentShare: 70,
140+
previousShare: 76,
141+
delta: -7.9,
142+
color: '%23ffc0cb',
143+
},
144+
{
145+
id: 'referral',
146+
label: 'Referral',
147+
currentValue: 8750,
148+
previousValue: 9500,
149+
currentShare: 10,
150+
previousShare: 16,
151+
delta: -7.9,
152+
color: '%2300ff00',
153+
},
154+
];

0 commit comments

Comments
 (0)