You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now when you click on Add collection the collection is place on the top left corner of the visible area of the canvas, if a blind person tries to add more than one collection they will be place stacked, that's not an accesible approach.
The idea is to implement an algorithm that:
Will find for free spots (or at least the ones with less collision area).
Will propose a where to place the collection starting in the center of the visible area.
Will place next tables following an spiral path.
Once the table is added we should highlight it using some animation just to let the user know where has been placed.
import{Box,Size}from"../model";import{calculateCollisionArea,isOverlapping}from"./canvas.utils";function*spiralPositions(centerX: number,centerY: number,canvasSize: Size): Generator<[number,number]>{letx=0,y=0,dx=0,dy=-1;for(leti=0;i<Math.max(canvasSize.width,canvasSize.height)**2;i++){if(-canvasSize.width/2<x&&x<canvasSize.width/2&&-canvasSize.height/2<y&&y<canvasSize.height/2){yield[centerX+x,centerY+y];}if(x===y||(x<0&&x===-y)||(x>0&&x===1-y)){[dx,dy]=[-dy,dx];}x+=dx;y+=dy;}}exportfunctionfindFreePositionOrMinCollision(boxes: Box[],newBoxSize: Size,canvasSize: Size): Box|null{constcenterX=Math.floor(canvasSize.width/2);constcenterY=Math.floor(canvasSize.height/2);letminCollisionBox: Box|null=null;letminCollisionArea=Infinity;for(const[x,y]ofspiralPositions(centerX,centerY,canvasSize)){constnewBox={
x,
y,width: newBoxSize.width,height: newBoxSize.height,// TODO: we will remove this once we get rid of the poc// and integrate this into the main appcolor: "orange",};if(x>=0&&y>=0&&x+newBoxSize.width<=canvasSize.width&&y+newBoxSize.height<=canvasSize.height){letcollisionArea=0;letisFree=true;for(constexistingBoxofboxes){if(isOverlapping(newBox,existingBox)){isFree=false;collisionArea+=calculateCollisionArea(newBox,existingBox);}}if(isFree){returnnewBox;}if(collisionArea<minCollisionArea){minCollisionArea=collisionArea;minCollisionBox=newBox;}}}if(minCollisionBox!==null){returnminCollisionBox;}// TODO: if no free position is found, return a random onereturnnull;}
Now on the Add table handler let's use the findFreePositionOrMinCollision, to add a new collection, things to take into consideration:
Let's map all the tables from TableVm to Box (just create a mapper), to take into account we will have to calculate the fullsize of each table (witdth and height) and add a margin e.g. 40px.
Then call findFreePositionOrMinCollision passing the box collection and the current view size ( canvasViewSettings.scrollPosition.x, canvasViewSettings.scrollPosition.y, and the current subview with the width and height of the part that is shown.
Add some transition or animation to highlight the table temporarily once is created
Check that the approach is working, then we will do a second iteration (refactor the code, add unit testing etc...)
The text was updated successfully, but these errors were encountered:
I have added a commit in the feature/#507-implement-autoarrange branch implementing autoarrange collection. I will add some animation to highlight the table once created. After that I will create the pull request linking this issue.
Right now when you click on Add collection the collection is place on the top left corner of the visible area of the canvas, if a blind person tries to add more than one collection they will be place stacked, that's not an accesible approach.
The idea is to implement an algorithm that:
Once the table is added we should highlight it using some animation just to let the user know where has been placed.
There's an initial POC implemented:
https://github.com/Lemoncode/auto-arrange-playground
And how it works:
autoarrange.mp4
A previous discussion is needed before starting integrating the POC, the steps:
Steps to implement this:
In common under common/helper create a subfolder called
autorrange-table
.Under that subfolder create a
autoarrange-table.model.ts
we will slightly update the model (removecolor
field)../src/common/autoarrange-table/autoarrange-table.model.ts
./src/common/autoarrange-table/autoarrange-table.utils.ts
And create the main file:
./src/common/autoarrange-table/index.ts
Now on the Add table handler let's use the
findFreePositionOrMinCollision
, to add a new collection, things to take into consideration:TableVm
toBox
(just create a mapper), to take into account we will have to calculate the fullsize of each table (witdth and height) and add a margin e.g. 40px.findFreePositionOrMinCollision
passing the box collection and the current view size (canvasViewSettings.scrollPosition.x
,canvasViewSettings.scrollPosition.y
, and the current subview with the width and height of the part that is shown.Check that the approach is working, then we will do a second iteration (refactor the code, add unit testing etc...)
The text was updated successfully, but these errors were encountered: