Skip to content

Commit

Permalink
fix: make themeVariables typesafe
Browse files Browse the repository at this point in the history
  • Loading branch information
ad1992 committed Jul 8, 2024
1 parent b263164 commit 1061231
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/mermaid/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const addDirective = (directive: MermaidConfig) => {
sanitizeDirective(directive);

// If the directive has a fontFamily, but no themeVariables, add the fontFamily to the themeVariables
if (directive.fontFamily && !directive.themeVariables?.fontFamily) {
if (directive.fontFamily && !directive.themeVariables.fontFamily) {
directive.themeVariables = { fontFamily: directive.fontFamily };
}

Expand Down
26 changes: 13 additions & 13 deletions packages/mermaid/src/diagrams/pie/pieRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,21 @@ export const draw: DrawDefinition = (text, id, _version, diagObj) => {
const arcs: d3.PieArcDatum<D3Section>[] = createPieArcs(sections);

const myGeneratedColors = [
themeVariables.pie1,
themeVariables.pie2,
themeVariables.pie3,
themeVariables.pie4,
themeVariables.pie5,
themeVariables.pie6,
themeVariables.pie7,
themeVariables.pie8,
themeVariables.pie9,
themeVariables.pie10,
themeVariables.pie11,
themeVariables.pie12,
themeVariables.pie1 || null,
themeVariables.pie2 || null,
themeVariables.pie3 || null,
themeVariables.pie4 || null,
themeVariables.pie5 || null,
themeVariables.pie6 || null,
themeVariables.pie7 || null,
themeVariables.pie8 || null,
themeVariables.pie9 || null,
themeVariables.pie10 || null,
themeVariables.pie11 || null,
themeVariables.pie12 || null,
];
// Set the color scale
const color: d3.ScaleOrdinal<string, 12, never> = scaleOrdinal(myGeneratedColors);
const color: d3.ScaleOrdinal<string, string | null, never> = scaleOrdinal(myGeneratedColors);

// Build the pie chart: each part of the pie is a path that we build using the arc function.
group
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/mermaid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ const runThrowsErrors = async function (

/**
* Used to set configurations for mermaid.
* This function should be called before the run function.
* This function should be called before the run function.
* @param config - Configuration object for mermaid.
*/

Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/mermaidAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,9 @@ const render = async function (
/**
* @param options - Initial Mermaid options
*/
function initialize(options: MermaidConfig = {}) {
function initialize(options: MermaidConfig = { themeVariables: {} }) {
// Handle legacy location of font-family configuration
if (options?.fontFamily && !options.themeVariables?.fontFamily) {
if (options?.fontFamily && !options.themeVariables.fontFamily) {
if (!options.themeVariables) {
options.themeVariables = {};
}
Expand Down

0 comments on commit 1061231

Please sign in to comment.