mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-17 22:39:56 +02:00
feat(arch): added fallback icon
This commit is contained in:
@@ -3,12 +3,14 @@ import database from "./database.js";
|
||||
import server from "./server.js";
|
||||
import disk from "./disk.js";
|
||||
import internet from "./internet.js";
|
||||
import unknown from "./unknown.js";
|
||||
|
||||
const defaultIconLibrary: IconLibrary = {
|
||||
database: database,
|
||||
server: server,
|
||||
disk: disk,
|
||||
internet: internet,
|
||||
unknown: unknown,
|
||||
}
|
||||
|
||||
export default defaultIconLibrary
|
10
packages/mermaid/src/rendering-util/svg/unknown.ts
Normal file
10
packages/mermaid/src/rendering-util/svg/unknown.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* @author Nicolas Newman
|
||||
* @see https://github.com/NicolasNewman/IconLibrary
|
||||
*/
|
||||
import { createIcon } from "../svgRegister.js";
|
||||
|
||||
export default createIcon(`<g>
|
||||
<rect width="80" height="80" style="fill: #087ebf; stroke-width: 0px;"/>
|
||||
<text transform="translate(21.16 64.67)" style="fill: #fff; font-family: ArialMT, Arial; font-size: 67.75px;"><tspan x="0" y="0">?</tspan></text>
|
||||
</g>`, 80)
|
@@ -5,6 +5,13 @@ type IconResolver = (
|
||||
) => Selection<SVGGElement, unknown, Element | null, unknown>;
|
||||
type IconLibrary = Record<string, IconResolver>;
|
||||
|
||||
const createIcon = (icon: string, originalSize: number): IconResolver => {
|
||||
return (parent: Selection<SVGGElement, unknown, Element | null, unknown>, size: number = originalSize) => {
|
||||
parent.html(`<g style="transform: scale(${size / originalSize})">${icon}</g>`)
|
||||
return parent
|
||||
}
|
||||
}
|
||||
|
||||
const icons: IconLibrary = {};
|
||||
|
||||
const isIconNameInUse = (name: string): boolean => {
|
||||
@@ -29,14 +36,7 @@ const getIcon = (name: string): IconResolver | null => {
|
||||
if (isIconNameInUse(name)) {
|
||||
return icons[name];
|
||||
}
|
||||
return null; // TODO: return default
|
||||
return icons["unknown"];
|
||||
};
|
||||
|
||||
const createIcon = (icon: string, originalSize: number): IconResolver => {
|
||||
return (parent: Selection<SVGGElement, unknown, Element | null, unknown>, size: number = originalSize) => {
|
||||
parent.html(`<g style="transform: scale(${size / originalSize})">${icon}</g>`)
|
||||
return parent
|
||||
}
|
||||
}
|
||||
|
||||
export { registerIcon, registerIcons, getIcon, isIconNameInUse, createIcon, IconLibrary };
|
||||
|
Reference in New Issue
Block a user