utilSetDimensions/utilGetDimensions improvements

utilSetDimensions should always return a selection for chaining
Add `force` argument to utilGetDimensions to override cached dimensions
This commit is contained in:
Bryan Housel
2016-10-27 14:13:39 -04:00
parent 38e0b4ba5d
commit 5fb966c35b
2 changed files with 9 additions and 8 deletions
+2 -2
View File
@@ -6,7 +6,7 @@ import { tooltip } from '../util/tooltip';
import { svgDefs, svgIcon } from '../svg/index';
import { modeBrowse } from '../modes/index';
import { behaviorHash } from '../behavior/index';
import { utilSetDimensions } from '../util/dimensions';
import { utilGetDimensions } from '../util/dimensions';
import { uiAccount } from './account';
import { uiAttribution } from './attribution';
@@ -229,7 +229,7 @@ export function uiInit(context) {
var mapDimensions = map.dimensions();
function onResize() {
mapDimensions = utilSetDimensions(content, null);
mapDimensions = utilGetDimensions(content, true);
map.dimensions(mapDimensions);
}
+7 -6
View File
@@ -5,23 +5,24 @@ function refresh(selection, node) {
return prop;
}
export function utilGetDimensions(selection) {
export function utilGetDimensions(selection, force) {
if (!selection || selection.empty()) {
return [0, 0];
}
var node = selection.node();
return selection.property('__dimensions__') || refresh(selection, node);
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 [0, 0];
return selection;
}
var node = selection.node();
if (dimensions === null) {
return refresh(selection, node);
refresh(selection, node);
return selection;
}
return selection
.property('__dimensions__', [dimensions[0], dimensions[1]])