MCPcopy
hub / github.com/microsoft/SandDance / gridLayout

Function gridLayout

docs/tests/v2/es6/js/sanddance.js:103844–104035  ·  view source on GitHub ↗
(view, groups, opt)

Source from the content-addressed store, hash-verified

103842}
103843
103844function gridLayout(view, groups, opt) {
103845 var dirty = !opt.nodirty,
103846 bbox = opt.bounds === _constants.Flush ? bboxFlush : bboxFull,
103847 bounds = _util.tempBounds.set(0, 0, 0, 0),
103848 alignCol = get(opt.align, _constants.Column),
103849 alignRow = get(opt.align, _constants.Row),
103850 padCol = get(opt.padding, _constants.Column),
103851 padRow = get(opt.padding, _constants.Row),
103852 ncols = opt.columns || groups.length,
103853 nrows = ncols < 0 ? 1 : Math.ceil(groups.length / ncols),
103854 n = groups.length,
103855 xOffset = Array(n),
103856 xExtent = Array(ncols),
103857 xMax = 0,
103858 yOffset = Array(n),
103859 yExtent = Array(nrows),
103860 yMax = 0,
103861 dx = Array(n),
103862 dy = Array(n),
103863 boxes = Array(n),
103864 m,
103865 i,
103866 c,
103867 r,
103868 b,
103869 g,
103870 px,
103871 py,
103872 x,
103873 y,
103874 offset;
103875
103876 for (i = 0; i < ncols; ++i) xExtent[i] = 0;
103877
103878 for (i = 0; i < nrows; ++i) yExtent[i] = 0; // determine offsets for each group
103879
103880
103881 for (i = 0; i < n; ++i) {
103882 g = groups[i];
103883 b = boxes[i] = bbox(g);
103884 g.x = g.x || 0;
103885 dx[i] = 0;
103886 g.y = g.y || 0;
103887 dy[i] = 0;
103888 c = i % ncols;
103889 r = ~~(i / ncols);
103890 xMax = Math.max(xMax, px = Math.ceil(b.x2));
103891 yMax = Math.max(yMax, py = Math.ceil(b.y2));
103892 xExtent[c] = Math.max(xExtent[c], px);
103893 yExtent[r] = Math.max(yExtent[r], py);
103894 xOffset[i] = padCol + offsetValue(b.x1);
103895 yOffset[i] = padRow + offsetValue(b.y1);
103896 if (dirty) view.dirty(groups[i]);
103897 } // set initial alignment offsets
103898
103899
103900 for (i = 0; i < n; ++i) {
103901 if (i % ncols === 0) xOffset[i] = 0;

Callers 1

trellisLayoutFunction · 0.70

Calls 6

getFunction · 0.70
offsetValueFunction · 0.70
clearMethod · 0.65
setMethod · 0.45
maxMethod · 0.45
translateMethod · 0.45

Tested by

no test coverage detected