Skip to content
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

Feature/charts package #1648

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Feature/charts package #1648

wants to merge 8 commits into from

Conversation

natanfernandes
Copy link

@natanfernandes natanfernandes commented Jun 13, 2024

Summary

The @vtex/shoreline-charts library wraps echarts in a react component with consistent theming.

Default styles

@vtex/shoreline-charts will contains default styles for all chart, in order to get a easy setup for a chart, in this PR we've a demo with the Bar chart.
For the default styles we have variants, which is a pre-defined attributes on theme in addition to a pre-defined values to the series itself, but the user is free to edit and customize the chart as your own.

Installation

pnpm add @vtex/shoreline @vtex/shoreline-charts echarts

Examples

Simple chart setup

<Chart 
  option={{
    xAxis: {
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    series: {
      data: [1, 2, 3, 4, 5, 6, 7]
    }
  }} 
  type="bar" 
  style={{
    height: 550
  }} 
/>

Captura de Tela 2024-06-11 às 16 20 11

Variant chart

<Chart 
  option={{
    xAxis: {
      data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
   series: [{
      data: [1, 2, 3, 4, 5, 6, 7]
    }, {
      data: [1, 4, 2, 1, 4, 3, 5]
    }]
  }} 
  type="bar" 
  variant="horizontal"
  style={{
    height: 550
  }} 
/>

Captura de Tela 2024-06-11 às 16 22 38

@natanfernandes natanfernandes requested a review from a team as a code owner June 13, 2024 14:53
Copy link

vercel bot commented Jun 13, 2024

Deployment failed with the following error:

You don't have permission to create a Preview Deployment for this project.

View Documentation: https://vercel.com/docs/accounts/team-members-and-roles

@natanfernandes natanfernandes mentioned this pull request Jun 13, 2024
Comment on lines +1 to +16
export const CATEGORICAL = {
primary: '#014592',
secondary: '#9C56F3',
tertiary: '#0D504D',
quaternary: '#CA226A',
quinary: '#F95D47',
senary: '#5C12B6',
septenary: '#08A822',
octonary: '#EF5997',
nonary: '#157BF4',
denary: '#B18D01',
undenary: '#013A5E',
duodenary: '#01A29B;',
ternary: '#B24D01',
fourteen: '#720000',
}
Copy link
Contributor

@matheusps matheusps Jun 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks to me that this naming could be simpler. For example: 100, 200, 300, 400, 500... OR 1, 2, 3, 4, 5... You would write less and semantic actually gets lost after quaternary, for example. What do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can achieve a better way to name it, for now i'm was following the token names defined in Figma

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about this naming, @beatrizmilhomem, @davicostalf ?

"react-dom": "18.x"
},
"devDependencies": {
"@types/lodash": "^4.17.4",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"@types/lodash": "^4.17.4",

"dependencies": {
"@vtex/shoreline-utils": "workspace:*",
"echarts-for-react": "^3.0.2",
"lodash": "^4.17.21",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're not using it, right?

Suggested change
"lodash": "^4.17.21",

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, i'll remove it

"@vtex/shoreline-utils": "workspace:*",
"echarts-for-react": "^3.0.2",
"lodash": "^4.17.21",
"vitest": "^1.6.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vistest is already on the global scope.

Suggested change
"vitest": "^1.6.0",

* Render a Shoreline Chart with echarts
* @see https://echarts.apache.org/en/index.html
*/
export const Chart = forwardRef<echarts.EChartsType | undefined, ChartProps>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this undefined?

Copy link
Author

@natanfernandes natanfernandes Jun 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was facing a type error with ref, on the useImperativeHandle and tried the undefined

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this echarts.ECartsType return? Some HTMLDivElement?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It returns the Chart instance, the same as in chartRef.current.getEchartsInstance()

Comment on lines 53 to 58
useEffect(() => {
window.addEventListener('resize', handleResize)
return () => {
window.removeEventListener('resize', handleResize)
}
}, [handleResize])
Copy link
Contributor

@matheusps matheusps Jun 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add a check for dom. It is useful for SSR. You can use the canUseDom util from @vtex/shoreline utils

Suggested change
useEffect(() => {
window.addEventListener('resize', handleResize)
return () => {
window.removeEventListener('resize', handleResize)
}
}, [handleResize])
useEffect(() => {
if(!canUseDom) return
window.addEventListener('resize', handleResize)
return () => {
window.removeEventListener('resize', handleResize)
}
}, [handleResize])

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice tip!

@matheusps matheusps added design wanted Indicates that additional help or expertise from design is needed to address the issue dev wanted Indicates that additional help or expertise from engineering is needed to address the issue. labels Jun 17, 2024
@matheusps
Copy link
Contributor

An API question: What will happen to the variant property when you add another chart (type)? Every chart type will have an "horizontal" variant?

@natanfernandes
Copy link
Author

natanfernandes commented Jun 17, 2024

An API question: What will happen to the variant property when you add another chart (type)? Every chart type will have an "horizontal" variant?

After implement the variant this case come to my mind, at this moment, just bar has the horizontal variant, the first solution that i thought was when the type hasnt the variant, return the default. Second solution is create the variant type according to the type variants, like bar.horizontal or something but seems to be more complex

@natanfernandes
Copy link
Author

I moved the type and variant props to chartConfig, by this we can validate the variant according to the type

@matheusps matheusps added the blocked Blocked by some reason label Jun 20, 2024
@matheusps
Copy link
Contributor

Updating the status, @beatrizmilhomem and @davicostalf are checking the design part of the PR.

@beatrizmilhomem beatrizmilhomem linked an issue Jun 24, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Blocked by some reason design wanted Indicates that additional help or expertise from design is needed to address the issue dev wanted Indicates that additional help or expertise from engineering is needed to address the issue.
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Charts
2 participants