- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 12
feat: add vega-lite #137
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
feat: add vega-lite #137
Conversation
| }, []) | ||
|  | ||
| if (hasError) { | ||
| return <Typography variant="body2">Failed to load the chart.</Typography> | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there other ways of triggering the error? In storybook you use "invalid chart"- do we want to recommend to check the spec or schema?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't think of other error cases. I thought about mentioning invalid spec in the error message, but end users might not have any controls for that. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
End users might not be able to control directly but I'm thinking maybe it might help them try to refine their prompt? Like if speaking to say, an agent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think we should worry too much about this. This error message is ok
| export type TableData = TableFormat & Updates<TableFormat> | ||
|  | ||
| export interface VegaLiteChartFormat extends DataFormat { | ||
| /** Follow Vega-lite's [documentation](https://vega.github.io/vega-lite/) to provide a specification object. Schema should be included in the spec. Need to use 'container' for width or height for responsive chart. */ | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /** Follow Vega-lite's [documentation](https://vega.github.io/vega-lite/) to provide a specification object. Schema should be included in the spec. Need to use 'container' for width or height for responsive chart. */ | |
| /** Follow Vega-lite's [documentation](https://vega.github.io/vega-lite/) to provide a specification object. Schema should be included in the spec. Set width or height to 'container' in the spec for a responsive chart. */ | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice if we could automatically do this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you suggesting having default value if width and height are not provided?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was suggesting that we force the chart to be responsive by adding the required properties to the spec. Is that possible ?
| Maybe in a follow up but maybe we can look into applying the theme colours. I think changing background and text for now would be sufficient since dark mode looks like this: Saw some examples here. | 
| export type TableData = TableFormat & Updates<TableFormat> | ||
|  | ||
| export interface VegaLiteChartFormat extends DataFormat { | ||
| /** Follow Vega-lite's [documentation](https://vega.github.io/vega-lite/) to provide a specification object. Schema should be included in the spec. Need to use 'container' for width or height for responsive chart. */ | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice if we could automatically do this
|  | ||
| export interface VegaLiteChartFormat extends DataFormat { | ||
| /** Follow Vega-lite's [documentation](https://vega.github.io/vega-lite/) to provide a specification object. Schema should be included in the spec. Need to use 'container' for width or height for responsive chart. */ | ||
| spec: VisualizationSpec | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
VisualizationSpec and DataFormat both have the fields title and description. How are the two handled/rendered differently ? Could we add an example ?
| if (chartRef.current && props.spec) { | ||
| embed(chartRef.current, props.spec) | ||
| .then(() => { | ||
| hasError && setHasError(false) | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| hasError && setHasError(false) | |
| setHasError(false) | 
|  | ||
| import Typography from '@mui/material/Typography' | ||
| import React, { useEffect, useRef, useState } from 'react' | ||
| import { default as embed } from 'vega-embed' | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| import { default as embed } from 'vega-embed' | |
| import { default as VegaEmbed } from 'vega-embed' | 
| decorators, | ||
| } | ||
|  | ||
| export const ErrorBars = { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think we need to add this. We dont need to cover all the charts vega-lite supports in the samples. Also, I got confused with the name of this story.
| decorators, | ||
| } | ||
|  | ||
| export const Scatterplot = { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove this one as well. We dont need to have data files to indicate it works with vega-lite spec.
|  | ||
| export type TableData = TableFormat & Updates<TableFormat> | ||
|  | ||
| export interface VegaLiteChartFormat extends DataFormat { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be useful to provide option to configure theme as well ?
https://github.com/vega/vega-themes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we could use 'default' when light theme and 'dark' with dark theme by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the current theme can be checked using useTheme. for example,
 const isDarkTheme = useTheme().palette.mode === 'dark';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to provide a theme props and let people override dark and light theme?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes we could do that and set default values
44e5824    to
    8a498d3      
    Compare
  
    |  | ||
| VegaLiteChart.defaultProps = { | ||
| theme: { | ||
| dark: 'dark' as const, | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| dark: 'dark' as const, | |
| dark: 'dark' as const, | |
| light: 'default' as const, | 
| x: { field: 'a', type: 'nominal', axis: { labelAngle: 0 } }, | ||
| y: { field: 'b', type: 'quantitative' }, | ||
| }, | ||
| }, | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should update this vega-lite spec to have title and description as well and showcase how having both looks like. So, there should be two titles and descriptions. One which is a sub-heading and has a following paragraph from the DataFormat props and the second for the chart, focusing on the chart's title and description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vega-lite's description is only for commenting purpose and won't be rendered, but I could add them here
| return <Typography variant="body2">Failed to load the chart.</Typography> | ||
| } else { | ||
| return ( | ||
| <Stack direction="column" className="rustic-responsive-chart"> | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <Stack direction="column" className="rustic-responsive-chart"> | |
| <Stack direction="column" className="rustic-chart"> | 
| 'A theme object has the following fields:\n' + | ||
| ' light: A light theme string that is supported by vega-themes.\n' + | ||
| ' dark: A dark theme string that is supported by vega-themes.\n' + | ||
| 'Refer to the [vega-themes](https://github.com/vega/vega-themes) documentation for more information.', | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part doesn't seem to be rendering correctly (the link). Maybe you can add it to the prop description instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think vega also accepts an object. I dont think we should restrict it to string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just moving the vega theme ref link to the prop description otherwise lgtm

Changes
Note: I didn't handle updates in this PR.
Screenshots