From 70a3805f42b02466dc3f34c77704405ef7714b9d Mon Sep 17 00:00:00 2001 From: Youri van den Bogert Date: Thu, 27 Nov 2025 15:05:27 +0100 Subject: [PATCH 1/2] Fixing tagcloud issues due d3 v6 incompatabilities. --- .../resources/ext.srf.formats.tagcloud.js | 2 +- resources/jquery/d3/d3.layout.cloud.js | 53 +++++++++++++++---- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/formats/tagcloud/resources/ext.srf.formats.tagcloud.js b/formats/tagcloud/resources/ext.srf.formats.tagcloud.js index f9d93f681..62ef7b03e 100644 --- a/formats/tagcloud/resources/ext.srf.formats.tagcloud.js +++ b/formats/tagcloud/resources/ext.srf.formats.tagcloud.js @@ -146,7 +146,7 @@ } ); // Init the colour array - var fill = d3.scale.category20b(); + var fill = d3.scaleOrdinal(d3.schemeTableau10); // Set properties for the tags function draw( words ) { diff --git a/resources/jquery/d3/d3.layout.cloud.js b/resources/jquery/d3/d3.layout.cloud.js index 511bdb771..d8d75b891 100644 --- a/resources/jquery/d3/d3.layout.cloud.js +++ b/resources/jquery/d3/d3.layout.cloud.js @@ -1,7 +1,24 @@ // Word cloud layout by Jason Davies, http://www.jasondavies.com/word-cloud/ // Algorithm due to Jonathan Feinberg, http://static.mrfeinberg.com/bv_ch03.pdf // @author: mwjames, 2012-08, added href as construtor field +// @auhtor: your1, 2026-11-27, fixed support for D3 v6 (function(exports) { + + // Simple replacement for d3.functor (removed in D3 v4+) + function functor(v) { + return typeof v === "function" ? v : function() { return v; }; + } + + // Replacement for d3.rebind(cloud, event, "on") + function rebindOn(target, source) { + target.on = function() { + var value = source.on.apply(source, arguments); + // Keep chainability like the old d3.rebind + return value === source ? target : value; + }; + return target; + } + function cloud() { var size = [256, 256], text = cloudText, @@ -13,6 +30,7 @@ spiral = archimedeanSpiral, words = [], timeInterval = Infinity, + // D3 v6 still uses d3.dispatch, but dispatching is done via .call() event = d3.dispatch("word", "end"), timer = null, cloud = {}; @@ -30,7 +48,8 @@ font: font.call(this, d, i), rotate: rotate.call(this, d, i), size: ~~fontSize.call(this, d, i), - padding: cloudPadding.call(this, d, i) + // NOTE: use variable 'padding' here so cloud.padding(...) works + padding: padding.call(this, d, i) }; }).sort(function(a, b) { return b.size - a.size; }); @@ -50,7 +69,11 @@ cloudSprite(d, data, i); if (place(board, d, bounds)) { tags.push(d); - event.word(d); + + // OLD: event.word(d); + // NEW (D3 v6): use dispatch.call(type, thisArg, ...) + event.call("word", cloud, d); + if (bounds) cloudBounds(bounds, d); else bounds = [{x: d.x + d.x0, y: d.y + d.y0}, {x: d.x + d.x1, y: d.y + d.y1}]; // Temporary hack @@ -60,7 +83,10 @@ } if (i >= n) { cloud.stop(); - event.end(tags, bounds); + + // OLD: event.end(tags, bounds); + // NEW: dispatch.call("end", thisArg, ...) + event.call("end", cloud, tags, bounds); } } } @@ -143,25 +169,25 @@ cloud.font = function(x) { if (!arguments.length) return font; - font = d3.functor(x); + font = functor(x); return cloud; }; cloud.rotate = function(x) { if (!arguments.length) return rotate; - rotate = d3.functor(x); + rotate = functor(x); return cloud; }; cloud.text = function(x) { if (!arguments.length) return text; - text = d3.functor(x); + text = functor(x); return cloud; }; cloud.href = function(x) { if (!arguments.length) return href; - text = d3.functor(x); + href = functor(x); // FIX: previously set 'text' by mistake return cloud; }; @@ -173,17 +199,19 @@ cloud.fontSize = function(x) { if (!arguments.length) return fontSize; - fontSize = d3.functor(x); + fontSize = functor(x); return cloud; }; cloud.padding = function(x) { if (!arguments.length) return padding; - padding = d3.functor(x); + padding = functor(x); return cloud; }; - return d3.rebind(cloud, event, "on"); + // OLD: return d3.rebind(cloud, event, "on"); + // NEW: manually rebind .on + return rebindOn(cloud, event); } function cloudText(d) { @@ -395,4 +423,7 @@ c.textAlign = "center"; exports.cloud = cloud; -})(typeof exports === "undefined" ? d3.layout || (d3.layout = {}) : exports); + +// D3 v6 still exposes a global `d3` if you use the UMD bundle. +// This keeps the original API: d3.layout.cloud(...) +})(typeof exports === "undefined" ? d3.layout || (d3.layout = {}) : exports); \ No newline at end of file From affee22242604ecf74df4f19565cccf2b9136486 Mon Sep 17 00:00:00 2001 From: Youri van den Bogert Date: Fri, 28 Nov 2025 08:10:09 +0100 Subject: [PATCH 2/2] Remoevd unnecessary comments that we're used while debugging. --- resources/jquery/d3/d3.layout.cloud.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/resources/jquery/d3/d3.layout.cloud.js b/resources/jquery/d3/d3.layout.cloud.js index d8d75b891..1a4677101 100644 --- a/resources/jquery/d3/d3.layout.cloud.js +++ b/resources/jquery/d3/d3.layout.cloud.js @@ -13,7 +13,6 @@ function rebindOn(target, source) { target.on = function() { var value = source.on.apply(source, arguments); - // Keep chainability like the old d3.rebind return value === source ? target : value; }; return target; @@ -70,8 +69,6 @@ if (place(board, d, bounds)) { tags.push(d); - // OLD: event.word(d); - // NEW (D3 v6): use dispatch.call(type, thisArg, ...) event.call("word", cloud, d); if (bounds) cloudBounds(bounds, d); @@ -84,8 +81,6 @@ if (i >= n) { cloud.stop(); - // OLD: event.end(tags, bounds); - // NEW: dispatch.call("end", thisArg, ...) event.call("end", cloud, tags, bounds); } } @@ -209,8 +204,6 @@ return cloud; }; - // OLD: return d3.rebind(cloud, event, "on"); - // NEW: manually rebind .on return rebindOn(cloud, event); }