# Restrict BPMN modeler within window

**URL:** <https://forum.bpmn.io/t/restrict-bpmn-modeler-within-window/3591>\
**Category:** Developers\
**Created:** [July 3, 2019, 6:06am UTC](https://forum.bpmn.io/t/restrict-bpmn-modeler-within-window/3591 "2019-07-03T06:06:51Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![venkatesh\_bs](https://forum.bpmn.io/user_avatar/forum.bpmn.io/venkatesh_bs/32/1401_2.png) [@venkatesh\_bs](https://forum.bpmn.io/u/venkatesh_bs)\
**Post date:** [July 3, 2019, 6:06am UTC](https://forum.bpmn.io/t/restrict-bpmn-modeler-within-window/3591/1 "2019-07-03T06:06:51Z")

</div>

Hi Team,

I have created the bpmn modeler with scroll bar. However when i tried to insert the diagram in workspace it is scrollable beyond window screen. How to restrict the diagram to not to move upwards at the scroll bar initial position. image|1600x645

---

<div class="post-metadata">

**Author:** ![philippfromme](https://forum.bpmn.io/user_avatar/forum.bpmn.io/philippfromme/32/2803_2.png) [@philippfromme](https://forum.bpmn.io/u/philippfromme)\
**Post date:** [July 4, 2019, 12:44pm UTC](https://forum.bpmn.io/t/restrict-bpmn-modeler-within-window/3591/2 "2019-07-04T12:44:57Z")

</div>

Do you mind sharing a screenshot?

---

<div class="post-metadata">

**Author:** ![venkatesh\_bs](https://forum.bpmn.io/user_avatar/forum.bpmn.io/venkatesh_bs/32/1401_2.png) [@venkatesh\_bs](https://forum.bpmn.io/u/venkatesh_bs)\
**Post date:** [July 4, 2019, 1:14pm UTC](https://forum.bpmn.io/t/restrict-bpmn-modeler-within-window/3591/3 "2019-07-04T13:14:19Z")

</div>

![flowchart](https://forum.bpmn.io/uploads/default/original/2X/2/26f83e0624d4eab63cc39713733c205cca748fce.jpeg)

You see the minimum position of scroll bar at the top position. However the flow chart draggable above container

---

<div class="post-metadata">

**Author:** ![philippfromme](https://forum.bpmn.io/user_avatar/forum.bpmn.io/philippfromme/32/2803_2.png) [@philippfromme](https://forum.bpmn.io/u/philippfromme)\
**Post date:** [July 4, 2019, 2:20pm UTC](https://forum.bpmn.io/t/restrict-bpmn-modeler-within-window/3591/4 "2019-07-04T14:20:21Z")

</div>

Have you made yourself familiar with our toolkits? The canvas is infinite by default. You’d need to restrict it.

---

<div class="post-metadata">

**Author:** ![venkatesh\_bs](https://forum.bpmn.io/user_avatar/forum.bpmn.io/venkatesh_bs/32/1401_2.png) [@venkatesh\_bs](https://forum.bpmn.io/u/venkatesh_bs)\
**Post date:** [July 8, 2019, 4:50am UTC](https://forum.bpmn.io/t/restrict-bpmn-modeler-within-window/3591/5 "2019-07-08T04:50:49Z")

</div>

Thanks philip. It seems the position is working on degrees. Its too difficult to find out the position to restrict it. Kindly confirm how to restrict within visible area instead of infinite in canvas. It will be helpful if you share some idea on code.

I could see this code

- canvas.viewbox({ x: 100, y: 100, width: 500, height: 500 })

---

<div class="post-metadata">

**Author:** ![venkatesh\_bs](https://forum.bpmn.io/user_avatar/forum.bpmn.io/venkatesh_bs/32/1401_2.png) [@venkatesh\_bs](https://forum.bpmn.io/u/venkatesh_bs)\
**Post date:** [July 8, 2019, 10:05am UTC](https://forum.bpmn.io/t/restrict-bpmn-modeler-within-window/3591/6 "2019-07-08T10:05:28Z")

</div>

Hi Philip,

Any update on this. Expecting your response.

---

<div class="post-metadata">

**Author:** ![philippfromme](https://forum.bpmn.io/user_avatar/forum.bpmn.io/philippfromme/32/2803_2.png) [@philippfromme](https://forum.bpmn.io/u/philippfromme)\
**Post date:** [July 8, 2019, 10:58am UTC](https://forum.bpmn.io/t/restrict-bpmn-modeler-within-window/3591/7 "2019-07-08T10:58:55Z")

</div>

What have you tried already to achieve this?

---

<div class="post-metadata">

**Author:** ![venkatesh\_bs](https://forum.bpmn.io/user_avatar/forum.bpmn.io/venkatesh_bs/32/1401_2.png) [@venkatesh\_bs](https://forum.bpmn.io/u/venkatesh_bs)\
**Post date:** [July 8, 2019, 11:01am UTC](https://forum.bpmn.io/t/restrict-bpmn-modeler-within-window/3591/8 "2019-07-08T11:01:43Z")

</div>

Hi Philippe,

I have tried to restrict the position to avoid overflow from container in dragging.js. But nothing worked.

---

<div class="post-metadata">

**Author:** ![ShefaliAgarwal](https://forum.bpmn.io/user_avatar/forum.bpmn.io/shefaliagarwal/32/1467_2.png) [@ShefaliAgarwal](https://forum.bpmn.io/u/ShefaliAgarwal)\
**Post date:** [October 19, 2019, 3:35am UTC](https://forum.bpmn.io/t/restrict-bpmn-modeler-within-window/3591/9 "2019-10-19T03:35:02Z")

</div>

Hi Venkatesh,

I am facing the same issue, did you find the solution?

---

<div class="post-metadata">

**Author:** ![DevAutomationInf](https://forum.bpmn.io/letter_avatar_proxy/v4/letter/d/b19c9b/32.png) [@DevAutomationInf](https://forum.bpmn.io/u/DevAutomationInf)\
**Post date:** [December 10, 2024, 10:29am UTC](https://forum.bpmn.io/t/restrict-bpmn-modeler-within-window/3591/10 "2024-12-10T10:29:50Z")

</div>

This is my attempt to a solution for this: [StackBlitz](https://stackblitz.com/~/github.com/DevAutomationInf/custom-font?file=src/app/custom/custom-canvas.ts) However this is not working well when scale is changed because it has a lag and the mouse gets stuck.

```auto
import Canvas, { CanvasConfig } from 'diagram-js/lib/core/Canvas';
import ElementRegistry from 'diagram-js/lib/core/ElementRegistry';
import EventBus from 'diagram-js/lib/core/EventBus';
import GraphicsFactory from 'diagram-js/lib/core/GraphicsFactory';
import { Point, ScrollDelta } from 'diagram-js/lib/util/Types';

export default class CustomCanvas extends Canvas {
  static override $inject = ['config.canvas', 'eventBus', 'graphicsFactory', 'elementRegistry'];

  //eslint-disable-next-line @typescript-eslint/no-explicit-any
  constructor(
    config: CanvasConfig | null,
    eventBus: EventBus,
    graphicsFactory: GraphicsFactory,
    elementRegistry: ElementRegistry,
  ) {
    super(config, eventBus, graphicsFactory, elementRegistry);
  }

  override scroll(delta?: ScrollDelta): Point {
    const viewbox = this.viewbox();
    const scale = viewbox.scale || 1; // Ensure scale is not undefined or 0

    if (delta) {
      const { dx, dy } = delta;

      // Scale the deltas to match the current scale
      const scaledDx = (dx || 0) / scale;
      const scaledDy = (dy || 0) / scale;

      const nextY = viewbox.y - scaledDy;
      const nextX = viewbox.x - scaledDx;

      // Adjust limits for the scaled viewbox
      const minX = viewbox.inner.width + viewbox.inner.x - viewbox.outer.width / scale;
      const minY = viewbox.inner.height + viewbox.inner.y - viewbox.outer.height / scale;
      const maxX = viewbox.inner.x;
      const maxY = viewbox.inner.y;

      // Check if the next position is within bounds
      if (nextY < maxY && nextX < maxX && nextX > minX && nextY > minY) {
        return super.scroll({ dx: scaledDx, dy: scaledDy });
      }
    }

    return { x: viewbox.x, y: viewbox.y }; // Return the current position if out of bounds
  }
}

    this.modeler = new Modeler({
      container: this.bpmnModeler.nativeElement,
      additionalModules: [
        {
          __init__ : ['customRenderer','resizeTasks'],
          customRenderer: ['type', CustomRenderer],
          resizeTasks: ['type', CustomRules],
          canvas: ['type', CustomCanvas],
        },
      ],
      moddleExtensions: MODDLE_EXTENSIONS,
    });

```

Can anyone please suggest an improvement?

---

<div class="post-metadata">

**Author:** ![jarekdanielak](https://forum.bpmn.io/user_avatar/forum.bpmn.io/jarekdanielak/32/5522_2.png) [@jarekdanielak](https://forum.bpmn.io/u/jarekdanielak)\
**Post date:** [December 17, 2024, 11:44am UTC](https://forum.bpmn.io/t/restrict-bpmn-modeler-within-window/3591/11 "2024-12-17T11:44:43Z")

</div>

Please do not [necrobump](https://www.urbandictionary.com/define.php?term=necrobump) old topics. Instead [link to this thread from new topic](https://forum.bpmn.io/t/reply-as-a-linked-topic/7489).

---

<div class="post-metadata">

**Author:** ![jarekdanielak](https://forum.bpmn.io/user_avatar/forum.bpmn.io/jarekdanielak/32/5522_2.png) [@jarekdanielak](https://forum.bpmn.io/u/jarekdanielak)\
**Post date:** [December 17, 2024, 11:44am UTC](https://forum.bpmn.io/t/restrict-bpmn-modeler-within-window/3591/12 "2024-12-17T11:44:53Z")

</div>

Closed on December 17, 2024, 11:44am UTC


