Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
6 changes: 3 additions & 3 deletions dev/ts/shared/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ function getRendererOptionsFromParameters(config: BpmnVisualizationDemoConfigura
// Mapping between query parameter names and RendererOptions boolean properties
const rendererParameterMappings: Record<string, Exclude<keyof RendererOptions, 'iconPainter'>> = {
'renderer.ignore.bpmn.colors': 'ignoreBpmnColors',
'renderer.ignore.label.style': 'ignoreBpmnLabelStyles',
'renderer.ignore.activity.label.bounds': 'ignoreBpmnActivityLabelBounds',
'renderer.ignore.task.label.bounds': 'ignoreBpmnTaskLabelBounds',
'renderer.ignore.label.style': 'ignoreLabelStyles',
'renderer.ignore.activity.label.bounds': 'ignoreActivityLabelBounds',
'renderer.ignore.task.label.bounds': 'ignoreTaskLabelBounds',
};

// Process renderer parameters
Expand Down
16 changes: 8 additions & 8 deletions src/component/mxgraph/BpmnRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ import StyleComputer from './renderer/StyleComputer';
* @internal
*/
export class BpmnRenderer {
private readonly ignoreBpmnActivityLabelBounds: boolean;
private readonly ignoreBpmnTaskLabelBounds: boolean;
private readonly ignoreActivityLabelBounds: boolean;
private readonly ignoreTaskLabelBounds: boolean;

constructor(
readonly graph: BpmnGraph,
readonly coordinatesTranslator: CoordinatesTranslator,
readonly styleComputer: StyleComputer,
rendererOptions: RendererOptions,
) {
this.ignoreBpmnActivityLabelBounds = rendererOptions?.ignoreBpmnActivityLabelBounds ?? false;
this.ignoreBpmnTaskLabelBounds = rendererOptions?.ignoreBpmnTaskLabelBounds ?? false;
this.ignoreActivityLabelBounds = rendererOptions?.ignoreActivityLabelBounds ?? false;
this.ignoreTaskLabelBounds = rendererOptions?.ignoreTaskLabelBounds ?? false;
}

render(renderedModel: RenderedModel): void {
Expand Down Expand Up @@ -78,7 +78,7 @@ export class BpmnRenderer {
const bpmnElement = shape.bpmnElement;
const parent = this.getParent(bpmnElement);
const bounds = shape.bounds;
const labelBounds = isLabelBoundsIgnored(shape, this.ignoreBpmnActivityLabelBounds, this.ignoreBpmnTaskLabelBounds) ? undefined : shape.label?.bounds;
const labelBounds = isLabelBoundsIgnored(shape, this.ignoreActivityLabelBounds, this.ignoreTaskLabelBounds) ? undefined : shape.label?.bounds;
const style = this.styleComputer.computeStyle(shape, labelBounds);

this.insertVertex(parent, bpmnElement.id, bpmnElement.name, bounds, labelBounds, style);
Expand Down Expand Up @@ -147,12 +147,12 @@ export class BpmnRenderer {
/**
* @internal
*/
export function isLabelBoundsIgnored(shape: Shape, ignoreBpmnActivityLabelBounds: boolean, ignoreBpmnTaskLabelBounds: boolean): boolean {
export function isLabelBoundsIgnored(shape: Shape, ignoreActivityLabelBounds: boolean, ignoreTaskLabelBounds: boolean): boolean {
const kind = shape.bpmnElement.kind;
return (
ShapeUtil.isPoolOrLane(kind) || // pool/lane label bounds are not managed for now (use hard coded values)
(ignoreBpmnActivityLabelBounds && ShapeUtil.isActivity(kind)) ||
(ignoreBpmnTaskLabelBounds && ShapeUtil.isTask(kind))
(ignoreActivityLabelBounds && ShapeUtil.isActivity(kind)) ||
(ignoreTaskLabelBounds && ShapeUtil.isTask(kind))
);
}

Expand Down
20 changes: 1 addition & 19 deletions src/component/mxgraph/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,7 @@ 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;
export const { mxCellRenderer, mxClient, mxConstants, mxEvent, mxPerimeter, mxPoint, mxRectangle, mxRectangleShape, mxSvgCanvas2D, mxUtils } = mxgraph;

/** @internal */
declare global {
Expand Down
6 changes: 3 additions & 3 deletions src/component/mxgraph/renderer/StyleComputer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ import { BpmnStyleIdentifier } from '../style';
*/
export default class StyleComputer {
private readonly ignoreBpmnColors: boolean;
private readonly ignoreBpmnLabelStyles: boolean;
private readonly ignoreLabelStyles: boolean;

constructor(options?: RendererOptions) {
this.ignoreBpmnColors = options?.ignoreBpmnColors ?? true;
this.ignoreBpmnLabelStyles = options?.ignoreBpmnLabelStyles ?? false;
this.ignoreLabelStyles = options?.ignoreLabelStyles ?? false;
}

computeStyle(bpmnCell: Shape | Edge, labelBounds: Bounds): string {
Expand Down Expand Up @@ -112,7 +112,7 @@ export default class StyleComputer {
const styleValues = new Map<string, string | number>();

const font = bpmnCell.label?.font;
if (font && !this.ignoreBpmnLabelStyles) {
if (font && !this.ignoreLabelStyles) {
styleValues.set(mxConstants.STYLE_FONTFAMILY, font.name);
styleValues.set(mxConstants.STYLE_FONTSIZE, font.size);
styleValues.set(mxConstants.STYLE_FONTSTYLE, getFontStyleValue(font));
Expand Down
10 changes: 5 additions & 5 deletions src/component/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export type RendererOptions = {
* @default false
* @since 0.48.0
*/
ignoreBpmnActivityLabelBounds?: boolean;
ignoreActivityLabelBounds?: boolean;
/**
* If set to `false`, support the "BPMN in Color" specification with a fallback with bpmn.io colors. For more details about the support, see
* {@link https://github.com/process-analytics/bpmn-visualization-js/pull/2614}.
Expand All @@ -252,16 +252,16 @@ export type RendererOptions = {
* @default false
* @since 0.48.0
*/
ignoreBpmnLabelStyles?: boolean;
ignoreLabelStyles?: boolean;
/**
* If set to `true`, ignore the label bounds configuration defined in the BPMN diagram for tasks only.
* This forces the use of default label positioning for tasks instead of the bounds specified in the BPMN source.
* This option is more restrictive than `ignoreBpmnActivityLabelBounds` as it only affects tasks, not sub-processes or call activities.
* This option is more restrictive than {@link ignoreActivityLabelBounds} as it only affects tasks, not sub-processes or call activities.
*
* **Note**: When `ignoreBpmnActivityLabelBounds` is `true`, this option is ignored as the more general activity option takes precedence.
* **Note**: When {@link ignoreActivityLabelBounds} is `true`, this option is ignored as the more general activity option takes precedence.
*
* @default false
* @since 0.48.0
*/
ignoreBpmnTaskLabelBounds?: boolean;
ignoreTaskLabelBounds?: boolean;
};
12 changes: 6 additions & 6 deletions test/e2e/bpmn.rendering.ignore.options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,16 +159,16 @@ describe('BPMN rendering - ignore options', () => {
describe('Ignore activity label bounds', () => {
const bpmnDiagramName = 'activities.with.wrongly.positioned.labels';

describe.each([false, true])('ignoreBpmnActivityLabelBounds: %s', (ignoreBpmnActivityLabelBounds: boolean) => {
describe.each([false, true])('ignoreActivityLabelBounds: %s', (ignoreActivityLabelBounds: boolean) => {
const imageSnapshotConfigurator = new ImageSnapshotConfigurator(new ImageSnapshotThresholdsActivityLabelBounds(), 'bpmn-rendering-ignore-options');

it(`${bpmnDiagramName}`, async () => {
await pageTester.gotoPageAndLoadBpmnDiagram(bpmnDiagramName, {
rendererIgnoreBpmnActivityLabelBounds: ignoreBpmnActivityLabelBounds,
rendererIgnoreActivityLabelBounds: ignoreActivityLabelBounds,
});

const image = await page.screenshot({ fullPage: true });
const config = imageSnapshotConfigurator.getConfig(getConfigName(bpmnDiagramName, ignoreBpmnActivityLabelBounds));
const config = imageSnapshotConfigurator.getConfig(getConfigName(bpmnDiagramName, ignoreActivityLabelBounds));
expect(image).toMatchImageSnapshot(config);
});
});
Expand All @@ -177,16 +177,16 @@ describe('BPMN rendering - ignore options', () => {
describe('Ignore label styles', () => {
const bpmnDiagramName = 'labels.with.font.styles';

describe.each([false, true])('ignoreBpmnLabelStyles: %s', (ignoreBpmnLabelStyles: boolean) => {
describe.each([false, true])('ignoreLabelStyles: %s', (ignoreLabelStyles: boolean) => {
const imageSnapshotConfigurator = new ImageSnapshotConfigurator(new ImageSnapshotThresholdsLabelStyles(), 'bpmn-rendering-ignore-options');

it(`${bpmnDiagramName}`, async () => {
await pageTester.gotoPageAndLoadBpmnDiagram(bpmnDiagramName, {
rendererIgnoreBpmnLabelStyles: ignoreBpmnLabelStyles,
rendererIgnoreLabelStyles: ignoreLabelStyles,
});

const image = await page.screenshot({ fullPage: true });
const config = imageSnapshotConfigurator.getConfig(getConfigName(bpmnDiagramName, ignoreBpmnLabelStyles));
const config = imageSnapshotConfigurator.getConfig(getConfigName(bpmnDiagramName, ignoreLabelStyles));
expect(image).toMatchImageSnapshot(config);
});
});
Expand Down
9 changes: 4 additions & 5 deletions test/shared/visu/bpmn-page-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ export interface PageOptions {
bpmnElementIdToCollapse?: string;
poolIdsToFilter?: string | string[];
rendererIgnoreBpmnColors?: boolean;
rendererIgnoreBpmnLabelStyles?: boolean;
rendererIgnoreBpmnActivityLabelBounds?: boolean;
rendererIgnoreLabelStyles?: boolean;
rendererIgnoreActivityLabelBounds?: boolean;
}

export interface Point {
Expand Down Expand Up @@ -258,9 +258,8 @@ export class PageTester {
otherPageOptions?.poolIdsToFilter && (url += `&bpmn.filter.pool.ids=${otherPageOptions.poolIdsToFilter}`);
// renderer options
otherPageOptions?.rendererIgnoreBpmnColors !== undefined && (url += `&renderer.ignore.bpmn.colors=${otherPageOptions.rendererIgnoreBpmnColors}`);
otherPageOptions?.rendererIgnoreBpmnLabelStyles !== undefined && (url += `&renderer.ignore.label.style=${otherPageOptions.rendererIgnoreBpmnLabelStyles}`);
otherPageOptions?.rendererIgnoreBpmnActivityLabelBounds !== undefined &&
(url += `&renderer.ignore.activity.label.bounds=${otherPageOptions.rendererIgnoreBpmnActivityLabelBounds}`);
otherPageOptions?.rendererIgnoreLabelStyles !== undefined && (url += `&renderer.ignore.label.style=${otherPageOptions.rendererIgnoreLabelStyles}`);
otherPageOptions?.rendererIgnoreActivityLabelBounds !== undefined && (url += `&renderer.ignore.activity.label.bounds=${otherPageOptions.rendererIgnoreActivityLabelBounds}`);

return url;
}
Expand Down
8 changes: 4 additions & 4 deletions test/unit/component/mxgraph/BpmnRenderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ describe('isLabelBoundsIgnored', () => {
});
});

describe('with ignoreBpmnActivityLabelBounds option', () => {
describe.each([true, false])('with ignoreBpmnTaskLabelBounds option set to %s', (ignoreBpmnTaskLabelBounds: boolean) => {
describe('with ignoreActivityLabelBounds option', () => {
describe.each([true, false])('with ignoreTaskLabelBounds option set to %s', (ignoreTaskLabelBounds: boolean) => {
test.each([
[ShapeBpmnElementKind.POOL, true],
[ShapeBpmnElementKind.LANE, true],
Expand All @@ -54,12 +54,12 @@ describe('isLabelBoundsIgnored', () => {
[ShapeBpmnElementKind.GATEWAY_PARALLEL, false],
])('should ignore %s label bounds? %s', (kind, expected) => {
const shape = new Shape('id', new ShapeBpmnElement('id', 'name', kind));
expect(isLabelBoundsIgnored(shape, true, ignoreBpmnTaskLabelBounds)).toBe(expected);
expect(isLabelBoundsIgnored(shape, true, ignoreTaskLabelBounds)).toBe(expected);
});
});
});

describe('with ignoreBpmnTaskLabelBounds option', () => {
describe('with ignoreTaskLabelBounds option', () => {
test.each([
[ShapeBpmnElementKind.POOL, true],
[ShapeBpmnElementKind.LANE, true],
Expand Down
6 changes: 3 additions & 3 deletions test/unit/component/mxgraph/renderer/StyleComputer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,9 @@ describe('Style Computer', () => {
});

describe('compute style - ignore BPMN label styles', () => {
describe.each([[undefined], [false], [true]])(`Ignore BPMN label styles (renderer option): %s`, (ignoreBpmnLabelStyles: boolean) => {
const styleComputer = new StyleComputer(ignoreBpmnLabelStyles === undefined ? {} : { ignoreBpmnLabelStyles });
const expectFontStyles = !(ignoreBpmnLabelStyles ?? false);
describe.each([[undefined], [false], [true]])(`Ignore BPMN label styles (renderer option): %s`, (ignoreLabelStyles: boolean) => {
const styleComputer = new StyleComputer(ignoreLabelStyles === undefined ? {} : { ignoreLabelStyles });
Comment thread
tbouffard marked this conversation as resolved.
Outdated
const expectFontStyles = !(ignoreLabelStyles ?? false);

function computeStyleWithIgnoreLabelStyles(element: Shape | Edge): string {
return styleComputer.computeStyle(element, element.label?.bounds);
Expand Down