Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Fit horizontally the viewport on diagram load #834

Merged
merged 2 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/component/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ export enum FitType {
None,
/** Fit the whole viewport. */
HorizontalVertical,
/** Fit only horizontally. */
Horizontal,
}
7 changes: 5 additions & 2 deletions src/component/mxgraph/BpmnMxGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { FitType } from '../Options';

export class BpmnMxGraph extends mxGraph {
private cumulativeZoomFactor = 1;

Expand All @@ -27,8 +29,9 @@ export class BpmnMxGraph extends mxGraph {
return scale;
}

public customFit(): void {
this.fit(this.border, false, 0, true, false, false);
public customFit(type: FitType): void {
const ignoreHeight = type === FitType.Horizontal;
this.fit(this.border, false, 0, true, false, ignoreHeight);
}

// solution inspired by https://github.com/algenty/grafana-flowcharting/blob/0.9.0/src/graph_class.ts#L1254
Expand Down
2 changes: 1 addition & 1 deletion src/component/mxgraph/MxGraphRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class MxGraphRenderer {
this.insertShapesAndEdges(bpmnModel);

if (type != FitType.None) {
this.graph.customFit();
this.graph.customFit(type);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ <h3>Options</h3>
<select name="fitTypes" id="fitType-selected">
<option value="None" selected="yes">None</option>
<option value="HorizontalVertical">Horizontal-Vertical</option>
<option value="Horizontal">Horizontal</option>
</select>
</label>
</div>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions test/e2e/diagram.rendering.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,25 @@ describe('no diagram visual regression', () => {
windows: 0.0035,
},
],
[
'vertical',
// minimal threshold to make test pass on Github Workflow
// ubuntu: Expected image to match or be a close match to snapshot but was 0.0019441198722769393% different from snapshot
// macOS: Expected image to match or be a close match to snapshot but was 0.0019441198722769393% different from snapshot
// windows: Expected image to match or be a close match to snapshot but was 0.0019441198722769393% different from snapshot
{
linux: 0.00002,
macos: 0.00002,
windows: 0.00002,
},
],
]),
);

describe.each([
[FitType[FitType.None], FitType.None],
[FitType[FitType.HorizontalVertical], FitType.HorizontalVertical],
[FitType[FitType.Horizontal], FitType.Horizontal],
])('load options: %s fit', async (fitTitle: string, fitType: FitType) => {
const bpmnDiagramPreparation = new BpmnDiagramPreparation(new Map<string, BpmnLoadMethod>([]), { name: 'non-regression' }, 'diagram', { fitType });
const pageTester = new PageTester(bpmnDiagramPreparation, 'viewport', 'BPMN Visualization Non Regression');
Expand Down