Skip to content

Commit 9e690ee

Browse files
committed
Merge branch 'master' into copilot/fix-843b1ce6-17c8-4e97-aa4d-a934b93a1f70
# Conflicts: # src/component/mxgraph/renderer/StyleComputer.ts # src/component/options.ts
2 parents 190268f + 4cbe851 commit 9e690ee

File tree

7 files changed

+102
-27
lines changed

7 files changed

+102
-27
lines changed

dev/ts/shared/main.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import type {
2626
ModelFilter,
2727
Overlay,
2828
PoolFilter,
29+
RendererOptions,
2930
StyleUpdate,
3031
ZoomType,
3132
} from '../../../src/bpmn-visualization';
@@ -310,12 +311,24 @@ export function startBpmnVisualization(config: BpmnVisualizationDemoConfiguratio
310311
log(`Initializing BpmnVisualization with container:`, config.globalOptions.container);
311312

312313
const parameters = new URLSearchParams(window.location.search);
313-
const rendererIgnoreBpmnColors = parameters.get('renderer.ignore.bpmn.colors');
314-
if (rendererIgnoreBpmnColors) {
315-
const ignoreBpmnColors = rendererIgnoreBpmnColors === 'true';
316-
log('Ignore support for "BPMN in Color"?', ignoreBpmnColors);
317-
!config.globalOptions.renderer && (config.globalOptions.renderer = {});
318-
config.globalOptions.renderer.ignoreBpmnColors = ignoreBpmnColors;
314+
315+
// Always initialize renderer options
316+
!config.globalOptions.renderer && (config.globalOptions.renderer = {});
317+
318+
// Mapping between query parameter names and RendererOptions properties
319+
const rendererParameterMappings: Record<string, keyof RendererOptions> = {
320+
'renderer.ignore.bpmn.colors': 'ignoreBpmnColors',
321+
'renderer.ignore.label.style': 'ignoreBpmnLabelStyles',
322+
};
323+
324+
// Process renderer parameters
325+
for (const [parameterName, optionKey] of Object.entries(rendererParameterMappings)) {
326+
const parameterValue = parameters.get(parameterName);
327+
if (parameterValue) {
328+
const optionValue = parameterValue === 'true';
329+
log(`Setting renderer option '${optionKey}':`, optionValue);
330+
config.globalOptions.renderer[optionKey] = optionValue;
331+
}
319332
}
320333

321334
bpmnVisualization = new ThemedBpmnVisualization(config.globalOptions);

package-lock.json

Lines changed: 7 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
},
106106
"dependencies": {
107107
"@typed-mxgraph/typed-mxgraph": "~1.0.8",
108-
"es-toolkit": "~1.39.3",
108+
"es-toolkit": "~1.39.10",
109109
"fast-xml-parser": "5.2.5",
110110
"mxgraph": "4.2.2"
111111
},

src/component/mxgraph/renderer/StyleComputer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ import { BpmnStyleIdentifier } from '../style';
3939
*/
4040
export default class StyleComputer {
4141
private readonly ignoreBpmnColors: boolean;
42+
private readonly ignoreBpmnLabelStyles: boolean;
4243
private readonly ignoreBpmnActivityLabelBounds: boolean;
4344
private readonly ignoreBpmnTaskLabelBounds: boolean;
4445

4546
constructor(options?: RendererOptions) {
4647
this.ignoreBpmnColors = options?.ignoreBpmnColors ?? true;
48+
this.ignoreBpmnLabelStyles = options?.ignoreBpmnLabelStyles ?? false;
4749
this.ignoreBpmnActivityLabelBounds = options?.ignoreBpmnActivityLabelBounds ?? false;
4850
this.ignoreBpmnTaskLabelBounds = options?.ignoreBpmnTaskLabelBounds ?? false;
4951
}
@@ -118,7 +120,7 @@ export default class StyleComputer {
118120
const styleValues = new Map<string, string | number>();
119121

120122
const font = bpmnCell.label?.font;
121-
if (font) {
123+
if (font && !this.ignoreBpmnLabelStyles) {
122124
styleValues.set(mxConstants.STYLE_FONTFAMILY, font.name);
123125
styleValues.set(mxConstants.STYLE_FONTSIZE, font.size);
124126
styleValues.set(mxConstants.STYLE_FONTSTYLE, getFontStyleValue(font));

src/component/options.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ export type ParserOptions = {
197197
* @since 0.35.0
198198
*/
199199
export type RendererOptions = {
200+
/**
201+
* If set to `true`, ignore the label bounds configuration defined in the BPMN diagram for all activities.
202+
* This forces the use of default label positioning instead of the bounds specified in the BPMN source.
203+
* Activities include tasks, sub-processes, and call activities.
204+
*
205+
* @default false
206+
* @since 0.48.0
207+
*/
208+
ignoreBpmnActivityLabelBounds?: boolean;
200209
/**
201210
* If set to `false`, support the "BPMN in Color" specification with a fallback with bpmn.io colors. For more details about the support, see
202211
* {@link https://github.com/process-analytics/bpmn-visualization-js/pull/2614}.
@@ -207,14 +216,13 @@ export type RendererOptions = {
207216
*/
208217
ignoreBpmnColors?: boolean;
209218
/**
210-
* If set to `true`, ignore the label bounds configuration defined in the BPMN diagram for all activities.
211-
* This forces the use of default label positioning instead of the bounds specified in the BPMN source.
212-
* Activities include tasks, sub-processes, and call activities.
219+
* If set to `true`, ignore the font configurations defined in the BPMN LabelStyles.
220+
* This ensures font consistency in the rendered diagram.
213221
*
214222
* @default false
215223
* @since 0.48.0
216224
*/
217-
ignoreBpmnActivityLabelBounds?: boolean;
225+
ignoreBpmnLabelStyles?: boolean;
218226
/**
219227
* If set to `true`, ignore the label bounds configuration defined in the BPMN diagram for tasks only.
220228
* This forces the use of default label positioning for tasks instead of the bounds specified in the BPMN source.

test/shared/visu/bpmn-page-utils.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ class BpmnPage {
4646
) {}
4747

4848
async expectAvailableBpmnContainer(options?: PageWaitForSelectorOptions): Promise<void> {
49-
pageCheckLog('Expecting the BPMN container available (confirm bpmn-visualization initialization)');
49+
pageCheckLog('Waiting for the BPMN container to be initialized (verifying bpmn-visualization setup)');
50+
// Check that mxGraph updated the DOM with the SVG element. This is done during the bpmn-visualization initialization.
51+
// See BpmnQuerySelectors, the 2nd 'g' node contains the BPMN elements
5052
// eslint-disable-next-line jest/no-standalone-expect
51-
await expect(this.page).toMatchAttribute(`#${this.bpmnContainerId}`, 'style', /cursor: default/, options);
52-
pageCheckLog('BPMN container available');
53+
await expect(this.page).toHaveSelector(`#${this.bpmnContainerId} > svg > g > g:nth-child(2)`, options);
54+
pageCheckLog('BPMN container initialized');
5355
}
5456

5557
async expectPageTitle(title: string): Promise<void> {

test/unit/component/mxgraph/renderer/StyleComputer.test.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,61 @@ describe('Style Computer', () => {
479479
);
480480
});
481481

482+
describe('compute style - ignore BPMN label styles', () => {
483+
describe.each([[undefined], [false], [true]])(`Ignore BPMN label styles (renderer option): %s`, (ignoreBpmnLabelStyles: boolean) => {
484+
const styleComputer = new StyleComputer(ignoreBpmnLabelStyles === undefined ? {} : { ignoreBpmnLabelStyles });
485+
const expectFontStyles = !(ignoreBpmnLabelStyles ?? false);
486+
487+
function computeStyleWithIgnoreLabelStyles(element: Shape | Edge): string {
488+
return styleComputer.computeStyle(element, element.label?.bounds);
489+
}
490+
491+
describe('shapes', () => {
492+
it('shape with font family only', () => {
493+
const shape = new Shape('id', newShapeBpmnElement(ShapeBpmnElementKind.TASK_SCRIPT), undefined, new Label(toFont({ name: 'Roboto' }), undefined));
494+
const expectedFontStyle = expectFontStyles ? ';fontFamily=Roboto' : '';
495+
expect(computeStyleWithIgnoreLabelStyles(shape)).toBe(`scriptTask${expectedFontStyle}`);
496+
});
497+
498+
it('shape with bold font', () => {
499+
const shape = new Shape(
500+
'id',
501+
newShapeBpmnElement(ShapeBpmnElementKind.GATEWAY_EXCLUSIVE),
502+
undefined,
503+
new Label(toFont({ name: 'Courier', size: 9, isBold: true }), undefined),
504+
);
505+
const expectedFontStyle = expectFontStyles ? ';fontFamily=Courier;fontSize=9;fontStyle=1' : '';
506+
expect(computeStyleWithIgnoreLabelStyles(shape)).toBe(`exclusiveGateway${expectedFontStyle}`);
507+
});
508+
509+
it('shape with italic font', () => {
510+
const shape = new Shape(
511+
'id',
512+
newShapeBpmnElement(ShapeBpmnElementKind.EVENT_INTERMEDIATE_CATCH),
513+
undefined,
514+
new Label(toFont({ name: 'Arial', isItalic: true }), undefined),
515+
);
516+
const expectedFontStyle = expectFontStyles ? ';fontFamily=Arial;fontStyle=2' : '';
517+
expect(computeStyleWithIgnoreLabelStyles(shape)).toBe(`intermediateCatchEvent${expectedFontStyle}`);
518+
});
519+
});
520+
521+
describe('edges', () => {
522+
it('edge with strike-through font', () => {
523+
const edge = new Edge('id', newSequenceFlow(SequenceFlowKind.CONDITIONAL_FROM_ACTIVITY), undefined, new Label(toFont({ size: 14.2, isStrikeThrough: true }), undefined));
524+
const expectedFontStyle = expectFontStyles ? ';fontSize=14.2;fontStyle=8' : '';
525+
expect(computeStyleWithIgnoreLabelStyles(edge)).toBe(`sequenceFlow;conditional_from_activity${expectedFontStyle}`);
526+
});
527+
528+
it('edge with underline font', () => {
529+
const edge = new Edge('id', newSequenceFlow(SequenceFlowKind.DEFAULT), undefined, new Label(toFont({ isUnderline: true }), undefined));
530+
const expectedFontStyle = expectFontStyles ? ';fontStyle=4' : '';
531+
expect(computeStyleWithIgnoreLabelStyles(edge)).toBe(`sequenceFlow;default${expectedFontStyle}`);
532+
});
533+
});
534+
});
535+
});
536+
482537
describe('compute style - colors', () => {
483538
describe.each([[undefined], [false], [true]])(`Ignore BPMN colors: %s`, (ignoreBpmnColors: boolean) => {
484539
// 'undefined' RendererOptions tested in other tests in this file

0 commit comments

Comments
 (0)