-
-
Notifications
You must be signed in to change notification settings - Fork 12
feat(mermaidViz): add mermaidViz component #175
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
Conversation
src/components/types.ts
Outdated
| export type VegaLiteData = VegaLiteFormat & Updates<VegaLiteFormat> | ||
|
|
||
| export interface MermaidFormat extends DataFormat { | ||
| /** Follow mermaid's [documentation](https://mermaid.js.org/intro/) to provide a code 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.
| /** Follow mermaid's [documentation](https://mermaid.js.org/intro/) to provide a code string. */ | |
| /** Follow Mermaid's [documentation](https://mermaid.js.org/intro/) to provide a code string. */ |
src/components/types.ts
Outdated
| export interface MermaidFormat extends DataFormat { | ||
| /** Follow mermaid's [documentation](https://mermaid.js.org/intro/) to provide a code string. */ | ||
| code: string | ||
| /** Follow mermaid's [documentation](https://mermaid.js.org/config/setup/README.html) to provide a config object. It's used for additional customizations. */ |
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 mermaid's [documentation](https://mermaid.js.org/config/setup/README.html) to provide a config object. It's used for additional customizations. */ | |
| /** Follow Mermaid's [documentation](https://mermaid.js.org/config/setup/README.html) to provide a config object. It's used for additional customizations. */ |
| tags: ['autodocs'], | ||
| parameters: { | ||
| layout: 'centered', | ||
| }, |
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.
| }, | |
| }, | |
| decorators: [ | |
| (Story: StoryFn) => { | |
| return ( | |
| <div | |
| style={{ | |
| width: 'clamp(250px, 70vw, 1000px)', | |
| }} | |
| > | |
| <Story /> | |
| </div> | |
| ) | |
| }, | |
| ] |
| const decorators = [ | ||
| (Story: StoryFn) => { | ||
| return ( | ||
| <div | ||
| style={{ | ||
| width: 'clamp(250px, 70vw, 1000px)', | ||
| }} | ||
| > | ||
| <Story /> | ||
| </div> | ||
| ) | ||
| }, | ||
| ] |
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.
| const decorators = [ | |
| (Story: StoryFn) => { | |
| return ( | |
| <div | |
| style={{ | |
| width: 'clamp(250px, 70vw, 1000px)', | |
| }} | |
| > | |
| <Story /> | |
| </div> | |
| ) | |
| }, | |
| ] |
| }, | ||
| ] | ||
|
|
||
| export const classDiagram = { |
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.
| export const classDiagram = { | |
| export const ClassDiagram = { |
| C -->|Two| E[iPhone] | ||
| C -->|Three| F[fa:fa-car Car]`, | ||
| }, | ||
| decorators, |
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.
| decorators, |
| PRODUCT-CATEGORY ||--|{ PRODUCT : contains | ||
| PRODUCT ||--o{ ORDER-ITEM : "ordered in"`, | ||
| }, | ||
| decorators, |
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.
| decorators, |
| decorators, | ||
| } | ||
|
|
||
| export const error = { |
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.
| export const error = { | |
| export const Error = { |
| args: { | ||
| code: '', | ||
| }, | ||
| decorators, |
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.
| decorators, |
| ) | ||
|
|
||
| cy.get(mermaidContainer).should('exist') | ||
| cy.get(mermaidContainer).contains('Christmas Shopping') |
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.
Should we do this to be explicit about assertions?
| cy.get(mermaidContainer).contains('Christmas Shopping') | |
| cy.get(mermaidContainer).should('contain', 'Christmas Shopping') |
|
I think the |
I was thinking using |
| ...props.config, | ||
| }) | ||
|
|
||
| mermaid.contentLoaded() |
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 be using mermaid.run instead. It allows more flexibility for the selectors and suppressing errors so that we can show custom error messages.
Refer - https://mermaid.js.org/config/usage.html#using-mermaid-run
src/components/types.ts
Outdated
| /** Follow Mermaid's [documentation](https://mermaid.js.org/intro/) to provide a code string. */ | ||
| code: 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.
| /** Follow Mermaid's [documentation](https://mermaid.js.org/intro/) to provide a code string. */ | |
| code: string | |
| /** Diagram definition following [Mermaid's syntax](https://mermaid.js.org/intro/syntax-reference.html#syntax-structure). The use of [these](https://mermaid.js.org/intro/syntax-reference.html#diagram-breaking) words or symbols can break diagrams. */ | |
| diagram: string |
src/components/types.ts
Outdated
| export interface MermaidFormat extends DataFormat { | ||
| /** Follow Mermaid's [documentation](https://mermaid.js.org/intro/) to provide a code string. */ | ||
| code: string | ||
| /** Follow Mermaid's [documentation](https://mermaid.js.org/config/setup/README.html) to provide a config object. It's used for additional customizations. */ |
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 Mermaid's [documentation](https://mermaid.js.org/config/setup/README.html) to provide a config object. It's used for additional customizations. */ | |
| /** Configuration for altering and customizing Mermaid Diagrams. Refer [Mermaid docs](https://mermaid.js.org/config/schema-docs/config.html) for details. */ |
|
|
||
| /** The `MermaidViz` component leverages [Mermaid.js](https://mermaid.js.org/) to create dynamic and interactive diagrams, including flowcharts, sequence diagrams, class diagrams, and more. It is ideal for visualizing complex data and processes in a clear and structured manner. */ | ||
| function MermaidViz(props: MermaidData) { | ||
| const chartRef = useRef(null) |
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.
Please update the name for the variable and also specify the type of useRef
| <Stack | ||
| direction="column" | ||
| className="rustic-mermaid-container" | ||
| data-cy="mermaid-container" | ||
| > |
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.
any particular reason for using Stack instead of a simple div ?
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 wanted to avoid adding display: flex; flex-direction: column by using Stack.
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.
In a div, elements are rendered one below the other. why do we need flex ?
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 want mermaid div takes up the remaining space of its parent container. I used flex:1 in mermaid div and in order to make it work, its parent container needs to have display: flex
| .rustic-mermaid-container div:last-of-type { | ||
| flex: 1; | ||
| min-height: 0; | ||
| display: flex; | ||
| justify-content: center; | ||
| } | ||
|
|
||
| .rustic-mermaid-container div:last-of-type svg { | ||
| height: 100%; | ||
| width: 100%; | ||
| } |
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 use a custom class name. Also, its not clear why we are setting min-height to 0
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 will use a custom className. For min-height: 0, I can't make the diagram's height responsive without it.
| ) | ||
| }) | ||
| } | ||
| }, [mermaidTheme]) |
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 make mermaidTheme a local variable inside useEffect and set rusticTheme as dependency
| }, [mermaidTheme]) | |
| }, [rusticTheme]) |
I have noticed a similar issue with other components as well, some of them do not reload on theme change.
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.
Using rusticTheme doesn't fix the theme toggle issue.
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.
yeah thats also a constant.
| if (mermaidRef.current) { | ||
| mermaid.initialize({ | ||
| theme: mermaidTheme, | ||
| themeVariables: { fontFamily: 'Inter' }, |
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.
Please dont hard-code font.
| .catch(() => { | ||
| setIsProcessed(true) | ||
| setErrorMessage( | ||
| 'An error occurred while rendering the diagram. Please check the syntax.' |
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.
| 'An error occurred while rendering the diagram. Please check the syntax.' | |
| 'Failed to render the diagram.' |
|
|
||
| mermaid | ||
| .run({ | ||
| querySelector: '.rustic-mermaid', |
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 query selector is too generic and will apply to all the elements on the page with this class.
Change
mermaidVizcomponentScreenshot
Light mode
Dark mode
Error