Skip to content

Commit

Permalink
Fix legend wrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheng5 committed Mar 21, 2017
1 parent f8c7dea commit 47eac69
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 19 deletions.
10 changes: 5 additions & 5 deletions legends.html
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ <h2>Legends</h2>
{
"method": "addTiles",
"args": [
"//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
null,
null,
{
Expand All @@ -258,7 +258,7 @@ <h2>Legends</h2>
"updateWhenIdle": null,
"detectRetina": false,
"reuseTiles": false,
"attribution": "&copy; <a href=\"http://openstreetmap.org\">OpenStreetMap\u003c/a> contributors, <a href=\"http://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA\u003c/a>"
"attribution": "&copy; <a href=\"http://openstreetmap.org\">OpenStreetMap<\/a> contributors, <a href=\"http://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA<\/a>"
}
]
},
Expand Down Expand Up @@ -2420,7 +2420,7 @@ <h2>Legends</h2>
{
"method": "addTiles",
"args": [
"//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
null,
null,
{
Expand All @@ -2441,7 +2441,7 @@ <h2>Legends</h2>
"updateWhenIdle": null,
"detectRetina": false,
"reuseTiles": false,
"attribution": "&copy; <a href=\"http://openstreetmap.org\">OpenStreetMap\u003c/a> contributors, <a href=\"http://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA\u003c/a>"
"attribution": "&copy; <a href=\"http://openstreetmap.org\">OpenStreetMap<\/a> contributors, <a href=\"http://creativecommons.org/licenses/by-sa/2.0/\">CC-BY-SA<\/a>"
}
]
},
Expand Down Expand Up @@ -4555,7 +4555,7 @@ <h2>Legends</h2>
"args": [
{
"colors": ["#D7191C", "#FDAE61", "#FFFFBF", "#ABD9E9", "#2C7BB6"],
"labels": ["<span title=\"-99 &ndash; 10,614\">0% &ndash; 20%\u003c/span>", "<span title=\"10,614 &ndash; 27,622\">20% &ndash; 40%\u003c/span>", "<span title=\"27,622 &ndash; 81,162\">40% &ndash; 60%\u003c/span>", "<span title=\"81,162 &ndash; 327,100\">60% &ndash; 80%\u003c/span>", "<span title=\"327,100 &ndash; 15,094,000\">80% &ndash; 100%\u003c/span>"],
"labels": ["<span title=\"-99 &ndash; 10,614\">0% &ndash; 20%<\/span>", "<span title=\"10,614 &ndash; 27,622\">20% &ndash; 40%<\/span>", "<span title=\"27,622 &ndash; 81,162\">40% &ndash; 60%<\/span>", "<span title=\"81,162 &ndash; 327,100\">60% &ndash; 80%<\/span>", "<span title=\"327,100 &ndash; 15,094,000\">80% &ndash; 100%<\/span>"],
"na_color": null,
"na_label": "NA",
"opacity": 1,
Expand Down
2 changes: 1 addition & 1 deletion libs/htmlwidgets/htmlwidgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,6 @@
// supported natively by Shiny at the time of this writing.

shinyBinding.renderValue = function(el, data) {
Shiny.renderDependencies(data.deps);
// Resolve strings marked as javascript literals to objects
if (!(data.evals instanceof Array)) data.evals = [data.evals];
for (var i = 0; data.evals && i < data.evals.length; i++) {
Expand All @@ -513,6 +512,7 @@
elementData(el, "init_result", result);
}
}
Shiny.renderDependencies(data.deps);
bindingDef.renderValue(el, data.x, elementData(el, "init_result"));
evalAndRun(data.jsHooks.render, elementData(el, "init_result"), [el, data.x]);
};
Expand Down
78 changes: 65 additions & 13 deletions libs/leaflet-binding/leaflet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,15 @@ var LayerManager = function () {
});
return result;
}
}, {
key: "getAllGroupNames",
value: function getAllGroupNames() {
var result = [];
_jquery2.default.each(this._groupContainers, function (k, v) {
result.push(k);
});
return result;
}
}, {
key: "clearGroup",
value: function clearGroup(group) {
Expand Down Expand Up @@ -1839,7 +1848,7 @@ methods.addLegend = function (options) {
labels.push(options.na_label);
}
for (var i = 0; i < colors.length; i++) {
legendHTML += "<i style=\"background:" + colors[i] + ";opacity:" + options.opacity + "\"></i> " + labels[i] + "<br/>";
legendHTML += "<i style=\"background:" + colors[i] + ";opacity:" + options.opacity + "\"></i> " + labels[i] + "<br clear='both'/>";
}
div.innerHTML = legendHTML;
}
Expand Down Expand Up @@ -1930,6 +1939,49 @@ methods.showGroup = function (group) {
});
};

