interact.js icon indicating copy to clipboard operation
interact.js copied to clipboard

.restrict({ }) with SVG transform issue

Open alkhoo opened this issue 11 years ago • 2 comments

Was trying to figure out how to use the restrict if my SVG canvas is 200 x 200 and i have a %lt;g>roup that is as follows:-

<g id="svg_name" transform="matrix(1,0,0,1,21,19)">
<rect data-index="0" class="edit-rectangle" x="0" y="0" width="100" height="100" stroke-width="1"></rect>
</g>

.rectChecker() can be rewritten to pull x=21, y = 19, and height=100, width=100 (ie:resulting in bottom=119 and right=121).

Question: How do I add a .restrict() to keep this rect within the 200x200 SVG?

alkhoo avatar Jan 19 '15 10:01 alkhoo

The interactable.restrict({drag: ..., resize: ..., endOnly: true, ... }) method is deprecated. You should use

interactable.<actionable>({
  restrict: {
    restriction: ...,
    endOnly: true,
    ...
  },
})

To answer your question, it depends on a few things including:

  • What origin you're using.
  • The svg element's position. At the top-left of the page with no margin, border or padding is the easiest to work with.

It could be enough to use restriction: 'svg' if the parent svg element is at the top-left of the page. restriction: { x: 0, y: 0, width: 200, height: 200 } should work in either case, I think.

taye avatar Jan 20 '15 10:01 taye

@alkhoo Did you get this working?

taye avatar Feb 22 '15 14:02 taye