MCPcopy Index your code
hub / github.com/bqplot/bqplot / getFigureSize

Method getFigureSize

js/src/Figure.ts:104–249  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

102 }
103
104 protected getFigureSize(): IFigureSize {
105 const domSize: IFigureSize = this.el.getBoundingClientRect();
106
107 if (!this.autoLayout) {
108 const clientRectRatio = domSize.width / domSize.height;
109
110 const minRatio: number = this.model.get('min_aspect_ratio');
111 const maxRatio: number = this.model.get('max_aspect_ratio');
112
113 if (clientRectRatio < minRatio) {
114 // Too much vertical space: Keep horizontal space but compute height from min aspect ratio
115 domSize.height = domSize.width / minRatio;
116 } else if (clientRectRatio > maxRatio) {
117 // Too much horizontal space: Keep vertical space but compute width from max aspect ratio
118 domSize.width = domSize.height * maxRatio;
119 }
120
121 return domSize;
122 }
123
124 let solver = new kiwi.Solver();
125 var width = new kiwi.Variable();
126 var height = new kiwi.Variable();
127
128 // calculate padding by summing up all auto sizes + fig_margins
129 var padding = { top: 0, bottom: 0, left: 0, right: 0 };
130 const fig_margin = this.model.get('fig_margin');
131 ['top', 'bottom', 'left', 'right'].forEach((side) => {
132 padding[side] = this.decorators[side].reduce((total, decorator) => {
133 decorator.setAutoOffset(total);
134 return total + decorator.calculateAutoSize();
135 }, 0);
136 padding[side] += fig_margin[side];
137 });
138
139 solver.addEditVariable(width, kiwi.Strength.strong);
140 solver.addEditVariable(height, kiwi.Strength.strong);
141 solver.suggestValue(width, domSize.width);
142 solver.suggestValue(height, domSize.height);
143
144 /*
145 We want the figure size to always be inside the dom element:
146 width + padding.left + padding.right <= domSize.width
147 width + padding.left + padding.right - domSize.width < 0
148 If we don't add these constraints, the width and height might actually grow
149 */
150 solver.addConstraint(
151 new kiwi.Constraint(
152 new kiwi.Expression(width, padding.left, padding.right, -domSize.width),
153 kiwi.Operator.Le
154 )
155 );
156 // and similarly for the height
157 solver.addConstraint(
158 new kiwi.Constraint(
159 new kiwi.Expression(
160 height,
161 padding.top,

Callers 7

renderImplMethod · 0.95
relayoutImplMethod · 0.95
renderImplMethod · 0.80
relayoutMethod · 0.80
coloraxis.tsFile · 0.80
figure.tsFile · 0.80
axis.tsFile · 0.80

Calls 2

setAutoOffsetMethod · 0.80
calculateAutoSizeMethod · 0.45

Tested by

no test coverage detected