-
Notifications
You must be signed in to change notification settings - Fork 170
feat: add bar charts #2924
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: add bar charts #2924
Changes from all commits
Commits
Show all changes
119 commits
Select commit
Hold shift + click to select a range
e7e3ef4
feat: line chart pocs
tewarig 4513e87
fix: lint
tewarig f38b3ec
chore: pie charts
tewarig 76ed2c6
feat: add area charts
tewarig 27f260f
Merge remote-tracking branch 'origin' into feat/recharts-poc
tewarig b2e5fae
feat: add line chart
tewarig 26c822b
refactor: charts and base components
tewarig 8310cb2
chore: code refactor
tewarig b14f469
fix: line chart styling and offset colors
tewarig 9e0f88f
fix: legend color in recharts
tewarig de5d214
chore: update legend styles
tewarig d3fed65
fix: add color in reference line
tewarig da0d881
chore: update color tokens
tewarig f177c6f
chore: add lable in chart
tewarig 9b45b94
fix: spacing
tewarig 5f2530e
fix: add custom label
tewarig 1aa02c5
feat: add colors
tewarig 7efc234
feat: support new colors in line charts & colors update
tewarig 263731a
chore: update color logic & exmaple color values
tewarig ab4bd23
chore: update blade color theme
tewarig b60d9a9
refactor: reference line props
tewarig ee3d062
fix: more color props
tewarig 1311652
fix: line chart errors
tewarig 67d5518
fix: ts errors
tewarig 201f28d
chore: more update
tewarig 535ca53
chore: more style changes
tewarig 5d23d9c
chore: change vars
tewarig 806a8fd
feat: add line charts
tewarig 3cf1ba3
chore: update cursor values
tewarig 5282030
chore: revert changes
tewarig cf58f98
chore: update spacing
tewarig 261e123
feat: inital code for area charts
tewarig 1338253
chore: area charts
tewarig 8524a8c
chore: code refactor
tewarig fe8a5e8
chore: refactor responsive container
tewarig 82b5f1a
chore: added more example
tewarig 0a48c83
chore: update types
tewarig 68899ea
chore: make x and y optional
tewarig 3a7547d
chore: add x and y props
tewarig 41f667f
chore: update area charts
tewarig 3dd2bda
refactor: area chart changes
tewarig f246bb1
feat: initial commit
tewarig baa2c22
chore: add spacing b/w charts
tewarig c28022e
fix: gap b/w bar charts
tewarig 8de429c
chore: update example
tewarig 36fa5d6
chore: remove cursor from tooltip
tewarig 36f1c12
fix: make animation work
tewarig e8dda48
chore: update final review
tewarig 26bbf54
feat: update color theme token
tewarig 85588b6
feat: expose color theme
tewarig 0aa935f
feat: update line charts
tewarig 016e9e3
fix: update snaps
tewarig eaaf45f
chore: add review notes
tewarig e1f8a97
fix: change to vairables
tewarig befed08
chore: more changes
tewarig 67696cf
Create calm-peas-work.md
tewarig a221c55
Merge remote-tracking branch 'origin' into feat/add-area-charts
tewarig fc7d69a
Merge remote-tracking branch 'origin' into feat/add-line-charts
tewarig 1a00f8f
Merge branch 'feat/add-line-charts' into feat/add-area-charts
tewarig 23e3cc0
chore: more code changes
tewarig 9d76c53
Merge branch 'feat/add-line-charts' into feat/add-area-charts
tewarig f5dae27
fix: update name
tewarig dbf3912
feat: update area charts to support color tokens
tewarig 1c0388a
Merge branch 'feat/add-area-charts' into feat/add-bar-charts
tewarig c4f1e3a
feat: update bar charts for review
tewarig e2e367b
chore: errors in charts
tewarig df8de7e
chore: update animation token and colors
tewarig 1992e99
fea: update bar charts
tewarig dd70df0
Merge remote-tracking branch 'origin' into feat/add-line-charts
tewarig 1f0df67
Revert "feat: add area charts" (#2936)
tewarig a5d6fd7
Merge branch 'feat/add-line-charts' into feat/add-area-charts
tewarig c5005a5
Merge branch 'feat/add-area-charts' into feat/add-bar-charts
tewarig bdb7bc7
chore: update change set
tewarig d70e2ab
review: update export types
tewarig 62efbbe
chore: update example
tewarig 049e0e0
fix: update baseChart components
tewarig c58ff8b
chore: update forecasted data
tewarig 3428965
Merge branch 'feat/add-line-charts' into feat/add-area-charts
tewarig e9c1bd9
chore: add changeset
tewarig f9e046b
feat: add bar chart
tewarig 94da90d
fix: add bar chart
tewarig 8449366
chore: remove logs from bar chart
tewarig 3aa90bb
chore: sync with master
tewarig 9b8e700
Merge remote-tracking branch 'origin' into feat/add-bar-charts
tewarig 0ab2051
refactor: bar charts
tewarig 2b3e8f4
fix: add area chart types
tewarig 4ae36ec
feat: add test cases
tewarig 2afee81
feat: add bar chart
tewarig 4083df8
feat: add changset
tewarig be35727
fix: update bar chart
tewarig 023b593
fix: opacity
tewarig eff0834
fix: bar chart review
tewarig 213613e
fix: bar chart review
tewarig d02a393
chore: update mcp docs
tewarig ef9eda0
chore: resolve review comments
tewarig e0df6a2
fix:linting issue
tewarig b1daa9c
chore: update lint
tewarig b5f4511
chore: rename chartBarwrapper
tewarig c07dff3
fix: update opacity
tewarig 08ded0a
fix: set animation easing to linear
tewarig f80e366
chore: export types
tewarig 27ffef4
feat: update chart layout
tewarig 1f88647
chore: rename to charts
tewarig 4bd36fa
chore: rename story
tewarig a3bc3e9
chore: update barchart stories
tewarig 2deae8c
fix: add animation
tewarig fd2825b
fix: animation speed
tewarig 51d9688
fix: animation logic and stacked bar logic
tewarig c8892f7
chore: more animation fixes
tewarig 6346b23
fix: update animation
tewarig 0283740
chore: update snaps
tewarig e23e82a
fix: ts issue
tewarig e9c088d
chore: add stacking
tewarig 8fd2bff
refactor: code animation
tewarig 01535f7
chore: update snaps
tewarig e3a8769
chore: remove animation :(
tewarig 5328255
review: change orientation to layout
tewarig 4fc94f2
chore: update layout
tewarig 37cb2c4
chore: update types
tewarig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@razorpay/blade': minor | ||
--- | ||
|
||
feat(blade): add BarChart component | ||
|
||
[Docs Link](https://blade.razorpay.com/?path=/docs/components-charts-barchart--docs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@razorpay/blade-mcp': minor | ||
--- | ||
|
||
feat(blade-mcp): update knowledgebase with BarChart |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
178 changes: 178 additions & 0 deletions
178
packages/blade-mcp/knowledgebase/components/BarChart.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
# BarChart | ||
|
||
## Component Name | ||
|
||
BarChart | ||
|
||
## Description | ||
|
||
BarChart is a comprehensive data visualization component that renders interactive bar charts with support for grouped, stacked, and vertical layouts. It provides customizable colors, animations, and interactive features like hover states and tooltips. The component is built on top of Recharts and integrates seamlessly with Blade's design system, offering consistent styling and accessibility features. BarChart supports multiple data series, custom color themes, and various chart configurations for displaying categorical data effectively. | ||
|
||
## Important Constraints | ||
|
||
- `ChartBarWrapper` component only accepts `ChartBar`, `ChartXAxis`, `ChartYAxis`, `ChartCartesianGrid`, `ChartTooltip`, `ChartLegend`, and `ChartReferenceLine` components as children. | ||
- `data` prop is required and must be an array of objects with consistent data structure | ||
- `dataKey` prop is required for each `ChartBar` component and must correspond to a property in the data array | ||
- `stackId` must be consistent across all bars that should be stacked together | ||
- `layout="vertical"` requires `ChartXAxis` to have `type="number"` and `ChartYAxis` to have `type="category"` | ||
- Color tokens must follow the exact format: `chart.background.categorical.{color}.{emphasis}` or `chart.background.sequential.{color}.{number}` | ||
|
||
## TypeScript Types | ||
|
||
These types define the props that the BarChart component and its subcomponents accept: | ||
|
||
```typescript | ||
type ChartBarProps = Omit<RechartsBarProps, 'fill' | 'dataKey' | 'name' | 'label' | 'activeBar'> & { | ||
/** | ||
* The data key of the bar chart. | ||
*/ | ||
dataKey: RechartsBarProps['dataKey']; | ||
/** | ||
* The name of the bar chart. | ||
*/ | ||
name?: RechartsBarProps['name']; | ||
/** | ||
* The color of the bar chart. | ||
*/ | ||
color?: ChartsCategoricalColorToken | ChartSequentialColorToken; | ||
/** | ||
* The stack id of the bar chart. | ||
*/ | ||
stackId?: RechartsBarProps['stackId']; | ||
/** | ||
* The active bar of the bar chart. | ||
*/ | ||
activeBar?: RechartsBarProps['activeBar']; | ||
/** | ||
* The label of the bar chart. | ||
*/ | ||
label?: RechartsBarProps['label']; | ||
/** | ||
* The show legend of the bar chart. | ||
*/ | ||
showLegend?: boolean; | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no showLegend prop? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
|
||
type data = { | ||
[key: string]: unknown; | ||
}; | ||
|
||
type ChartBarWrapperProps = { | ||
children?: React.ReactNode; | ||
/** | ||
* The color theme of the bar chart. | ||
*/ | ||
colorTheme?: colorTheme; | ||
/** | ||
* The orientation of the bar chart. | ||
*/ | ||
layout?: 'horizontal' | 'vertical'; | ||
swapnil-kr1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* Chart data to be rendered | ||
*/ | ||
data: data[]; | ||
} & BoxProps; | ||
|
||
|
||
type ChartsCategoricalColorToken = `chart.background.categorical.${ChartColorCategories}.${keyof ChartCategoricalEmphasis}`; | ||
|
||
type ChartSequentialColorToken = `chart.background.sequential.${Exclude<ChartColorCategories, 'gray'>}.${keyof ChartSequentialEmphasis}`; | ||
|
||
type colorTheme = 'default'; | ||
|
||
type ChartXAxisProps = Omit<RechartsXAxisProps, 'tick' | 'label' | 'dataKey' | 'stroke'> & { | ||
/** | ||
* The label of the x-axis. | ||
*/ | ||
label?: string; | ||
/** | ||
* The data key of the x-axis. | ||
*/ | ||
dataKey?: string; | ||
}; | ||
|
||
type ChartYAxisProps = Omit<RechartsYAxisProps, 'tick' | 'label' | 'dataKey' | 'stroke'> & { | ||
/** | ||
* The label of the y-axis. | ||
*/ | ||
label?: string; | ||
/** | ||
* The data key of the y-axis. | ||
*/ | ||
dataKey?: string; | ||
}; | ||
|
||
type ChartTooltipProps = ComponentProps<typeof RechartsTooltip>; | ||
|
||
type ChartLegendProps = ComponentProps<typeof RechartsLegend>; | ||
|
||
type ChartCartesianGridProps = Omit<RechartsCartesianGridProps, 'strokeDasharray' | 'verticalFill' | 'horizontalFill'>; | ||
|
||
type ChartReferenceLineProps = { | ||
/** | ||
* The y-coordinate of the reference line. | ||
*/ | ||
y?: RechartsReferenceLineProps['y']; | ||
/** | ||
* The x-coordinate of the reference line. | ||
*/ | ||
x?: RechartsReferenceLineProps['x']; | ||
/** | ||
* The label of the reference line. | ||
*/ | ||
label: string; | ||
}; | ||
``` | ||
|
||
## Example | ||
|
||
### Basic BarChart with Multiple Series | ||
|
||
```tsx | ||
import React from 'react'; | ||
import { | ||
ChartBar, | ||
ChartBarWrapper, | ||
ChartXAxis, | ||
ChartYAxis, | ||
ChartCartesianGrid, | ||
ChartTooltip, | ||
ChartLegend, | ||
} from '@razorpay/blade/components'; | ||
|
||
const salesData = [ | ||
{ month: 'Jan', revenue: 4000, profit: 2000, expenses: 1000 }, | ||
{ month: 'Feb', revenue: 3000, profit: 1500, expenses: 800 }, | ||
{ month: 'Mar', revenue: 5000, profit: 3000, expenses: 1200 }, | ||
{ month: 'Apr', revenue: 4500, profit: 2500, expenses: 1100 }, | ||
]; | ||
|
||
const BasicBarChart = () => { | ||
return ( | ||
<div style={{ width: '100%', height: '400px' }}> | ||
<ChartBarWrapper data={salesData}> | ||
<ChartCartesianGrid /> | ||
<ChartXAxis dataKey="month" /> | ||
<ChartYAxis /> | ||
<ChartTooltip /> | ||
<ChartLegend /> | ||
<ChartBar | ||
dataKey="revenue" | ||
name="Revenue" | ||
color="chart.background.categorical.azure.moderate" | ||
/> | ||
<ChartBar | ||
dataKey="profit" | ||
name="Profit" | ||
color="chart.background.categorical.emerald.moderate" | ||
/> | ||
<ChartBar | ||
dataKey="expenses" | ||
name="Expenses" | ||
color="chart.background.categorical.crimson.moderate" | ||
/> | ||
</ChartBarWrapper> | ||
</div> | ||
); | ||
}; | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/blade/src/components/Charts/BarChart/BarChart.native.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import React from 'react'; | ||
import type { ChartBarProps, ChartBarWrapperProps } from './types'; | ||
import { Text } from '~components/Typography'; | ||
import { throwBladeError } from '~utils/logger'; | ||
|
||
const ChartBar = (_prop: ChartBarProps): React.ReactElement => { | ||
throwBladeError({ | ||
message: 'ChartBar is not yet implemented for native', | ||
moduleName: 'ChartBar', | ||
}); | ||
|
||
return <Text>ChartBar is not available for Native mobile apps.</Text>; | ||
}; | ||
|
||
const ChartBarWrapper = (_prop: ChartBarWrapperProps): React.ReactElement => { | ||
throwBladeError({ | ||
message: 'ChartBarWrapper is not yet implemented for native', | ||
moduleName: 'ChartBarWrapper', | ||
}); | ||
|
||
return <Text>ChartLine is not available for Native mobile apps.</Text>; | ||
}; | ||
|
||
export type { ChartBarProps, ChartBarWrapperProps }; | ||
export { ChartBar, ChartBarWrapper }; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.