function setupShowHideGroupsOnZoom(map) {
if (map.leafletr._hasInitializedShowHideGroups) {
return;
}
map.leafletr._hasInitializedShowHideGroups = true;

function setVisibility(layer, visible) {
if (visible !== map.hasLayer(layer)) {
if (visible) map.addLayer(layer);else map.removeLayer(layer);
}
}

function showHideGroupsOnZoom() {
if (!map.layerManager) return;

var zoom = map.getZoom();
map.layerManager.getAllGroupNames().forEach(function (group) {
var layer = map.layerManager.getLayerGroup(group, false);
if (layer && typeof layer.zoomLevels !== "undefined") {
setVisibility(layer, layer.zoomLevels === true || layer.zoomLevels.indexOf(zoom) >= 0);
}
});
}

map.showHideGroupsOnZoom = showHideGroupsOnZoom;
map.on("zoomend", showHideGroupsOnZoom);
}

methods.setGroupOptions = function (group, options) {
var _this8 = this;

_jquery2.default.each((0, _util.asArray)(group), function (i, g) {
var layer = _this8.layerManager.getLayerGroup(g, true);
// This slightly tortured check is because 0 is a valid value for zoomLevels
if (typeof options.zoomLevels !== "undefined" && options.zoomLevels !== null) {
layer.zoomLevels = (0, _util.asArray)(options.zoomLevels);
}
});

setupShowHideGroupsOnZoom(this);
this.showHideGroupsOnZoom();
};

methods.addRasterImage = function (uri, bounds, opacity, attribution, layerId, group) {
// uri is a data URI containing an image. We want to paint this image as a
// layer at (top-left) bounds[0] to (bottom-right) bounds[1].
Expand Down Expand Up @@ -2213,7 +2265,7 @@ methods.removeMeasure = function () {
};

methods.addSelect = function (ctGroup) {
var _this8 = this;
var _this9 = this;

methods.removeSelect.call(this);

Expand All @@ -2224,42 +2276,42 @@ methods.addSelect = function (ctGroup) {
title: "Make a selection",
onClick: function onClick(btn, map) {
btn.state("select-active");
_this8._locationFilter = new _leaflet2.default.LocationFilter2();
_this9._locationFilter = new _leaflet2.default.LocationFilter2();

if (ctGroup) {
(function () {
var selectionHandle = new global.crosstalk.SelectionHandle(ctGroup);
selectionHandle.on("change", function (e) {
if (e.sender !== selectionHandle) {
if (_this8._locationFilter) {
_this8._locationFilter.disable();
if (_this9._locationFilter) {
_this9._locationFilter.disable();
btn.state("select-inactive");
}
}
});
var handler = function handler(e) {
_this8.layerManager.brush(_this8._locationFilter.getBounds(), { sender: selectionHandle });
_this9.layerManager.brush(_this9._locationFilter.getBounds(), { sender: selectionHandle });
};
_this8._locationFilter.on("enabled", handler);
_this8._locationFilter.on("change", handler);
_this8._locationFilter.on("disabled", function () {
_this9._locationFilter.on("enabled", handler);
_this9._locationFilter.on("change", handler);
_this9._locationFilter.on("disabled", function () {
selectionHandle.close();
_this8._locationFilter = null;
_this9._locationFilter = null;
});
})();
}

_this8._locationFilter.addTo(map);
_this9._locationFilter.addTo(map);
}
}, {
stateName: "select-active",
icon: "ion-close-round",
title: "Dismiss selection",
onClick: function onClick(btn, map) {
btn.state("select-inactive");
_this8._locationFilter.disable();
_this9._locationFilter.disable();
// If explicitly dismissed, clear the crosstalk selections
_this8.layerManager.unbrush();
_this9.layerManager.unbrush();
}
}]
});
Expand Down
50 changes: 50 additions & 0 deletions libs/navigation/tabsets.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,52 @@


/**
* jQuery Plugin: Sticky Tabs
*
* @author Aidan Lister <aidan@php.net>
* adapted by Ruben Arslan to activate parent tabs too
* http://www.aidanlister.com/2014/03/persisting-the-tab-state-in-bootstrap/
*/
(function($) {
"use strict";
$.fn.rmarkdownStickyTabs = function() {
var context = this;
// Show the tab corresponding with the hash in the URL, or the first tab
var showStuffFromHash = function() {
var hash = window.location.hash;
var selector = hash ? 'a[href="' + hash + '"]' : 'li.active > a';
var $selector = $(selector, context);
if($selector.data('toggle') === "tab") {
$selector.tab('show');
// walk up the ancestors of this element, show any hidden tabs
$selector.parents('.section.tabset').each(function(i, elm) {
var link = $('a[href="#' + $(elm).attr('id') + '"]');
if(link.data('toggle') === "tab") {
link.tab("show");
}
});
}
};


// Set the correct tab when the page loads
showStuffFromHash(context);

// Set the correct tab when a user uses their back/forward button
$(window).on('hashchange', function() {
showStuffFromHash(context);
});

// Change the URL when tabs are clicked
$('a', context).on('click', function(e) {
history.pushState(null, null, this.href);
showStuffFromHash(context);
});

return this;
};
}(jQuery));

window.buildTabsets = function(tocID) {

// build a tabset from a section div with the .tabset class
Expand Down Expand Up @@ -80,6 +127,9 @@ window.buildTabsets = function(tocID) {
active.addClass('active');
if (fade)
active.addClass('in');

if (tabset.hasClass("tabset-sticky"))
tabset.rmarkdownStickyTabs();
}

// convert section divs with the .tabset class to tabsets
Expand Down

0 comments on commit 47eac69

Please sign in to comment.