From c964fe2a54ed040250934491e7d9ba012e300e54 Mon Sep 17 00:00:00 2001 From: Alex de Mulder Date: Thu, 26 Nov 2015 17:26:28 +0100 Subject: [PATCH] - Fixed #1461: Reset order of SVG elements in legend icons. --- HISTORY.md | 1 + dist/vis.js | 18 ++++++++++++++---- lib/DOMutil.js | 10 ++++++++++ lib/timeline/component/Legend.js | 6 +++--- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 03ece476..46a6142f 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -35,6 +35,7 @@ http://visjs.org ### Graph2d - Fixed #1385: Draw lines on top of bars. +- Fixed #1461: Reset order of SVG elements in legend icons. ### DataSet/DataView diff --git a/dist/vis.js b/dist/vis.js index 0945606e..63d427d1 100644 --- a/dist/vis.js +++ b/dist/vis.js @@ -5,7 +5,7 @@ * A dynamic, browser-based visualization library. * * @version 4.9.1-SNAPSHOT - * @date 2015-11-20 + * @date 2015-11-26 * * @license * Copyright (C) 2011-2015 Almende B.V, http://almende.com @@ -5045,6 +5045,16 @@ return /******/ (function(modules) { // webpackBootstrap } }; + /** + * Ensures that all elements are removed first up so they can be recreated cleanly + * @param JSONcontainer + */ + exports.resetElements = function (JSONcontainer) { + exports.prepareElements(JSONcontainer); + exports.cleanupElements(JSONcontainer); + exports.prepareElements(JSONcontainer); + }; + /** * Allocate or generate an SVG element if needed. Store a reference to it in the JSON container and draw it in the svgContainer * the JSON container and the SVG container have to be supplied so other svg containers (like the legend) can use this. @@ -26684,7 +26694,9 @@ return /******/ (function(modules) { // webpackBootstrap return a < b ? -1 : 1; }); - DOMutil.prepareElements(this.svgElements); + // this resets the elements so the order is maintained + DOMutil.resetElements(this.svgElements); + var padding = window.getComputedStyle(this.dom.frame).paddingTop; var iconOffset = Number(padding.replace('px', '')); var x = iconOffset; @@ -26701,8 +26713,6 @@ return /******/ (function(modules) { // webpackBootstrap y += iconHeight + this.options.iconSpacing; } } - - DOMutil.cleanupElements(this.svgElements); } }; diff --git a/lib/DOMutil.js b/lib/DOMutil.js index 722df764..1e778bc0 100644 --- a/lib/DOMutil.js +++ b/lib/DOMutil.js @@ -36,6 +36,16 @@ exports.cleanupElements = function(JSONcontainer) { } }; +/** + * Ensures that all elements are removed first up so they can be recreated cleanly + * @param JSONcontainer + */ +exports.resetElements = function(JSONcontainer) { + exports.prepareElements(JSONcontainer); + exports.cleanupElements(JSONcontainer); + exports.prepareElements(JSONcontainer); +} + /** * Allocate or generate an SVG element if needed. Store a reference to it in the JSON container and draw it in the svgContainer * the JSON container and the SVG container have to be supplied so other svg containers (like the legend) can use this. diff --git a/lib/timeline/component/Legend.js b/lib/timeline/component/Legend.js index cedfe9fd..5748544f 100644 --- a/lib/timeline/component/Legend.js +++ b/lib/timeline/component/Legend.js @@ -189,7 +189,9 @@ Legend.prototype.drawLegendIcons = function() { return (a < b ? -1 : 1); }) - DOMutil.prepareElements(this.svgElements); + // this resets the elements so the order is maintained + DOMutil.resetElements(this.svgElements); + var padding = window.getComputedStyle(this.dom.frame).paddingTop; var iconOffset = Number(padding.replace('px','')); var x = iconOffset; @@ -206,8 +208,6 @@ Legend.prototype.drawLegendIcons = function() { y += iconHeight + this.options.iconSpacing; } } - - DOMutil.cleanupElements(this.svgElements); } };