Skip to content

Commit

Permalink
cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
kepta committed Aug 24, 2017
1 parent 91a5699 commit 909b72a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 107 deletions.
1 change: 0 additions & 1 deletion modules/core/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { utilRebind } from '../util/rebind';
import { utilCallWhenIdle } from '../util/index';



export var areaKeys = {};

export function setAreaKeys(value) {
Expand Down
115 changes: 18 additions & 97 deletions modules/renderer/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { utilGetDimensions } from '../util/dimensions';




export function rendererMap(context) {

var dimensions = [1, 1],
Expand All @@ -58,46 +57,31 @@ export function rendererMap(context) {
mouse,
mousemove;

// var debouncedTransformStart = () => requestAnimationFrame(() => transformStart = projection.transform());
// var setProjectionTransformStart = () => debSetTransformStart(projection.transform());

// var debSetTransformStart = _.debounce((val) => transformStart = val, 50);

// const debouncedTransform
// var projectIdleCb;
var savedToDrawVertices;
var saveToDrawLines;
var saveToDrawArea;
var saveToDrawMidpoints;
var saveToDrawLabels;
var saveToDrawPoints;

var zoom = d3.zoom()
.scaleExtent([ztok(2), ztok(24)])
.interpolate(d3.interpolate)
.filter(zoomEventFilter)
.on('zoom', zoomPan);

var _selection = d3.select(null);
var isRenderScheduled = false;
var isRedrawScheduled = false;
var pendingRedrawCall;
function initiateRedraw() {
// Reset the boolean so future redraws can be set.
isRenderScheduled = false;
redraw.apply(this, arguments);
}


function scheduleRedraw() {
// Only schedule the redraw if one has not already been set.
if (isRenderScheduled) return;

isRenderScheduled = true;

pendingRedrawCall = requestIdleCallback(() => initiateRedraw.apply(this, arguments), { timeout: 1400 });
if (isRedrawScheduled) return;
isRedrawScheduled = true;
var that = this;
var args = arguments;
pendingRedrawCall = requestIdleCallback(function () {
// Reset the boolean so future redraws can be set.
isRedrawScheduled = false;
redraw.apply(that, args);
}, { timeout: 1400 });
}

function cancelPendingRedraw() {
isRenderScheduled = false;
isRedrawScheduled = false;
window.cancelIdleCallback(pendingRedrawCall);
}

Expand Down Expand Up @@ -301,67 +285,6 @@ export function rendererMap(context) {
.call(drawLabels, graph, data, filter, dimensions, !difference && !extent)
.call(drawPoints, graph, data, filter);

// var toDrawVertices = (selection) => {
// // window.cancelIdleCallback(savedToDrawVertices);
// savedToDrawVertices = requestIdleCallback(() => {
// drawVertices(selection, graph, data, filter, map.extent(), map.zoom());
// setProjectionTransformStart();
// toDrawLines(selection);
// }, {timeout: 150});
// };

// var toDrawLines = (selection) => {
// // window.cancelIdleCallback(saveToDrawLines);
// saveToDrawLines = requestIdleCallback(() => {
// drawLines(selection, graph, data, filter);
// // setProjectionTransformStart();
// toDrawAreas(selection);
// }, {timeout: 150});
// };

// var toDrawAreas = (selection) => {
// // window.cancelIdleCallback(saveToDrawArea);
// saveToDrawArea = requestIdleCallback(() => {
// drawAreas(selection, graph, data, filter);
// // setProjectionTransformStart();
// toDrawMidpoints(selection);
// }, {timeout: 150});
// };

// var toDrawMidpoints = (selection) => {
// // window.cancelIdleCallback(saveToDrawMidpoints);
// saveToDrawMidpoints = requestIdleCallback(() => {
// drawMidpoints(selection,graph, data, filter, map.trimmedExtent());
// // setProjectionTransformStart();
// toDrawLabels(selection);
// }, {timeout: 150});
// };

// var toDrawLabels = (selection) => {
// // window.cancelIdleCallback(saveToDrawLabels);
// saveToDrawLabels = requestIdleCallback(() => {
// drawLabels(selection, graph, data, filter, dimensions, !difference && !extent);
// // setProjectionTransformStart();
// toDrawPoints(selection);
// }, {timeout: 150});
// };

// var toDrawPoints = (selection) => {
// // window.cancelIdleCallback(saveToDrawPoints);
// saveToDrawPoints = requestIdleCallback(() => {
// drawPoints(selection, graph, data, filter);
// setProjectionTransformStart();
// }, {timeout: 150});
// };

// surface.selectAll('.data-layer-osm')
// .call(toDrawVertices)
// .call(toDrawLines)
// .call(toDrawAreas)
// .call(toDrawMidpoints)
// .call(toDrawLabels)
// .call(toDrawPoints);

dispatch.call('drawn', this, {full: true});
}

Expand Down Expand Up @@ -419,7 +342,7 @@ export function rendererMap(context) {
surface.interrupt();
uiFlash().text(t('cannot_zoom'));
setZoom(context.minEditableZoom(), true);
queueRedraw();
scheduleRedraw();
dispatch.call('move', this, map);
return;
}
Expand All @@ -442,7 +365,7 @@ export function rendererMap(context) {
transformed = true;
transformLast = eventTransform;
utilSetTransform(supersurface, tX, tY, scale);
queueRedraw();
scheduleRedraw();

dispatch.call('move', this, map);
}
Expand Down Expand Up @@ -499,8 +422,6 @@ export function rendererMap(context) {
}


var queueRedraw = scheduleRedraw;


var immediateRedraw = function(difference, extent) {
if (!difference && !extent) cancelPendingRedraw();
Expand Down Expand Up @@ -672,7 +593,7 @@ export function rendererMap(context) {
mouse = utilFastMouse(supersurface.node());
setCenter(center);

queueRedraw();
scheduleRedraw();
return map;
};

Expand Down Expand Up @@ -701,7 +622,7 @@ export function rendererMap(context) {
dispatch.call('move', this, map);
}

queueRedraw();
scheduleRedraw();
return map;
};

Expand All @@ -721,7 +642,7 @@ export function rendererMap(context) {
dispatch.call('move', this, map);
}

queueRedraw();
scheduleRedraw();
return map;
};

Expand All @@ -744,7 +665,7 @@ export function rendererMap(context) {
dispatch.call('move', this, map);
}

queueRedraw();
scheduleRedraw();
return map;
};

Expand Down
5 changes: 3 additions & 2 deletions modules/svg/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { utilDetect } from '../util/detect';
import {
utilDisplayName,
utilDisplayNameForPath,
utilEntitySelector
utilEntitySelector,
utilCallWhenIdle
} from '../util/index';


Expand Down Expand Up @@ -652,7 +653,7 @@ export function svgLabels(projection, context) {
}


var throttleFilterLabels = _.throttle(filterLabels, 100);
var throttleFilterLabels = _.throttle(utilCallWhenIdle(filterLabels), 100);


drawLabels.observe = function(selection) {
Expand Down
4 changes: 2 additions & 2 deletions modules/ui/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { d3keybinding } from '../lib/d3.keybinding.js';
import { t, textDirection } from '../util/locale';
import { geoMetersToOffset, geoOffsetToMeters } from '../geo/index';
import { utilDetect } from '../util/detect';
import { utilSetTransform } from '../util/index';
import { utilSetTransform, utilCallWhenIdle } from '../util/index';
import { svgIcon } from '../svg/index';
import { uiMapInMap } from './map_in_map';
import { uiCmd } from './cmd';
Expand Down Expand Up @@ -540,7 +540,7 @@ export function uiBackground(context) {
);

context.map()
.on('move.background-update', _.debounce(update, 1000));
.on('move.background-update', _.debounce(utilCallWhenIdle(update), 1000));

context.background()
.on('change.background-update', update);
Expand Down
6 changes: 2 additions & 4 deletions modules/util/call_when_idle.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
// note the function should be of low priority
// and should not be returning a value.
export function utilCallWhenIdle(func, timeout, name) {
export function utilCallWhenIdle(func, timeout) {
return function() {
var args = arguments;
var that = this;
console.log('called ', name);
window.requestIdleCallback(function() {
console.log('idle succeed ', name);
func.apply(that, args);
}, {timeout: timeout});
};
}
}
2 changes: 1 addition & 1 deletion modules/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ export { utilTagText } from './util';
export { utilTriggerEvent } from './trigger_event';
export { utilWrap } from './util';
export { utilIdleWorker} from './idle_worker';
export { utilCallWhenIdle } from './call_when_idle';
export { utilCallWhenIdle } from './call_when_idle';

0 comments on commit 909b72a

Please sign in to comment.