[TASK] Avoid render blocking onload
This commit is contained in:
parent
7cbc4e75d7
commit
8c4978172b
@ -10,8 +10,8 @@ define(['leaflet', 'rbush', 'helper'],
|
|||||||
['right', 'top', 5 / 8],
|
['right', 'top', 5 / 8],
|
||||||
['center', 'ideographic', 2 / 8],
|
['center', 'ideographic', 2 / 8],
|
||||||
['right', 'ideographic', 3 / 8]];
|
['right', 'ideographic', 3 / 8]];
|
||||||
var bodyStyle = window.getComputedStyle(document.querySelector('body'));
|
|
||||||
var labelShadow;
|
var labelShadow;
|
||||||
|
var bodyStyle = { fontFamily: 'sans-serif' };
|
||||||
var nodeRadius = 4;
|
var nodeRadius = 4;
|
||||||
|
|
||||||
var cFont = document.createElement('canvas').getContext('2d');
|
var cFont = document.createElement('canvas').getContext('2d');
|
||||||
@ -101,11 +101,10 @@ define(['leaflet', 'rbush', 'helper'],
|
|||||||
// - label (string)
|
// - label (string)
|
||||||
// - color (string)
|
// - color (string)
|
||||||
|
|
||||||
var labelsOnline = d.online.map(prepareLabel(bodyStyle.color, 11, 8, true));
|
var labelsOnline = d.online.map(prepareLabel(null, 11, 8, true));
|
||||||
var labelsOffline = d.offline.map(prepareLabel('rgba(212, 62, 42, 0.9)', 9, 5, false));
|
var labelsOffline = d.offline.map(prepareLabel('rgba(212, 62, 42, 0.9)', 9, 5, false));
|
||||||
var labelsNew = d.new.map(prepareLabel('rgba(48, 99, 20, 0.9)', 11, 8, true));
|
var labelsNew = d.new.map(prepareLabel('rgba(48, 99, 20, 0.9)', 11, 8, true));
|
||||||
var labelsLost = d.lost.map(prepareLabel('rgba(212, 62, 42, 0.9)', 11, 8, true));
|
var labelsLost = d.lost.map(prepareLabel('rgba(212, 62, 42, 0.9)', 11, 8, true));
|
||||||
labelShadow = bodyStyle.backgroundColor.replace(/rgb/i, 'rgba').replace(/\)/i, ',0.7)');
|
|
||||||
|
|
||||||
var labels = []
|
var labels = []
|
||||||
.concat(labelsNew)
|
.concat(labelsNew)
|
||||||
@ -193,6 +192,8 @@ define(['leaflet', 'rbush', 'helper'],
|
|||||||
var tileSize = this.options.tileSize;
|
var tileSize = this.options.tileSize;
|
||||||
var s = tilePoint.multiplyBy(tileSize);
|
var s = tilePoint.multiplyBy(tileSize);
|
||||||
var map = this._map;
|
var map = this._map;
|
||||||
|
bodyStyle = window.getComputedStyle(document.querySelector('body'));
|
||||||
|
labelShadow = bodyStyle.backgroundColor.replace(/rgb/i, 'rgba').replace(/\)/i, ',0.7)');
|
||||||
|
|
||||||
function projectNodes(d) {
|
function projectNodes(d) {
|
||||||
var p = map.project(d.label.position);
|
var p = map.project(d.label.position);
|
||||||
@ -215,7 +216,7 @@ define(['leaflet', 'rbush', 'helper'],
|
|||||||
ctx.font = d.label.font;
|
ctx.font = d.label.font;
|
||||||
ctx.textAlign = d.label.anchor[0];
|
ctx.textAlign = d.label.anchor[0];
|
||||||
ctx.textBaseline = d.label.anchor[1];
|
ctx.textBaseline = d.label.anchor[1];
|
||||||
ctx.fillStyle = d.label.fillStyle;
|
ctx.fillStyle = d.label.fillStyle === null ? bodyStyle.color : d.label.fillStyle;
|
||||||
|
|
||||||
if (d.label.stroke) {
|
if (d.label.stroke) {
|
||||||
ctx.strokeText(d.label.label, d.p.x + d.label.offset[0], d.p.y + d.label.offset[1]);
|
ctx.strokeText(d.label.label, d.p.x + d.label.offset[0], d.p.y + d.label.offset[1]);
|
||||||
|
@ -4,6 +4,12 @@ define(function () {
|
|||||||
return function (el) {
|
return function (el) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
// Needed to avoid render blocking
|
||||||
|
var gridBreakpoints = {
|
||||||
|
lg: [992, 446],
|
||||||
|
xl: [1200, 560]
|
||||||
|
};
|
||||||
|
|
||||||
var sidebar = document.createElement('div');
|
var sidebar = document.createElement('div');
|
||||||
sidebar.classList.add('sidebar');
|
sidebar.classList.add('sidebar');
|
||||||
el.appendChild(sidebar);
|
el.appendChild(sidebar);
|
||||||
@ -21,10 +27,12 @@ define(function () {
|
|||||||
sidebar.appendChild(container);
|
sidebar.appendChild(container);
|
||||||
|
|
||||||
self.getWidth = function getWidth() {
|
self.getWidth = function getWidth() {
|
||||||
if (sidebar.classList.contains('hidden') || button.offsetHeight === 0) {
|
if (gridBreakpoints.lg[0] < window.innerWidth) {
|
||||||
return 0;
|
return 0;
|
||||||
|
} else if (gridBreakpoints.xl[0] < window.innerWidth) {
|
||||||
|
return gridBreakpoints.lg[1];
|
||||||
}
|
}
|
||||||
return sidebar.offsetWidth;
|
return gridBreakpoints.xl[1];
|
||||||
};
|
};
|
||||||
|
|
||||||
self.add = function add(d) {
|
self.add = function add(d) {
|
||||||
|
@ -21,6 +21,7 @@ $button-font-size: 1.6rem !default;
|
|||||||
$button-distance: 16px !default;
|
$button-distance: 16px !default;
|
||||||
|
|
||||||
// Bootstrap breakpoints
|
// Bootstrap breakpoints
|
||||||
|
// In lib/sidebar to avoid render blocking onload
|
||||||
$grid-breakpoints: (
|
$grid-breakpoints: (
|
||||||
// Extra small screen / phone
|
// Extra small screen / phone
|
||||||
xs: 0,
|
xs: 0,
|
||||||
@ -35,6 +36,7 @@ $grid-breakpoints: (
|
|||||||
) !default;
|
) !default;
|
||||||
|
|
||||||
// 45% sidebar - based on viewport
|
// 45% sidebar - based on viewport
|
||||||
|
// In lib/sidebar to avoid render blocking onload
|
||||||
$sidebar-width: map-get($grid-breakpoints, xl) * .45 !default;
|
$sidebar-width: map-get($grid-breakpoints, xl) * .45 !default;
|
||||||
$sidebar-width-small: map-get($grid-breakpoints, lg) * .45 !default;
|
$sidebar-width-small: map-get($grid-breakpoints, lg) * .45 !default;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user