Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dev/ts/component/SvgExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

import type { mxGraph, mxSvgCanvas2D as mxSvgCanvas2DType } from 'mxgraph';

import { mxgraph, mxClient, mxConstants, mxSvgCanvas2D, mxUtils } from '../../../src/component/mxgraph/initializer';
import { mxClient, mxConstants, mxImageExport, mxSvgCanvas2D, mxUtils } from '../../../src/component/mxgraph/initializer';

interface SvgExportOptions {
scale: number;
Expand Down Expand Up @@ -92,7 +92,7 @@ ${svgAsString}

svgCanvas.scale(s);

const imgExport = new mxgraph.mxImageExport();
const imgExport = new mxImageExport();
// FIXME only the first overlay is placed at the right position
// overlays put on element of subprocess/call-activity are not placed correctly in svg export
imgExport.includeOverlays = true;
Expand Down
14 changes: 7 additions & 7 deletions src/component/mxgraph/BpmnCellRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ limitations under the License.
*/

import type { IconPainter } from './shape/render';
import type { mxCellState, mxImageShape, mxShape } from 'mxgraph';
import type { mxCellState, mxImageShape as mxImageShapeType, mxShape } from 'mxgraph';

import { mxgraph, mxRectangle } from './initializer';
import { mxCellRenderer, mxDictionary, mxImageShape, mxRectangle } from './initializer';
import { CustomCellOverlay } from './overlay/custom-overlay';
import { OverlayBadgeShape } from './overlay/shapes';
import { overrideCreateSvgCanvas } from './shape/utils';

export class BpmnCellRenderer extends mxgraph.mxCellRenderer {
export class BpmnCellRenderer extends mxCellRenderer {
constructor(private readonly iconPainter: IconPainter) {
super();
}
Expand All @@ -33,7 +33,7 @@ export class BpmnCellRenderer extends mxgraph.mxCellRenderer {
let dict = null;

if (overlays != null) {
dict = new mxgraph.mxDictionary<mxShape>();
dict = new mxDictionary<mxShape>();

for (const currentOverlay of overlays) {
const shape = state.overlays == null ? null : state.overlays.remove(currentOverlay);
Expand All @@ -48,16 +48,16 @@ export class BpmnCellRenderer extends mxgraph.mxCellRenderer {
if (currentOverlay instanceof CustomCellOverlay) {
overlayShape = new OverlayBadgeShape(currentOverlay.label, new mxRectangle(0, 0, 0, 0), currentOverlay.style);
} else {
overlayShape = new mxgraph.mxImageShape(new mxRectangle(0, 0, 0, 0), currentOverlay.image.src);
(overlayShape as mxImageShape).preserveImageAspect = false;
overlayShape = new mxImageShape(new mxRectangle(0, 0, 0, 0), currentOverlay.image.src);
(overlayShape as mxImageShapeType).preserveImageAspect = false;
}
// END bpmn-visualization CUSTOMIZATION

overlayShape.dialect = state.view.graph.dialect;
overlayShape.overlay = currentOverlay;

// The 'initializeOverlay' signature forces us to hardly cast the overlayShape
this.initializeOverlay(state, overlayShape as mxImageShape);
this.initializeOverlay(state, overlayShape as mxImageShapeType);
this.installCellOverlayListeners(state, currentOverlay, overlayShape);

if (currentOverlay.cursor != null) {
Expand Down
10 changes: 5 additions & 5 deletions src/component/mxgraph/BpmnGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ limitations under the License.
*/

import type { IconPainter } from './shape/render';
import type { mxCellRenderer, mxCellState, mxGraphView, mxPoint } from 'mxgraph';
import type { mxCellRenderer, mxCellState, mxGraphView as mxGraphViewType, mxPoint } from 'mxgraph';

import { BpmnCellRenderer } from './BpmnCellRenderer';
import { mxgraph } from './initializer';
import { mxGraph, mxGraphView } from './initializer';

/**
* Temporary storage for iconPainter during BpmnGraph construction.
Expand Down Expand Up @@ -49,7 +49,7 @@ import { mxgraph } from './initializer';
*/
let pendingIconPainter: IconPainter | undefined;

export class BpmnGraph extends mxgraph.mxGraph {
export class BpmnGraph extends mxGraph {
/**
* @internal
*/
Expand All @@ -72,7 +72,7 @@ export class BpmnGraph extends mxgraph.mxGraph {
/**
* @internal
*/
override createGraphView(): mxGraphView {
override createGraphView(): mxGraphViewType {
return new BpmnGraphView(this);
}

Expand Down Expand Up @@ -108,7 +108,7 @@ export class BpmnGraph extends mxgraph.mxGraph {
}
}

class BpmnGraphView extends mxgraph.mxGraphView {
class BpmnGraphView extends mxGraphView {
override getFloatingTerminalPoint(edge: mxCellState, start: mxCellState, end: mxCellState, source: boolean): mxPoint {
// some values may be null: the first and the last values are null prior computing floating terminal points
const edgePoints = edge.absolutePoints.filter(Boolean);
Expand Down
4 changes: 2 additions & 2 deletions src/component/mxgraph/config/register-style-definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
import type { mxAbstractCanvas2D, mxCell, mxPoint, mxShape } from 'mxgraph';

import { ShapeBpmnElementKind } from '../../../model/bpmn/internal';
import { mxCellRenderer, mxgraph } from '../initializer';
import { mxCellRenderer, mxMarker } from '../initializer';
import {
BusinessRuleTaskShape,
CallActivityShape,
Expand Down Expand Up @@ -102,5 +102,5 @@ const dashMarkerFactory = (
};

export const registerEdgeMarkers = (): void => {
mxgraph.mxMarker.addMarker(MarkerIdentifier.ARROW_DASH, dashMarkerFactory);
mxMarker.addMarker(MarkerIdentifier.ARROW_DASH, dashMarkerFactory);
};
49 changes: 28 additions & 21 deletions src/component/mxgraph/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import factory, { type mxGraphExportObject } from 'mxgraph';
import factory, { type mxGraph as mxGraphClass, type mxGraphExportObject } from 'mxgraph';

/**
* The `mxgraph` context that allows access to the mxGraph objects.
Expand All @@ -33,26 +33,33 @@ import factory, { type mxGraphExportObject } from 'mxgraph';
*/
export const mxgraph = initialize();

/** @internal */
export const mxCellRenderer = mxgraph.mxCellRenderer;
/** @internal */
export const mxClient = mxgraph.mxClient;
/** @internal */
export const mxConstants = mxgraph.mxConstants;
/** @internal */
export const mxEvent = mxgraph.mxEvent;
/** @internal */
export const mxPerimeter = mxgraph.mxPerimeter;
/** @internal */
export const mxPoint = mxgraph.mxPoint;
/** @internal */
export const mxRectangle = mxgraph.mxRectangle;
/** @internal */
export const mxRectangleShape = mxgraph.mxRectangleShape;
/** @internal */
export const mxSvgCanvas2D = mxgraph.mxSvgCanvas2D;
/** @internal */
export const mxUtils = mxgraph.mxUtils;
// Destructured exports for convenient access to mxGraph objects.
// mxGraph is exported separately to preserve their constructor types in the api-extractor generated .d.ts (destructuring loses `typeof` during rollup).
Comment thread
tbouffard marked this conversation as resolved.
Outdated
export const {
mxCellOverlay,
mxCellRenderer,
mxClient,
mxConnector,
mxConstants,
mxDictionary,
mxEllipse,
mxEvent,
mxGeometry, // at least used in tests
mxGraphView,
mxImageExport,
mxImageShape,
mxMarker,
mxPerimeter,
mxPoint,
mxRectangle,
mxRectangleShape,
mxRhombus,
mxSvgCanvas2D,
mxText,
mxUtils,
} = mxgraph;

export const mxGraph: typeof mxGraphClass = mxgraph.mxGraph;
Comment thread
tbouffard marked this conversation as resolved.
Outdated

/** @internal */
declare global {
Expand Down
4 changes: 2 additions & 2 deletions src/component/mxgraph/overlay/custom-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
import type { OverlayStyle } from '../../registry';
import type { mxCellState, mxPoint as mxPointType, mxRectangle as mxRectangleType } from 'mxgraph';

import { mxgraph, mxConstants, mxPoint, mxRectangle } from '../initializer';
import { mxCellOverlay, mxConstants, mxPoint, mxRectangle } from '../initializer';

export type VerticalAlignType = 'bottom' | 'middle' | 'top';
export type HorizontalAlignType = 'left' | 'center' | 'right';
Expand All @@ -34,7 +34,7 @@ export interface CustomCellOverlayPosition {

export type CustomCellOverlayStyle = Required<OverlayStyle>;

export class CustomCellOverlay extends mxgraph.mxCellOverlay {
export class CustomCellOverlay extends mxCellOverlay {
readonly style: CustomCellOverlayStyle;

constructor(
Expand Down
4 changes: 2 additions & 2 deletions src/component/mxgraph/overlay/shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ limitations under the License.
import type { CustomCellOverlayStyle } from './custom-overlay';
import type { mxRectangle } from 'mxgraph';

import { mxgraph } from '../initializer';
import { mxText } from '../initializer';

export class OverlayBadgeShape extends mxgraph.mxText {
export class OverlayBadgeShape extends mxText {
constructor(value: string, bounds: mxRectangle, style: CustomCellOverlayStyle) {
super(
value,
Expand Down
4 changes: 2 additions & 2 deletions src/component/mxgraph/shape/edges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ limitations under the License.

import type { mxAbstractCanvas2D, mxPoint } from 'mxgraph';

import { mxgraph, mxSvgCanvas2D, mxUtils } from '../initializer';
import { mxConnector, mxSvgCanvas2D, mxUtils } from '../initializer';
import { BpmnStyleIdentifier } from '../style';

export class BpmnConnector extends mxgraph.mxConnector {
export class BpmnConnector extends mxConnector {
override paintEdgeShape(c: mxAbstractCanvas2D, pts: mxPoint[]): void {
// The indirection via functions for markers is needed in
// order to apply the offsets before painting the line and
Expand Down
4 changes: 2 additions & 2 deletions src/component/mxgraph/shape/event-shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import type { BpmnCanvas, PaintParameter, IconPainter } from './render';
import type { mxAbstractCanvas2D } from 'mxgraph';

import { ShapeBpmnEventDefinitionKind } from '../../../model/bpmn/internal';
import { mxgraph, mxUtils } from '../initializer';
import { mxEllipse, mxUtils } from '../initializer';
import { BpmnStyleIdentifier, StyleDefault } from '../style';

import { buildPaintParameter } from './render/icon-painter';

/**
* @internal
*/
export class EventShape extends mxgraph.mxEllipse {
export class EventShape extends mxEllipse {
// The actual value is injected at runtime by BpmnCellRenderer
protected iconPainter: IconPainter = undefined;

Expand Down
4 changes: 2 additions & 2 deletions src/component/mxgraph/shape/gateway-shapes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import type { IconPainter, PaintParameter } from './render';
import type { mxAbstractCanvas2D } from 'mxgraph';

import { ShapeBpmnEventBasedGatewayKind } from '../../../model/bpmn/internal';
import { mxgraph, mxUtils } from '../initializer';
import { mxRhombus, mxUtils } from '../initializer';
import { BpmnStyleIdentifier, StyleDefault } from '../style';
import { getBpmnIsInstantiating } from '../style/utils';

import { buildPaintParameter } from './render/icon-painter';

abstract class GatewayShape extends mxgraph.mxRhombus {
abstract class GatewayShape extends mxRhombus {
// The actual value is injected at runtime by BpmnCellRenderer
protected iconPainter: IconPainter = undefined;

Expand Down
4 changes: 1 addition & 3 deletions test/integration/mxGraph.model.bpmn.elements.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ import {
ShapeBpmnMarkerKind,
ShapeBpmnSubProcessKind,
} from '@lib/bpmn-visualization';
import { mxConstants, mxgraph, mxPoint } from '@lib/component/mxgraph/initializer';
import { mxConstants, mxGeometry, mxPoint } from '@lib/component/mxgraph/initializer';
import { readFileSync } from '@test/shared/file-helper';

const mxGeometry = mxgraph.mxGeometry;

describe('mxGraph model - BPMN elements', () => {
describe('BPMN elements should be available in the mxGraph model', () => {
describe('Diagram with all the kind of elements', () => {
Expand Down
Loading