mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 09:12:52 +00:00
utilSetDimensions should always return a selection for chaining Add `force` argument to utilGetDimensions to override cached dimensions
32 lines
903 B
JavaScript
32 lines
903 B
JavaScript
function refresh(selection, node) {
|
|
var cr = node.getBoundingClientRect();
|
|
var prop = [cr.width, cr.height];
|
|
selection.property('__dimensions__', prop);
|
|
return prop;
|
|
}
|
|
|
|
export function utilGetDimensions(selection, force) {
|
|
if (!selection || selection.empty()) {
|
|
return [0, 0];
|
|
}
|
|
var node = selection.node(),
|
|
cached = selection.property('__dimensions__');
|
|
return (!cached || force) ? refresh(selection, node) : cached;
|
|
}
|
|
|
|
|
|
export function utilSetDimensions(selection, dimensions) {
|
|
if (!selection || selection.empty()) {
|
|
return selection;
|
|
}
|
|
var node = selection.node();
|
|
if (dimensions === null) {
|
|
refresh(selection, node);
|
|
return selection;
|
|
}
|
|
return selection
|
|
.property('__dimensions__', [dimensions[0], dimensions[1]])
|
|
.attr('width', dimensions[0])
|
|
.attr('height', dimensions[1]);
|
|
}
|