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

using mermaid in vue3[svgElem.node(...).getBBox] #5401

Open
ToBeNiceMan opened this issue Mar 22, 2024 · 1 comment
Open

using mermaid in vue3[svgElem.node(...).getBBox] #5401

ToBeNiceMan opened this issue Mar 22, 2024 · 1 comment
Labels
Status: Triage Needs to be verified, categorized, etc

Comments

@ToBeNiceMan
Copy link

my project like this

  <div style="width: 100%; height: 100%;">
    <div ref="chartContainer" id="mermaidChart" class="chartClass">
    </div>
  </div>
</template>
<script setup>
import { ref, onMounted } from 'vue';
import mermaid from 'mermaid';
import { convertToMermaid } from '@/utils/convertToMermaid.js';

const props = defineProps({
  nodes: Array,
  edges: Array
});

const chartContainer = ref(null);

const initializeMermaid = () => {
  const config = {
    "startOnLoad": true,
}
  mermaid.initialize(config);
  
};


const setupMermaidGraphs = () => {

  // const chartDefinition = convertToMermaid(props.nodes, props.edges);
  const chartDefinition = `graph TD
    A[Enter Chart Definition] --> B(Preview)
    B --> C{decide}
    C --> D[Keep]
    C --> E[Edit Definition]
    E --> B
    D --> F[Save Image and Code]
    F --> B`;
  console.log('chartDefinition', chartDefinition);
  console.log('mermaid', mermaid);
  
  // mermaid.render("chartContainer", chartDefinition)
  // 异步方法
  mermaid.mermaidAPI.render("mermaidChart", chartDefinition, chartContainer.value)


}

onMounted(async () => {
  await initializeMermaid();
  setupMermaidGraphs();
});


</script>

<style scoped>
.chartClass {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
}
</style>

browser console err with chunk-5EJBOFBL.js?v=f39a814a:14270 Uncaught (in promise) TypeError: svgElem.node(...).getBBox is not a function

and webpage display with
image

how to fix?

@github-actions github-actions bot added the Status: Triage Needs to be verified, categorized, etc label Mar 22, 2024
@AntoniJakubiak
Copy link

Hi,

Try this:

<template>
  <div style="width: 100%; height: 100%;">
    <div ref="chartContainer" id="mermaidChart"></div>
  </div>
</template>
<script setup>
import {ref, onMounted} from 'vue';
import mermaid from 'mermaid';

const chartContainer = ref(null);

const initializeMermaid = async () => {
  mermaid.initialize({
    startOnLoad: false,
  });
  const chartDefinition = `
      graph TD;
      A[Enter Chart Definition] --> B(Preview);
      B --> C{decide};
      C --> D[Keep];
      C --> E[Edit Definition];
      E --> B;
      D --> F[Save Image and Code];
      F --> B;
  `;

  const renderResult = await mermaid.render("newMermaidChart", chartDefinition, chartContainer.value);
  chartContainer.value.innerHTML = renderResult.svg;

};


onMounted(async () => {
  await initializeMermaid();
});

</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage Needs to be verified, categorized, etc
Projects
None yet
Development

No branches or pull requests

2 participants