Skip to content

Commit

Permalink
chore: Rename Group to SVGGroup
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthv96 committed Aug 21, 2024
1 parent f6e1515 commit 037ba2f
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 55 deletions.
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagram-api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,6 @@ export type HTML = d3.Selection<HTMLIFrameElement, unknown, Element | null, unkn

export type SVG = d3.Selection<SVGSVGElement, unknown, Element | null, unknown>;

export type Group = d3.Selection<SVGGElement, unknown, Element | null, unknown>;
export type SVGGroup = d3.Selection<SVGGElement, unknown, Element | null, unknown>;

export type DiagramStylesProvider = (options?: any) => string;
14 changes: 7 additions & 7 deletions packages/mermaid/src/diagrams/common/svgDrawCommon.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { sanitizeUrl } from '@braintree/sanitize-url';
import type { Group, SVG } from '../../diagram-api/types.js';
import type { SVG, SVGGroup } from '../../diagram-api/types.js';
import { lineBreakRegex } from './common.js';
import type {
Bound,
D3ImageElement,
Expand All @@ -11,9 +12,8 @@ import type {
TextData,
TextObject,
} from './commonTypes.js';
import { lineBreakRegex } from './common.js';

export const drawRect = (element: SVG | Group, rectData: RectData): D3RectElement => {
export const drawRect = (element: SVG | SVGGroup, rectData: RectData): D3RectElement => {
const rectElement: D3RectElement = element.append('rect');
rectElement.attr('x', rectData.x);
rectElement.attr('y', rectData.y);
Expand Down Expand Up @@ -50,7 +50,7 @@ export const drawRect = (element: SVG | Group, rectData: RectData): D3RectElemen
* @param element - Diagram (reference for bounds)
* @param bounds - Shape of the rectangle
*/
export const drawBackgroundRect = (element: SVG | Group, bounds: Bound): void => {
export const drawBackgroundRect = (element: SVG | SVGGroup, bounds: Bound): void => {
const rectData: RectData = {
x: bounds.startx,
y: bounds.starty,
Expand All @@ -64,7 +64,7 @@ export const drawBackgroundRect = (element: SVG | Group, bounds: Bound): void =>
rectElement.lower();
};

export const drawText = (element: SVG | Group, textData: TextData): D3TextElement => {
export const drawText = (element: SVG | SVGGroup, textData: TextData): D3TextElement => {
const nText: string = textData.text.replace(lineBreakRegex, ' ');

const textElem: D3TextElement = element.append('text');
Expand All @@ -84,7 +84,7 @@ export const drawText = (element: SVG | Group, textData: TextData): D3TextElemen
return textElem;
};

export const drawImage = (elem: SVG | Group, x: number, y: number, link: string): void => {
export const drawImage = (elem: SVG | SVGGroup, x: number, y: number, link: string): void => {
const imageElement: D3ImageElement = elem.append('image');
imageElement.attr('x', x);
imageElement.attr('y', y);
Expand All @@ -93,7 +93,7 @@ export const drawImage = (elem: SVG | Group, x: number, y: number, link: string)
};

export const drawEmbeddedImage = (
element: SVG | Group,
element: SVG | SVGGroup,
x: number,
y: number,
link: string
Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/diagrams/error/errorRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { SVG, SVGGroup } from '../../diagram-api/types.js';
import { log } from '../../logger.js';
import type { Group, SVG } from '../../diagram-api/types.js';
import { selectSvgElement } from '../../rendering-util/selectSvgElement.js';
import { configureSvgSize } from '../../setupGraphViewbox.js';

Expand All @@ -13,7 +13,7 @@ import { configureSvgSize } from '../../setupGraphViewbox.js';
export const draw = (_text: string, id: string, version: string) => {
log.debug('rendering svg for syntax error\n');
const svg: SVG = selectSvgElement(id);
const g: Group = svg.append('g');
const g: SVGGroup = svg.append('g');

svg.attr('viewBox', '0 0 2412 512');
configureSvgSize(svg, 100, 512, true);
Expand Down
6 changes: 3 additions & 3 deletions packages/mermaid/src/diagrams/info/infoRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { DrawDefinition, SVG, SVGGroup } from '../../diagram-api/types.js';
import { log } from '../../logger.js';
import { configureSvgSize } from '../../setupGraphViewbox.js';
import type { DrawDefinition, Group, SVG } from '../../diagram-api/types.js';
import { selectSvgElement } from '../../rendering-util/selectSvgElement.js';
import { configureSvgSize } from '../../setupGraphViewbox.js';

/**
* Draws a an info picture in the tag with id: id based on the graph definition in text.
Expand All @@ -16,7 +16,7 @@ const draw: DrawDefinition = (text, id, version) => {
const svg: SVG = selectSvgElement(id);
configureSvgSize(svg, 100, 400, true);

const group: Group = svg.append('g');
const group: SVGGroup = svg.append('g');
group
.append('text')
.attr('x', 100)
Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/diagrams/packet/renderer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Diagram } from '../../Diagram.js';
import type { PacketDiagramConfig } from '../../config.type.js';
import type { DiagramRenderer, DrawDefinition, Group, SVG } from '../../diagram-api/types.js';
import type { DiagramRenderer, DrawDefinition, SVG, SVGGroup } from '../../diagram-api/types.js';
import { selectSvgElement } from '../../rendering-util/selectSvgElement.js';
import { configureSvgSize } from '../../setupGraphViewbox.js';
import type { PacketDB, PacketWord } from './types.js';
Expand Down Expand Up @@ -39,7 +39,7 @@ const drawWord = (
rowNumber: number,
{ rowHeight, paddingX, paddingY, bitWidth, bitsPerRow, showBits }: Required<PacketDiagramConfig>
) => {
const group: Group = svg.append('g');
const group: SVGGroup = svg.append('g');
const wordY = rowNumber * (rowHeight + paddingY) + paddingY;
for (const block of word) {
const blockX = (block.start % bitsPerRow) * bitWidth + 1;
Expand Down
12 changes: 6 additions & 6 deletions packages/mermaid/src/diagrams/pie/pieRenderer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type d3 from 'd3';
import { scaleOrdinal, pie as d3pie, arc } from 'd3';
import { arc, pie as d3pie, scaleOrdinal } from 'd3';
import type { MermaidConfig, PieDiagramConfig } from '../../config.type.js';
import { getConfig } from '../../diagram-api/diagramAPI.js';
import type { DrawDefinition, SVG, SVGGroup } from '../../diagram-api/types.js';
import { log } from '../../logger.js';
import { selectSvgElement } from '../../rendering-util/selectSvgElement.js';
import { configureSvgSize } from '../../setupGraphViewbox.js';
import { getConfig } from '../../diagram-api/diagramAPI.js';
import { cleanAndMerge, parseFontSize } from '../../utils.js';
import type { DrawDefinition, Group, SVG } from '../../diagram-api/types.js';
import type { D3Section, PieDB, Sections } from './pieTypes.js';
import type { MermaidConfig, PieDiagramConfig } from '../../config.type.js';
import { selectSvgElement } from '../../rendering-util/selectSvgElement.js';

const createPieArcs = (sections: Sections): d3.PieArcDatum<D3Section>[] => {
// Compute the position of each group on the pie:
Expand Down Expand Up @@ -46,7 +46,7 @@ export const draw: DrawDefinition = (text, id, _version, diagObj) => {
const height = 450;
const pieWidth: number = height;
const svg: SVG = selectSvgElement(id);
const group: Group = svg.append('g');
const group: SVGGroup = svg.append('g');
group.attr('transform', 'translate(' + pieWidth / 2 + ',' + height / 2 + ')');

const { themeVariables } = globalConfig;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Group } from '../../../../../diagram-api/types.js';
import type { SVGGroup } from '../../../../../diagram-api/types.js';
import type {
AxisDataType,
ChartComponent,
Expand All @@ -25,7 +25,7 @@ export function getAxis(
data: AxisDataType,
axisConfig: XYChartAxisConfig,
axisThemeConfig: XYChartAxisThemeConfig,
tmpSVGGroup: Group
tmpSVGGroup: SVGGroup
): Axis {
const textDimensionCalculator = new TextDimensionCalculatorWithFont(tmpSVGGroup);
if (isBandAxisData(data)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { Group } from '../../../../diagram-api/types.js';
import type { SVGGroup } from '../../../../diagram-api/types.js';
import type {
BoundingRect,
ChartComponent,
Dimension,
DrawableElem,
Point,
XYChartConfig,
XYChartData,
XYChartThemeConfig,
XYChartConfig,
} from '../interfaces.js';
import type { TextDimensionCalculator } from '../textDimensionCalculator.js';
import { TextDimensionCalculatorWithFont } from '../textDimensionCalculator.js';
Expand Down Expand Up @@ -84,7 +84,7 @@ export function getChartTitleComponent(
chartConfig: XYChartConfig,
chartData: XYChartData,
chartThemeConfig: XYChartThemeConfig,
tmpSVGGroup: Group
tmpSVGGroup: SVGGroup
): ChartComponent {
const textDimensionCalculator = new TextDimensionCalculatorWithFont(tmpSVGGroup);
return new ChartTitle(textDimensionCalculator, chartConfig, chartData, chartThemeConfig);
Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/diagrams/xychart/chartBuilder/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Group } from '../../../diagram-api/types.js';
import type { SVGGroup } from '../../../diagram-api/types.js';
import type { DrawableElem, XYChartConfig, XYChartData, XYChartThemeConfig } from './interfaces.js';
import { Orchestrator } from './orchestrator.js';

Expand All @@ -7,7 +7,7 @@ export class XYChartBuilder {
config: XYChartConfig,
chartData: XYChartData,
chartThemeConfig: XYChartThemeConfig,
tmpSVGGroup: Group
tmpSVGGroup: SVGGroup
): DrawableElem[] {
const orchestrator = new Orchestrator(config, chartData, chartThemeConfig, tmpSVGGroup);
return orchestrator.getDrawableElement();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import type { SVGGroup } from '../../../diagram-api/types.js';
import type { Axis } from './components/axis/index.js';
import { getAxis } from './components/axis/index.js';
import { getChartTitleComponent } from './components/chartTitle.js';
import type { Plot } from './components/plot/index.js';
import { getPlotComponent } from './components/plot/index.js';
import type {
ChartComponent,
DrawableElem,
Expand All @@ -6,12 +12,6 @@ import type {
XYChartThemeConfig,
} from './interfaces.js';
import { isBarPlot } from './interfaces.js';
import type { Axis } from './components/axis/index.js';
import { getAxis } from './components/axis/index.js';
import { getChartTitleComponent } from './components/chartTitle.js';
import type { Plot } from './components/plot/index.js';
import { getPlotComponent } from './components/plot/index.js';
import type { Group } from '../../../diagram-api/types.js';

export class Orchestrator {
private componentStore: {
Expand All @@ -24,7 +24,7 @@ export class Orchestrator {
private chartConfig: XYChartConfig,
private chartData: XYChartData,
chartThemeConfig: XYChartThemeConfig,
tmpSVGGroup: Group
tmpSVGGroup: SVGGroup
) {
this.componentStore = {
title: getChartTitleComponent(chartConfig, chartData, chartThemeConfig, tmpSVGGroup),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type { Dimension } from './interfaces.js';
import type { SVGGroup } from '../../../diagram-api/types.js';
import { computeDimensionOfText } from '../../../rendering-util/createText.js';
import type { Group } from '../../../diagram-api/types.js';
import type { Dimension } from './interfaces.js';

export interface TextDimensionCalculator {
getMaxDimension(texts: string[], fontSize: number): Dimension;
}

export class TextDimensionCalculatorWithFont implements TextDimensionCalculator {
constructor(private parentGroup: Group) {}
constructor(private parentGroup: SVGGroup) {}
getMaxDimension(texts: string[], fontSize: number): Dimension {
if (!this.parentGroup) {
return {
Expand Down
16 changes: 8 additions & 8 deletions packages/mermaid/src/diagrams/xychart/xychartDb.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import * as configApi from '../../config.js';
import defaultConfig from '../../defaultConfig.js';
import type { SVGGroup } from '../../diagram-api/types.js';
import { getThemeVariables } from '../../themes/theme-default.js';
import { cleanAndMerge } from '../../utils.js';
import { sanitizeText } from '../common/common.js';
import {
clear as commonClear,
getAccDescription,
Expand All @@ -7,11 +13,6 @@ import {
setAccTitle,
setDiagramTitle,
} from '../common/commonDb.js';
import * as configApi from '../../config.js';
import defaultConfig from '../../defaultConfig.js';
import { getThemeVariables } from '../../themes/theme-default.js';
import { cleanAndMerge } from '../../utils.js';
import { sanitizeText } from '../common/common.js';
import { XYChartBuilder } from './chartBuilder/index.js';
import type {
DrawableElem,
Expand All @@ -21,11 +22,10 @@ import type {
XYChartThemeConfig,
} from './chartBuilder/interfaces.js';
import { isBandAxisData, isLinearAxisData } from './chartBuilder/interfaces.js';
import type { Group } from '../../diagram-api/types.js';

let plotIndex = 0;

let tmpSVGGroup: Group;
let tmpSVGGroup: SVGGroup;

let xyChartConfig: XYChartConfig = getChartDefaultConfig();
let xyChartThemeConfig: XYChartThemeConfig = getChartDefaultThemeConfig();
Expand Down Expand Up @@ -75,7 +75,7 @@ function textSanitizer(text: string) {
return sanitizeText(text.trim(), config);
}

function setTmpSVGG(SVGG: Group) {
function setTmpSVGG(SVGG: SVGGroup) {
tmpSVGGroup = SVGG;
}
function setOrientation(orientation: string) {
Expand Down
2 changes: 2 additions & 0 deletions packages/mermaid/src/internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ export const internalHelpers = {
log,
positionEdgeLabel,
};

export type InternalHelpers = typeof internalHelpers;
10 changes: 6 additions & 4 deletions packages/mermaid/src/mermaid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@ import type { MermaidConfig } from './config.type.js';
import { detectType, registerLazyLoadedDiagrams } from './diagram-api/detectType.js';
import { addDiagrams } from './diagram-api/diagram-orchestration.js';
import { loadRegisteredDiagrams } from './diagram-api/loadDiagram.js';
import type { ExternalDiagramDefinition } from './diagram-api/types.js';
import type { ExternalDiagramDefinition, SVG, SVGGroup } from './diagram-api/types.js';
import type { ParseErrorFunction } from './Diagram.js';
import type { UnknownDiagramError } from './errors.js';
import type { internalHelpers } from './internals.js';
import type { InternalHelpers } from './internals.js';
import { log } from './logger.js';
import { mermaidAPI } from './mermaidAPI.js';
import type { LayoutLoaderDefinition } from './rendering-util/render.js';
import type { LayoutLoaderDefinition, RenderOptions } from './rendering-util/render.js';
import { registerLayoutLoaders } from './rendering-util/render.js';
import type { LayoutData } from './rendering-util/types.js';
import type { ParseOptions, ParseResult, RenderResult } from './types.js';
import type { DetailedError } from './utils.js';
import utils, { isDetailedError } from './utils.js';

type InternalHelpers = typeof internalHelpers;
export type {
DetailedError,
ExternalDiagramDefinition,
Expand All @@ -31,7 +30,10 @@ export type {
ParseErrorFunction,
ParseOptions,
ParseResult,
RenderOptions,
RenderResult,
SVG,
SVGGroup,
UnknownDiagramError,
};

Expand Down
10 changes: 5 additions & 5 deletions packages/mermaid/src/rendering-util/createText.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// @ts-nocheck TODO: Fix types
import type { MermaidConfig } from '../config.type.js';
import type { Group } from '../diagram-api/types.js';
import { getConfig } from '$root/diagram-api/diagramAPI.js';
import common, { hasKatex, renderKatex } from '$root/diagrams/common/common.js';
import { select } from 'd3';
import type { MermaidConfig } from '../config.type.js';
import type { SVGGroup } from '../diagram-api/types.js';
import type { D3TSpanElement, D3TextElement } from '../diagrams/common/commonTypes.js';
import { log } from '../logger.js';
import { markdownToHTML, markdownToLines } from '../rendering-util/handle-markdown-text.js';
import { decodeEntities } from '../utils.js';
import { splitLineToFitWidth } from './splitText.js';
import type { MarkdownLine, MarkdownWord } from './types.js';
import common, { hasKatex, renderKatex } from '$root/diagrams/common/common.js';
import { getConfig } from '$root/diagram-api/diagramAPI.js';

function applyStyle(dom, styleFn) {
if (styleFn) {
Expand Down Expand Up @@ -82,7 +82,7 @@ function computeWidthOfText(parentNode: any, lineHeight: number, line: MarkdownL
}

export function computeDimensionOfText(
parentNode: Group,
parentNode: SVGGroup,
lineHeight: number,
text: string
): DOMRect | undefined {
Expand Down

0 comments on commit 037ba2f

Please sign in to comment.