Skip to content

Conversation

@lyjeileen
Copy link
Collaborator

@lyjeileen lyjeileen commented May 16, 2024

Changes

  • Add vega-lite component, stories and tests

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

Screenshots

Screenshot 2024-05-16 at 12 09 30 AM

Screenshot 2024-05-17 at 4 16 01 PM

Screenshot 2024-05-16 at 12 10 18 AM

}, [])

if (hasError) {
return <Typography variant="body2">Failed to load the chart.</Typography>
Copy link
Collaborator

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?

Copy link
Collaborator Author

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?

Copy link
Collaborator

@kaseyvee kaseyvee May 16, 2024

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

Copy link
Contributor

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. */
Copy link
Collaborator

@kaseyvee kaseyvee May 16, 2024

Choose a reason for hiding this comment

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

Suggested change
/** 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. */

Copy link
Contributor

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

Copy link
Collaborator Author

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?

Copy link
Contributor

@Shiti Shiti May 16, 2024

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 ?

@lyjeileen lyjeileen requested a review from Shiti May 16, 2024 16:46
@kaseyvee
Copy link
Collaborator

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:
Screenshot 2024-05-16 at 9 57 35 AM

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. */
Copy link
Contributor

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
Copy link
Contributor

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)
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
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'
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
import { default as embed } from 'vega-embed'
import { default as VegaEmbed } from 'vega-embed'

decorators,
}

export const ErrorBars = {
Copy link
Contributor

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 = {
Copy link
Contributor

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 {
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

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';

Copy link
Collaborator Author

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?

Copy link
Contributor

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

@lyjeileen lyjeileen force-pushed the vega-lite branch 2 times, most recently from 44e5824 to 8a498d3 Compare May 17, 2024 21:25

VegaLiteChart.defaultProps = {
theme: {
dark: 'dark' as const,
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
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' },
},
},
Copy link
Contributor

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

Copy link
Collaborator Author

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">
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
<Stack direction="column" className="rustic-responsive-chart">
<Stack direction="column" className="rustic-chart">

Shiti
Shiti previously approved these changes May 17, 2024
'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.',
Copy link
Collaborator

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.

Copy link
Contributor

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

Copy link
Collaborator

@kaseyvee kaseyvee left a 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

@Shiti Shiti merged commit c3fb4fc into rustic-ai:main May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants