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

add a validation callback on item/grid to be called inside checkColission #293

Closed
Chibas opened this issue Apr 6, 2018 · 4 comments
Closed
Milestone

Comments

@Chibas
Copy link

Chibas commented Apr 6, 2018

Hello. Is there a way to keep aspect ratio of my grid items?
I've tried something like

`static itemResize(item: GridsterItem, itemComponent: GridsterItemComponentInterface) {

    let deltaOld = item.minItemCols - item.minItemRows;
    let deltaNew =  item.cols - item.rows;
    if (deltaNew !== deltaOld) {
         deltaNew > 0 ? item.cols += deltaNew : item.rows += deltaNew;
    }

}`

But that did not affect anything at all. Can i directly set resizable item dimensions on the go?

@tiberiuzuld
Copy link
Owner

Hi @Chibas ,
You can set minItemRows/minItemCols/minItemArea.
Or you can use the push API to resize a item from code.
I think is up to the user to set his widgets how he thinks he is ok with.

About aspect ratio:
It is relative to the screen size / available space for the grid and gridType.
If you choose for example the gridType vertical scroll, then the widgets will be square.

@GMacAussie
Copy link

We have a similar situation where we have dial graph widgets in the mix that should only be square.

We did the following to the code (sorry) - this is for AngularJS:

  1. Added an aspectRatio variable to the vm.$item initialisation:

aspectRatio: undefined

  1. Modified vm.checkGridCollision to enforce aspect ratio. NOTE! We only need 1:1 so this is not generalised - it suited our purpose however:
  vm.checkGridCollision = function checkGridCollision(item) {
      // handle locked aspect ratio. 1 to 1 only at the moment
      if (item.aspectRatio) {
        if ((item.rows != item.rowsA) && (item.cols != item.colsA)) {
            item.cols = item.rows;
        } else if (item.rows != item.rowsA) {
            item.cols = item.rows;
        } else if (item.cols != item.colsA) {
            item.rows = item.cols;
        }

        item.rowsA = item.rows;
        item.colsA = item.cols;
      }

I am not sure this is the best way but it got us over non-square dial graphs.

@tiberiuzuld
Copy link
Owner

tiberiuzuld commented Apr 10, 2018

Hmm, interesting, maybe is better to add a validation callback on item/grid to be called inside checkColission.
That will fix these kind of issues more generally.

@tiberiuzuld tiberiuzuld changed the title Keep aspect ratio while resizing add a validation callback on item/grid to be called inside checkColission Apr 20, 2018
@tiberiuzuld
Copy link
Owner

Added in v5.3.0

@tiberiuzuld tiberiuzuld added this to the 5.x milestone Apr 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants