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

Set mermaid configuration #1326

Closed
GuillaumeDesforges opened this issue Sep 3, 2022 · 6 comments · Fixed by #1413
Closed

Set mermaid configuration #1326

GuillaumeDesforges opened this issue Sep 3, 2022 · 6 comments · Fixed by #1413
Labels
👶 good first issue Good for newcomers 🍩 enhancement New feature or request ☕ java Related to Java code 📜 javascript Related to Javascript code 👋 help wanted Help wanted!

Comments

@GuillaumeDesforges
Copy link

Mermaid has a bunch of features that need to be set at configuration level, such as mainBranchName for gitGraph.

Would it be possible to change mermaid configuration in a HTTP call?

@ggrossetie ggrossetie added 🍩 enhancement New feature or request 👋 help wanted Help wanted! 👶 good first issue Good for newcomers ☕ java Related to Java code 📜 javascript Related to Javascript code labels Sep 4, 2022
@ggrossetie
Copy link
Member

Hello Guillaume,

Technically, that's possible now that we accept a list of options and propagate them to the companion containers.
However, the Mermaid companion server does not retrieve the query parameters but it's possible to do so in:

const server = micro(async (req, res) => {
// TODO: add a /_status route (return mermaid version)
// TODO: read the diagram source as plain text
const outputType = req.url.match(/\/(png|svg)$/)?.[1]
if (outputType) {
const diagramSource = await micro.text(req, { limit: '1mb', encoding: 'utf8' })
if (diagramSource) {
try {
const isPng = outputType === 'png'
const output = await worker.convert(new Task(diagramSource, isPng))
res.setHeader('Content-Type', isPng ? 'image/png' : 'image/svg+xml')
return micro.send(res, 200, output)
} catch (e) {
if (e instanceof SyntaxError) {
return micro.send(res, 400, e.message)
} else {
console.log('Exception during convert', e)
return micro.send(res, 500, 'An error occurred while converting the diagram')
}
}
}
return micro.send(res, 400, 'Body must not be empty.')
}
return micro.send(res, 400, 'Available endpoints are /svg and /png.')
})
server.listen(8002)

Then, we will need to update the Mermaid default config:

this.mermaidConfig = {
theme: 'default',
class: {
useMaxWidth: false
},
er: {
useMaxWidth: false
},
flowchart: {
useMaxWidth: false
},
gantt: {
useMaxWidth: false
},
git: {
useMaxWidth: false
},
journey: {
useMaxWidth: false
},
sequence: {
useMaxWidth: false
},
state: {
useMaxWidth: false
}
}
}

Do you want to give it a try?

@GuillaumeDesforges
Copy link
Author

Thanks, looks feasible.

I don't have the bandwidth to do it right now, so if anyone reading this wants it they should not rely on me implementing it.

@jhogendorn
Copy link

interested in this but from a different perspective, i'd like to be able to set kroki to have a default set of options for a given engine, or perhaps even a given referrer? ie, if wiki.mydomain.com calls a kroki diagram up, it can go 'oh, yep, the theme for that is this'.

@SayakMukhopadhyay
Copy link
Contributor

SayakMukhopadhyay commented Dec 30, 2022

Hi, I am a backstage user and I have the same requirement. I will make an attempt to implement this. Just one thing I need help on @Mogztter . How do I run the kroki-server locally, without using Docker and stuff. Preferably, is there a maven command that starts up kroki with a built in server like say spring-boot does?

EDIT:
Wait... do I just run main??? Seems like so...

@SayakMukhopadhyay
Copy link
Contributor

I have created a PR which partially fulfills this issue. For now, it will pretty much work with only theme option for mermaid. Ngl, theme is what I personally need but I am also confused as to how to implement the other configuration params so haven't really worked on them. Let me know what you folks think.

@ggrossetie
Copy link
Member

EDIT: Wait... do I just run main??? Seems like so...

Yes, the "gateway" server is a Vert.x stateless web app. You can indeed run the main 😉

I will make an attempt to implement this.

Thanks for contributing!

I have created a PR which partially fulfills this issue. For now, it will pretty much work with only theme option for mermaid. Ngl, theme is what I personally need but I am also confused as to how to implement the other configuration params so haven't really worked on them. Let me know what you folks think.

I will have a look this week-end 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👶 good first issue Good for newcomers 🍩 enhancement New feature or request ☕ java Related to Java code 📜 javascript Related to Javascript code 👋 help wanted Help wanted!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants