jaumard / ngx-dashboard

Dashboard library for angular 4 and more
https://jaumard.github.io/ngx-dashboard/demo/demoDist/index.html
MIT License
71 stars 31 forks source link

infinite loop in _positionWidget #14

Closed michalkotas closed 7 years ago

michalkotas commented 7 years ago

If widget width (size[0]) is bigger than current _nbColumn 'while' loop in _positionWidget will never end. while ((lines[column] > 0) || !haveEnoughSpace)

Tested on version 1.1.4

How to reproduce:

Quick hack solution is to add itemWiderThanContainer:

const itemWiderThanContainer = item.size[0] > this._nbColumn;

let haveEnoughSpace = column + item.size[0] - 1 <= this._nbColumn || itemWiderThanContainer;

while ((lines[column] > 0) || !haveEnoughSpace) {
  column++;
  haveEnoughSpace = column + item.size[0] - 1 <= this._nbColumn || itemWiderThanContainer;

  if (column >= this._nbColumn) {
    column = 0;
    for (let i = 0; i < lines.length; i++) {
      lines[i]--;
    }
    row++;
    haveEnoughSpace = column + item.size[0] - 1 <= this._nbColumn || itemWiderThanContainer;
  }

  if (!haveEnoughSpace) continue;
  for (let i = 1; i < item.size[0]; i++) {
    haveEnoughSpace = lines[column + i] <= 0 || itemWiderThanContainer;
    if (!haveEnoughSpace) break;
  }
}
jaumard commented 7 years ago

You're right, I miss that use case :) thanks for the report and example :D What would be the best fix then ? Force the widget width at the max available ?

What does your fix do exactly ?

jaumard commented 7 years ago

So for now I force the widget at the maximum of the pages, I think it's the best way to have coherent UI and not an infinite loop. You can always override this behavior yourself by listening window.resize event and set the width you want (but less than max available) Thanks again ! :)

michalkotas commented 7 years ago

Thanks for quick update, infinite loop issue has been resolved.

..but there's a strange resize behavior - details in #15

jaumard commented 7 years ago

Ho I see the override stay even when windows gets bigger... I'll try to look at it soon! Can you open a new issue for this? The most urgent was the infinite loop witch is fixed it will be more clear. Thanks :)