| 1 | // https://d3js.org/d3-transition/ v3.0.1 Copyright 2010-2021 Mike Bostock
|
|---|
| 2 | (function (global, factory) {
|
|---|
| 3 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('d3-selection'), require('d3-dispatch'), require('d3-timer'), require('d3-interpolate'), require('d3-color'), require('d3-ease')) :
|
|---|
| 4 | typeof define === 'function' && define.amd ? define(['exports', 'd3-selection', 'd3-dispatch', 'd3-timer', 'd3-interpolate', 'd3-color', 'd3-ease'], factory) :
|
|---|
| 5 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.d3 = global.d3 || {}, global.d3, global.d3, global.d3, global.d3, global.d3, global.d3));
|
|---|
| 6 | }(this, (function (exports, d3Selection, d3Dispatch, d3Timer, d3Interpolate, d3Color, d3Ease) { 'use strict';
|
|---|
| 7 |
|
|---|
| 8 | var emptyOn = d3Dispatch.dispatch("start", "end", "cancel", "interrupt");
|
|---|
| 9 | var emptyTween = [];
|
|---|
| 10 |
|
|---|
| 11 | var CREATED = 0;
|
|---|
| 12 | var SCHEDULED = 1;
|
|---|
| 13 | var STARTING = 2;
|
|---|
| 14 | var STARTED = 3;
|
|---|
| 15 | var RUNNING = 4;
|
|---|
| 16 | var ENDING = 5;
|
|---|
| 17 | var ENDED = 6;
|
|---|
| 18 |
|
|---|
| 19 | function schedule(node, name, id, index, group, timing) {
|
|---|
| 20 | var schedules = node.__transition;
|
|---|
| 21 | if (!schedules) node.__transition = {};
|
|---|
| 22 | else if (id in schedules) return;
|
|---|
| 23 | create(node, id, {
|
|---|
| 24 | name: name,
|
|---|
| 25 | index: index, // For context during callback.
|
|---|
| 26 | group: group, // For context during callback.
|
|---|
| 27 | on: emptyOn,
|
|---|
| 28 | tween: emptyTween,
|
|---|
| 29 | time: timing.time,
|
|---|
| 30 | delay: timing.delay,
|
|---|
| 31 | duration: timing.duration,
|
|---|
| 32 | ease: timing.ease,
|
|---|
| 33 | timer: null,
|
|---|
| 34 | state: CREATED
|
|---|
| 35 | });
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | function init(node, id) {
|
|---|
| 39 | var schedule = get(node, id);
|
|---|
| 40 | if (schedule.state > CREATED) throw new Error("too late; already scheduled");
|
|---|
| 41 | return schedule;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | function set(node, id) {
|
|---|
| 45 | var schedule = get(node, id);
|
|---|
| 46 | if (schedule.state > STARTED) throw new Error("too late; already running");
|
|---|
| 47 | return schedule;
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | function get(node, id) {
|
|---|
| 51 | var schedule = node.__transition;
|
|---|
| 52 | if (!schedule || !(schedule = schedule[id])) throw new Error("transition not found");
|
|---|
| 53 | return schedule;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | function create(node, id, self) {
|
|---|
| 57 | var schedules = node.__transition,
|
|---|
| 58 | tween;
|
|---|
| 59 |
|
|---|
| 60 | // Initialize the self timer when the transition is created.
|
|---|
| 61 | // Note the actual delay is not known until the first callback!
|
|---|
| 62 | schedules[id] = self;
|
|---|
| 63 | self.timer = d3Timer.timer(schedule, 0, self.time);
|
|---|
| 64 |
|
|---|
| 65 | function schedule(elapsed) {
|
|---|
| 66 | self.state = SCHEDULED;
|
|---|
| 67 | self.timer.restart(start, self.delay, self.time);
|
|---|
| 68 |
|
|---|
| 69 | // If the elapsed delay is less than our first sleep, start immediately.
|
|---|
| 70 | if (self.delay <= elapsed) start(elapsed - self.delay);
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | function start(elapsed) {
|
|---|
| 74 | var i, j, n, o;
|
|---|
| 75 |
|
|---|
| 76 | // If the state is not SCHEDULED, then we previously errored on start.
|
|---|
| 77 | if (self.state !== SCHEDULED) return stop();
|
|---|
| 78 |
|
|---|
| 79 | for (i in schedules) {
|
|---|
| 80 | o = schedules[i];
|
|---|
| 81 | if (o.name !== self.name) continue;
|
|---|
| 82 |
|
|---|
| 83 | // While this element already has a starting transition during this frame,
|
|---|
| 84 | // defer starting an interrupting transition until that transition has a
|
|---|
| 85 | // chance to tick (and possibly end); see d3/d3-transition#54!
|
|---|
| 86 | if (o.state === STARTED) return d3Timer.timeout(start);
|
|---|
| 87 |
|
|---|
| 88 | // Interrupt the active transition, if any.
|
|---|
| 89 | if (o.state === RUNNING) {
|
|---|
| 90 | o.state = ENDED;
|
|---|
| 91 | o.timer.stop();
|
|---|
| 92 | o.on.call("interrupt", node, node.__data__, o.index, o.group);
|
|---|
| 93 | delete schedules[i];
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | // Cancel any pre-empted transitions.
|
|---|
| 97 | else if (+i < id) {
|
|---|
| 98 | o.state = ENDED;
|
|---|
| 99 | o.timer.stop();
|
|---|
| 100 | o.on.call("cancel", node, node.__data__, o.index, o.group);
|
|---|
| 101 | delete schedules[i];
|
|---|
| 102 | }
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | // Defer the first tick to end of the current frame; see d3/d3#1576.
|
|---|
| 106 | // Note the transition may be canceled after start and before the first tick!
|
|---|
| 107 | // Note this must be scheduled before the start event; see d3/d3-transition#16!
|
|---|
| 108 | // Assuming this is successful, subsequent callbacks go straight to tick.
|
|---|
| 109 | d3Timer.timeout(function() {
|
|---|
| 110 | if (self.state === STARTED) {
|
|---|
| 111 | self.state = RUNNING;
|
|---|
| 112 | self.timer.restart(tick, self.delay, self.time);
|
|---|
| 113 | tick(elapsed);
|
|---|
| 114 | }
|
|---|
| 115 | });
|
|---|
| 116 |
|
|---|
| 117 | // Dispatch the start event.
|
|---|
| 118 | // Note this must be done before the tween are initialized.
|
|---|
| 119 | self.state = STARTING;
|
|---|
| 120 | self.on.call("start", node, node.__data__, self.index, self.group);
|
|---|
| 121 | if (self.state !== STARTING) return; // interrupted
|
|---|
| 122 | self.state = STARTED;
|
|---|
| 123 |
|
|---|
| 124 | // Initialize the tween, deleting null tween.
|
|---|
| 125 | tween = new Array(n = self.tween.length);
|
|---|
| 126 | for (i = 0, j = -1; i < n; ++i) {
|
|---|
| 127 | if (o = self.tween[i].value.call(node, node.__data__, self.index, self.group)) {
|
|---|
| 128 | tween[++j] = o;
|
|---|
| 129 | }
|
|---|
| 130 | }
|
|---|
| 131 | tween.length = j + 1;
|
|---|
| 132 | }
|
|---|
| 133 |
|
|---|
| 134 | function tick(elapsed) {
|
|---|
| 135 | var t = elapsed < self.duration ? self.ease.call(null, elapsed / self.duration) : (self.timer.restart(stop), self.state = ENDING, 1),
|
|---|
| 136 | i = -1,
|
|---|
| 137 | n = tween.length;
|
|---|
| 138 |
|
|---|
| 139 | while (++i < n) {
|
|---|
| 140 | tween[i].call(node, t);
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | // Dispatch the end event.
|
|---|
| 144 | if (self.state === ENDING) {
|
|---|
| 145 | self.on.call("end", node, node.__data__, self.index, self.group);
|
|---|
| 146 | stop();
|
|---|
| 147 | }
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | function stop() {
|
|---|
| 151 | self.state = ENDED;
|
|---|
| 152 | self.timer.stop();
|
|---|
| 153 | delete schedules[id];
|
|---|
| 154 | for (var i in schedules) return; // eslint-disable-line no-unused-vars
|
|---|
| 155 | delete node.__transition;
|
|---|
| 156 | }
|
|---|
| 157 | }
|
|---|
| 158 |
|
|---|
| 159 | function interrupt(node, name) {
|
|---|
| 160 | var schedules = node.__transition,
|
|---|
| 161 | schedule,
|
|---|
| 162 | active,
|
|---|
| 163 | empty = true,
|
|---|
| 164 | i;
|
|---|
| 165 |
|
|---|
| 166 | if (!schedules) return;
|
|---|
| 167 |
|
|---|
| 168 | name = name == null ? null : name + "";
|
|---|
| 169 |
|
|---|
| 170 | for (i in schedules) {
|
|---|
| 171 | if ((schedule = schedules[i]).name !== name) { empty = false; continue; }
|
|---|
| 172 | active = schedule.state > STARTING && schedule.state < ENDING;
|
|---|
| 173 | schedule.state = ENDED;
|
|---|
| 174 | schedule.timer.stop();
|
|---|
| 175 | schedule.on.call(active ? "interrupt" : "cancel", node, node.__data__, schedule.index, schedule.group);
|
|---|
| 176 | delete schedules[i];
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | if (empty) delete node.__transition;
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | function selection_interrupt(name) {
|
|---|
| 183 | return this.each(function() {
|
|---|
| 184 | interrupt(this, name);
|
|---|
| 185 | });
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | function tweenRemove(id, name) {
|
|---|
| 189 | var tween0, tween1;
|
|---|
| 190 | return function() {
|
|---|
| 191 | var schedule = set(this, id),
|
|---|
| 192 | tween = schedule.tween;
|
|---|
| 193 |
|
|---|
| 194 | // If this node shared tween with the previous node,
|
|---|
| 195 | // just assign the updated shared tween and we’re done!
|
|---|
| 196 | // Otherwise, copy-on-write.
|
|---|
| 197 | if (tween !== tween0) {
|
|---|
| 198 | tween1 = tween0 = tween;
|
|---|
| 199 | for (var i = 0, n = tween1.length; i < n; ++i) {
|
|---|
| 200 | if (tween1[i].name === name) {
|
|---|
| 201 | tween1 = tween1.slice();
|
|---|
| 202 | tween1.splice(i, 1);
|
|---|
| 203 | break;
|
|---|
| 204 | }
|
|---|
| 205 | }
|
|---|
| 206 | }
|
|---|
| 207 |
|
|---|
| 208 | schedule.tween = tween1;
|
|---|
| 209 | };
|
|---|
| 210 | }
|
|---|
| 211 |
|
|---|
| 212 | function tweenFunction(id, name, value) {
|
|---|
| 213 | var tween0, tween1;
|
|---|
| 214 | if (typeof value !== "function") throw new Error;
|
|---|
| 215 | return function() {
|
|---|
| 216 | var schedule = set(this, id),
|
|---|
| 217 | tween = schedule.tween;
|
|---|
| 218 |
|
|---|
| 219 | // If this node shared tween with the previous node,
|
|---|
| 220 | // just assign the updated shared tween and we’re done!
|
|---|
| 221 | // Otherwise, copy-on-write.
|
|---|
| 222 | if (tween !== tween0) {
|
|---|
| 223 | tween1 = (tween0 = tween).slice();
|
|---|
| 224 | for (var t = {name: name, value: value}, i = 0, n = tween1.length; i < n; ++i) {
|
|---|
| 225 | if (tween1[i].name === name) {
|
|---|
| 226 | tween1[i] = t;
|
|---|
| 227 | break;
|
|---|
| 228 | }
|
|---|
| 229 | }
|
|---|
| 230 | if (i === n) tween1.push(t);
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | schedule.tween = tween1;
|
|---|
| 234 | };
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| 237 | function transition_tween(name, value) {
|
|---|
| 238 | var id = this._id;
|
|---|
| 239 |
|
|---|
| 240 | name += "";
|
|---|
| 241 |
|
|---|
| 242 | if (arguments.length < 2) {
|
|---|
| 243 | var tween = get(this.node(), id).tween;
|
|---|
| 244 | for (var i = 0, n = tween.length, t; i < n; ++i) {
|
|---|
| 245 | if ((t = tween[i]).name === name) {
|
|---|
| 246 | return t.value;
|
|---|
| 247 | }
|
|---|
| 248 | }
|
|---|
| 249 | return null;
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | return this.each((value == null ? tweenRemove : tweenFunction)(id, name, value));
|
|---|
| 253 | }
|
|---|
| 254 |
|
|---|
| 255 | function tweenValue(transition, name, value) {
|
|---|
| 256 | var id = transition._id;
|
|---|
| 257 |
|
|---|
| 258 | transition.each(function() {
|
|---|
| 259 | var schedule = set(this, id);
|
|---|
| 260 | (schedule.value || (schedule.value = {}))[name] = value.apply(this, arguments);
|
|---|
| 261 | });
|
|---|
| 262 |
|
|---|
| 263 | return function(node) {
|
|---|
| 264 | return get(node, id).value[name];
|
|---|
| 265 | };
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | function interpolate(a, b) {
|
|---|
| 269 | var c;
|
|---|
| 270 | return (typeof b === "number" ? d3Interpolate.interpolateNumber
|
|---|
| 271 | : b instanceof d3Color.color ? d3Interpolate.interpolateRgb
|
|---|
| 272 | : (c = d3Color.color(b)) ? (b = c, d3Interpolate.interpolateRgb)
|
|---|
| 273 | : d3Interpolate.interpolateString)(a, b);
|
|---|
| 274 | }
|
|---|
| 275 |
|
|---|
| 276 | function attrRemove(name) {
|
|---|
| 277 | return function() {
|
|---|
| 278 | this.removeAttribute(name);
|
|---|
| 279 | };
|
|---|
| 280 | }
|
|---|
| 281 |
|
|---|
| 282 | function attrRemoveNS(fullname) {
|
|---|
| 283 | return function() {
|
|---|
| 284 | this.removeAttributeNS(fullname.space, fullname.local);
|
|---|
| 285 | };
|
|---|
| 286 | }
|
|---|
| 287 |
|
|---|
| 288 | function attrConstant(name, interpolate, value1) {
|
|---|
| 289 | var string00,
|
|---|
| 290 | string1 = value1 + "",
|
|---|
| 291 | interpolate0;
|
|---|
| 292 | return function() {
|
|---|
| 293 | var string0 = this.getAttribute(name);
|
|---|
| 294 | return string0 === string1 ? null
|
|---|
| 295 | : string0 === string00 ? interpolate0
|
|---|
| 296 | : interpolate0 = interpolate(string00 = string0, value1);
|
|---|
| 297 | };
|
|---|
| 298 | }
|
|---|
| 299 |
|
|---|
| 300 | function attrConstantNS(fullname, interpolate, value1) {
|
|---|
| 301 | var string00,
|
|---|
| 302 | string1 = value1 + "",
|
|---|
| 303 | interpolate0;
|
|---|
| 304 | return function() {
|
|---|
| 305 | var string0 = this.getAttributeNS(fullname.space, fullname.local);
|
|---|
| 306 | return string0 === string1 ? null
|
|---|
| 307 | : string0 === string00 ? interpolate0
|
|---|
| 308 | : interpolate0 = interpolate(string00 = string0, value1);
|
|---|
| 309 | };
|
|---|
| 310 | }
|
|---|
| 311 |
|
|---|
| 312 | function attrFunction(name, interpolate, value) {
|
|---|
| 313 | var string00,
|
|---|
| 314 | string10,
|
|---|
| 315 | interpolate0;
|
|---|
| 316 | return function() {
|
|---|
| 317 | var string0, value1 = value(this), string1;
|
|---|
| 318 | if (value1 == null) return void this.removeAttribute(name);
|
|---|
| 319 | string0 = this.getAttribute(name);
|
|---|
| 320 | string1 = value1 + "";
|
|---|
| 321 | return string0 === string1 ? null
|
|---|
| 322 | : string0 === string00 && string1 === string10 ? interpolate0
|
|---|
| 323 | : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
|
|---|
| 324 | };
|
|---|
| 325 | }
|
|---|
| 326 |
|
|---|
| 327 | function attrFunctionNS(fullname, interpolate, value) {
|
|---|
| 328 | var string00,
|
|---|
| 329 | string10,
|
|---|
| 330 | interpolate0;
|
|---|
| 331 | return function() {
|
|---|
| 332 | var string0, value1 = value(this), string1;
|
|---|
| 333 | if (value1 == null) return void this.removeAttributeNS(fullname.space, fullname.local);
|
|---|
| 334 | string0 = this.getAttributeNS(fullname.space, fullname.local);
|
|---|
| 335 | string1 = value1 + "";
|
|---|
| 336 | return string0 === string1 ? null
|
|---|
| 337 | : string0 === string00 && string1 === string10 ? interpolate0
|
|---|
| 338 | : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
|
|---|
| 339 | };
|
|---|
| 340 | }
|
|---|
| 341 |
|
|---|
| 342 | function transition_attr(name, value) {
|
|---|
| 343 | var fullname = d3Selection.namespace(name), i = fullname === "transform" ? d3Interpolate.interpolateTransformSvg : interpolate;
|
|---|
| 344 | return this.attrTween(name, typeof value === "function"
|
|---|
| 345 | ? (fullname.local ? attrFunctionNS : attrFunction)(fullname, i, tweenValue(this, "attr." + name, value))
|
|---|
| 346 | : value == null ? (fullname.local ? attrRemoveNS : attrRemove)(fullname)
|
|---|
| 347 | : (fullname.local ? attrConstantNS : attrConstant)(fullname, i, value));
|
|---|
| 348 | }
|
|---|
| 349 |
|
|---|
| 350 | function attrInterpolate(name, i) {
|
|---|
| 351 | return function(t) {
|
|---|
| 352 | this.setAttribute(name, i.call(this, t));
|
|---|
| 353 | };
|
|---|
| 354 | }
|
|---|
| 355 |
|
|---|
| 356 | function attrInterpolateNS(fullname, i) {
|
|---|
| 357 | return function(t) {
|
|---|
| 358 | this.setAttributeNS(fullname.space, fullname.local, i.call(this, t));
|
|---|
| 359 | };
|
|---|
| 360 | }
|
|---|
| 361 |
|
|---|
| 362 | function attrTweenNS(fullname, value) {
|
|---|
| 363 | var t0, i0;
|
|---|
| 364 | function tween() {
|
|---|
| 365 | var i = value.apply(this, arguments);
|
|---|
| 366 | if (i !== i0) t0 = (i0 = i) && attrInterpolateNS(fullname, i);
|
|---|
| 367 | return t0;
|
|---|
| 368 | }
|
|---|
| 369 | tween._value = value;
|
|---|
| 370 | return tween;
|
|---|
| 371 | }
|
|---|
| 372 |
|
|---|
| 373 | function attrTween(name, value) {
|
|---|
| 374 | var t0, i0;
|
|---|
| 375 | function tween() {
|
|---|
| 376 | var i = value.apply(this, arguments);
|
|---|
| 377 | if (i !== i0) t0 = (i0 = i) && attrInterpolate(name, i);
|
|---|
| 378 | return t0;
|
|---|
| 379 | }
|
|---|
| 380 | tween._value = value;
|
|---|
| 381 | return tween;
|
|---|
| 382 | }
|
|---|
| 383 |
|
|---|
| 384 | function transition_attrTween(name, value) {
|
|---|
| 385 | var key = "attr." + name;
|
|---|
| 386 | if (arguments.length < 2) return (key = this.tween(key)) && key._value;
|
|---|
| 387 | if (value == null) return this.tween(key, null);
|
|---|
| 388 | if (typeof value !== "function") throw new Error;
|
|---|
| 389 | var fullname = d3Selection.namespace(name);
|
|---|
| 390 | return this.tween(key, (fullname.local ? attrTweenNS : attrTween)(fullname, value));
|
|---|
| 391 | }
|
|---|
| 392 |
|
|---|
| 393 | function delayFunction(id, value) {
|
|---|
| 394 | return function() {
|
|---|
| 395 | init(this, id).delay = +value.apply(this, arguments);
|
|---|
| 396 | };
|
|---|
| 397 | }
|
|---|
| 398 |
|
|---|
| 399 | function delayConstant(id, value) {
|
|---|
| 400 | return value = +value, function() {
|
|---|
| 401 | init(this, id).delay = value;
|
|---|
| 402 | };
|
|---|
| 403 | }
|
|---|
| 404 |
|
|---|
| 405 | function transition_delay(value) {
|
|---|
| 406 | var id = this._id;
|
|---|
| 407 |
|
|---|
| 408 | return arguments.length
|
|---|
| 409 | ? this.each((typeof value === "function"
|
|---|
| 410 | ? delayFunction
|
|---|
| 411 | : delayConstant)(id, value))
|
|---|
| 412 | : get(this.node(), id).delay;
|
|---|
| 413 | }
|
|---|
| 414 |
|
|---|
| 415 | function durationFunction(id, value) {
|
|---|
| 416 | return function() {
|
|---|
| 417 | set(this, id).duration = +value.apply(this, arguments);
|
|---|
| 418 | };
|
|---|
| 419 | }
|
|---|
| 420 |
|
|---|
| 421 | function durationConstant(id, value) {
|
|---|
| 422 | return value = +value, function() {
|
|---|
| 423 | set(this, id).duration = value;
|
|---|
| 424 | };
|
|---|
| 425 | }
|
|---|
| 426 |
|
|---|
| 427 | function transition_duration(value) {
|
|---|
| 428 | var id = this._id;
|
|---|
| 429 |
|
|---|
| 430 | return arguments.length
|
|---|
| 431 | ? this.each((typeof value === "function"
|
|---|
| 432 | ? durationFunction
|
|---|
| 433 | : durationConstant)(id, value))
|
|---|
| 434 | : get(this.node(), id).duration;
|
|---|
| 435 | }
|
|---|
| 436 |
|
|---|
| 437 | function easeConstant(id, value) {
|
|---|
| 438 | if (typeof value !== "function") throw new Error;
|
|---|
| 439 | return function() {
|
|---|
| 440 | set(this, id).ease = value;
|
|---|
| 441 | };
|
|---|
| 442 | }
|
|---|
| 443 |
|
|---|
| 444 | function transition_ease(value) {
|
|---|
| 445 | var id = this._id;
|
|---|
| 446 |
|
|---|
| 447 | return arguments.length
|
|---|
| 448 | ? this.each(easeConstant(id, value))
|
|---|
| 449 | : get(this.node(), id).ease;
|
|---|
| 450 | }
|
|---|
| 451 |
|
|---|
| 452 | function easeVarying(id, value) {
|
|---|
| 453 | return function() {
|
|---|
| 454 | var v = value.apply(this, arguments);
|
|---|
| 455 | if (typeof v !== "function") throw new Error;
|
|---|
| 456 | set(this, id).ease = v;
|
|---|
| 457 | };
|
|---|
| 458 | }
|
|---|
| 459 |
|
|---|
| 460 | function transition_easeVarying(value) {
|
|---|
| 461 | if (typeof value !== "function") throw new Error;
|
|---|
| 462 | return this.each(easeVarying(this._id, value));
|
|---|
| 463 | }
|
|---|
| 464 |
|
|---|
| 465 | function transition_filter(match) {
|
|---|
| 466 | if (typeof match !== "function") match = d3Selection.matcher(match);
|
|---|
| 467 |
|
|---|
| 468 | for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
|
|---|
| 469 | for (var group = groups[j], n = group.length, subgroup = subgroups[j] = [], node, i = 0; i < n; ++i) {
|
|---|
| 470 | if ((node = group[i]) && match.call(node, node.__data__, i, group)) {
|
|---|
| 471 | subgroup.push(node);
|
|---|
| 472 | }
|
|---|
| 473 | }
|
|---|
| 474 | }
|
|---|
| 475 |
|
|---|
| 476 | return new Transition(subgroups, this._parents, this._name, this._id);
|
|---|
| 477 | }
|
|---|
| 478 |
|
|---|
| 479 | function transition_merge(transition) {
|
|---|
| 480 | if (transition._id !== this._id) throw new Error;
|
|---|
| 481 |
|
|---|
| 482 | for (var groups0 = this._groups, groups1 = transition._groups, m0 = groups0.length, m1 = groups1.length, m = Math.min(m0, m1), merges = new Array(m0), j = 0; j < m; ++j) {
|
|---|
| 483 | for (var group0 = groups0[j], group1 = groups1[j], n = group0.length, merge = merges[j] = new Array(n), node, i = 0; i < n; ++i) {
|
|---|
| 484 | if (node = group0[i] || group1[i]) {
|
|---|
| 485 | merge[i] = node;
|
|---|
| 486 | }
|
|---|
| 487 | }
|
|---|
| 488 | }
|
|---|
| 489 |
|
|---|
| 490 | for (; j < m0; ++j) {
|
|---|
| 491 | merges[j] = groups0[j];
|
|---|
| 492 | }
|
|---|
| 493 |
|
|---|
| 494 | return new Transition(merges, this._parents, this._name, this._id);
|
|---|
| 495 | }
|
|---|
| 496 |
|
|---|
| 497 | function start(name) {
|
|---|
| 498 | return (name + "").trim().split(/^|\s+/).every(function(t) {
|
|---|
| 499 | var i = t.indexOf(".");
|
|---|
| 500 | if (i >= 0) t = t.slice(0, i);
|
|---|
| 501 | return !t || t === "start";
|
|---|
| 502 | });
|
|---|
| 503 | }
|
|---|
| 504 |
|
|---|
| 505 | function onFunction(id, name, listener) {
|
|---|
| 506 | var on0, on1, sit = start(name) ? init : set;
|
|---|
| 507 | return function() {
|
|---|
| 508 | var schedule = sit(this, id),
|
|---|
| 509 | on = schedule.on;
|
|---|
| 510 |
|
|---|
| 511 | // If this node shared a dispatch with the previous node,
|
|---|
| 512 | // just assign the updated shared dispatch and we’re done!
|
|---|
| 513 | // Otherwise, copy-on-write.
|
|---|
| 514 | if (on !== on0) (on1 = (on0 = on).copy()).on(name, listener);
|
|---|
| 515 |
|
|---|
| 516 | schedule.on = on1;
|
|---|
| 517 | };
|
|---|
| 518 | }
|
|---|
| 519 |
|
|---|
| 520 | function transition_on(name, listener) {
|
|---|
| 521 | var id = this._id;
|
|---|
| 522 |
|
|---|
| 523 | return arguments.length < 2
|
|---|
| 524 | ? get(this.node(), id).on.on(name)
|
|---|
| 525 | : this.each(onFunction(id, name, listener));
|
|---|
| 526 | }
|
|---|
| 527 |
|
|---|
| 528 | function removeFunction(id) {
|
|---|
| 529 | return function() {
|
|---|
| 530 | var parent = this.parentNode;
|
|---|
| 531 | for (var i in this.__transition) if (+i !== id) return;
|
|---|
| 532 | if (parent) parent.removeChild(this);
|
|---|
| 533 | };
|
|---|
| 534 | }
|
|---|
| 535 |
|
|---|
| 536 | function transition_remove() {
|
|---|
| 537 | return this.on("end.remove", removeFunction(this._id));
|
|---|
| 538 | }
|
|---|
| 539 |
|
|---|
| 540 | function transition_select(select) {
|
|---|
| 541 | var name = this._name,
|
|---|
| 542 | id = this._id;
|
|---|
| 543 |
|
|---|
| 544 | if (typeof select !== "function") select = d3Selection.selector(select);
|
|---|
| 545 |
|
|---|
| 546 | for (var groups = this._groups, m = groups.length, subgroups = new Array(m), j = 0; j < m; ++j) {
|
|---|
| 547 | for (var group = groups[j], n = group.length, subgroup = subgroups[j] = new Array(n), node, subnode, i = 0; i < n; ++i) {
|
|---|
| 548 | if ((node = group[i]) && (subnode = select.call(node, node.__data__, i, group))) {
|
|---|
| 549 | if ("__data__" in node) subnode.__data__ = node.__data__;
|
|---|
| 550 | subgroup[i] = subnode;
|
|---|
| 551 | schedule(subgroup[i], name, id, i, subgroup, get(node, id));
|
|---|
| 552 | }
|
|---|
| 553 | }
|
|---|
| 554 | }
|
|---|
| 555 |
|
|---|
| 556 | return new Transition(subgroups, this._parents, name, id);
|
|---|
| 557 | }
|
|---|
| 558 |
|
|---|
| 559 | function transition_selectAll(select) {
|
|---|
| 560 | var name = this._name,
|
|---|
| 561 | id = this._id;
|
|---|
| 562 |
|
|---|
| 563 | if (typeof select !== "function") select = d3Selection.selectorAll(select);
|
|---|
| 564 |
|
|---|
| 565 | for (var groups = this._groups, m = groups.length, subgroups = [], parents = [], j = 0; j < m; ++j) {
|
|---|
| 566 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
|---|
| 567 | if (node = group[i]) {
|
|---|
| 568 | for (var children = select.call(node, node.__data__, i, group), child, inherit = get(node, id), k = 0, l = children.length; k < l; ++k) {
|
|---|
| 569 | if (child = children[k]) {
|
|---|
| 570 | schedule(child, name, id, k, children, inherit);
|
|---|
| 571 | }
|
|---|
| 572 | }
|
|---|
| 573 | subgroups.push(children);
|
|---|
| 574 | parents.push(node);
|
|---|
| 575 | }
|
|---|
| 576 | }
|
|---|
| 577 | }
|
|---|
| 578 |
|
|---|
| 579 | return new Transition(subgroups, parents, name, id);
|
|---|
| 580 | }
|
|---|
| 581 |
|
|---|
| 582 | var Selection = d3Selection.selection.prototype.constructor;
|
|---|
| 583 |
|
|---|
| 584 | function transition_selection() {
|
|---|
| 585 | return new Selection(this._groups, this._parents);
|
|---|
| 586 | }
|
|---|
| 587 |
|
|---|
| 588 | function styleNull(name, interpolate) {
|
|---|
| 589 | var string00,
|
|---|
| 590 | string10,
|
|---|
| 591 | interpolate0;
|
|---|
| 592 | return function() {
|
|---|
| 593 | var string0 = d3Selection.style(this, name),
|
|---|
| 594 | string1 = (this.style.removeProperty(name), d3Selection.style(this, name));
|
|---|
| 595 | return string0 === string1 ? null
|
|---|
| 596 | : string0 === string00 && string1 === string10 ? interpolate0
|
|---|
| 597 | : interpolate0 = interpolate(string00 = string0, string10 = string1);
|
|---|
| 598 | };
|
|---|
| 599 | }
|
|---|
| 600 |
|
|---|
| 601 | function styleRemove(name) {
|
|---|
| 602 | return function() {
|
|---|
| 603 | this.style.removeProperty(name);
|
|---|
| 604 | };
|
|---|
| 605 | }
|
|---|
| 606 |
|
|---|
| 607 | function styleConstant(name, interpolate, value1) {
|
|---|
| 608 | var string00,
|
|---|
| 609 | string1 = value1 + "",
|
|---|
| 610 | interpolate0;
|
|---|
| 611 | return function() {
|
|---|
| 612 | var string0 = d3Selection.style(this, name);
|
|---|
| 613 | return string0 === string1 ? null
|
|---|
| 614 | : string0 === string00 ? interpolate0
|
|---|
| 615 | : interpolate0 = interpolate(string00 = string0, value1);
|
|---|
| 616 | };
|
|---|
| 617 | }
|
|---|
| 618 |
|
|---|
| 619 | function styleFunction(name, interpolate, value) {
|
|---|
| 620 | var string00,
|
|---|
| 621 | string10,
|
|---|
| 622 | interpolate0;
|
|---|
| 623 | return function() {
|
|---|
| 624 | var string0 = d3Selection.style(this, name),
|
|---|
| 625 | value1 = value(this),
|
|---|
| 626 | string1 = value1 + "";
|
|---|
| 627 | if (value1 == null) string1 = value1 = (this.style.removeProperty(name), d3Selection.style(this, name));
|
|---|
| 628 | return string0 === string1 ? null
|
|---|
| 629 | : string0 === string00 && string1 === string10 ? interpolate0
|
|---|
| 630 | : (string10 = string1, interpolate0 = interpolate(string00 = string0, value1));
|
|---|
| 631 | };
|
|---|
| 632 | }
|
|---|
| 633 |
|
|---|
| 634 | function styleMaybeRemove(id, name) {
|
|---|
| 635 | var on0, on1, listener0, key = "style." + name, event = "end." + key, remove;
|
|---|
| 636 | return function() {
|
|---|
| 637 | var schedule = set(this, id),
|
|---|
| 638 | on = schedule.on,
|
|---|
| 639 | listener = schedule.value[key] == null ? remove || (remove = styleRemove(name)) : undefined;
|
|---|
| 640 |
|
|---|
| 641 | // If this node shared a dispatch with the previous node,
|
|---|
| 642 | // just assign the updated shared dispatch and we’re done!
|
|---|
| 643 | // Otherwise, copy-on-write.
|
|---|
| 644 | if (on !== on0 || listener0 !== listener) (on1 = (on0 = on).copy()).on(event, listener0 = listener);
|
|---|
| 645 |
|
|---|
| 646 | schedule.on = on1;
|
|---|
| 647 | };
|
|---|
| 648 | }
|
|---|
| 649 |
|
|---|
| 650 | function transition_style(name, value, priority) {
|
|---|
| 651 | var i = (name += "") === "transform" ? d3Interpolate.interpolateTransformCss : interpolate;
|
|---|
| 652 | return value == null ? this
|
|---|
| 653 | .styleTween(name, styleNull(name, i))
|
|---|
| 654 | .on("end.style." + name, styleRemove(name))
|
|---|
| 655 | : typeof value === "function" ? this
|
|---|
| 656 | .styleTween(name, styleFunction(name, i, tweenValue(this, "style." + name, value)))
|
|---|
| 657 | .each(styleMaybeRemove(this._id, name))
|
|---|
| 658 | : this
|
|---|
| 659 | .styleTween(name, styleConstant(name, i, value), priority)
|
|---|
| 660 | .on("end.style." + name, null);
|
|---|
| 661 | }
|
|---|
| 662 |
|
|---|
| 663 | function styleInterpolate(name, i, priority) {
|
|---|
| 664 | return function(t) {
|
|---|
| 665 | this.style.setProperty(name, i.call(this, t), priority);
|
|---|
| 666 | };
|
|---|
| 667 | }
|
|---|
| 668 |
|
|---|
| 669 | function styleTween(name, value, priority) {
|
|---|
| 670 | var t, i0;
|
|---|
| 671 | function tween() {
|
|---|
| 672 | var i = value.apply(this, arguments);
|
|---|
| 673 | if (i !== i0) t = (i0 = i) && styleInterpolate(name, i, priority);
|
|---|
| 674 | return t;
|
|---|
| 675 | }
|
|---|
| 676 | tween._value = value;
|
|---|
| 677 | return tween;
|
|---|
| 678 | }
|
|---|
| 679 |
|
|---|
| 680 | function transition_styleTween(name, value, priority) {
|
|---|
| 681 | var key = "style." + (name += "");
|
|---|
| 682 | if (arguments.length < 2) return (key = this.tween(key)) && key._value;
|
|---|
| 683 | if (value == null) return this.tween(key, null);
|
|---|
| 684 | if (typeof value !== "function") throw new Error;
|
|---|
| 685 | return this.tween(key, styleTween(name, value, priority == null ? "" : priority));
|
|---|
| 686 | }
|
|---|
| 687 |
|
|---|
| 688 | function textConstant(value) {
|
|---|
| 689 | return function() {
|
|---|
| 690 | this.textContent = value;
|
|---|
| 691 | };
|
|---|
| 692 | }
|
|---|
| 693 |
|
|---|
| 694 | function textFunction(value) {
|
|---|
| 695 | return function() {
|
|---|
| 696 | var value1 = value(this);
|
|---|
| 697 | this.textContent = value1 == null ? "" : value1;
|
|---|
| 698 | };
|
|---|
| 699 | }
|
|---|
| 700 |
|
|---|
| 701 | function transition_text(value) {
|
|---|
| 702 | return this.tween("text", typeof value === "function"
|
|---|
| 703 | ? textFunction(tweenValue(this, "text", value))
|
|---|
| 704 | : textConstant(value == null ? "" : value + ""));
|
|---|
| 705 | }
|
|---|
| 706 |
|
|---|
| 707 | function textInterpolate(i) {
|
|---|
| 708 | return function(t) {
|
|---|
| 709 | this.textContent = i.call(this, t);
|
|---|
| 710 | };
|
|---|
| 711 | }
|
|---|
| 712 |
|
|---|
| 713 | function textTween(value) {
|
|---|
| 714 | var t0, i0;
|
|---|
| 715 | function tween() {
|
|---|
| 716 | var i = value.apply(this, arguments);
|
|---|
| 717 | if (i !== i0) t0 = (i0 = i) && textInterpolate(i);
|
|---|
| 718 | return t0;
|
|---|
| 719 | }
|
|---|
| 720 | tween._value = value;
|
|---|
| 721 | return tween;
|
|---|
| 722 | }
|
|---|
| 723 |
|
|---|
| 724 | function transition_textTween(value) {
|
|---|
| 725 | var key = "text";
|
|---|
| 726 | if (arguments.length < 1) return (key = this.tween(key)) && key._value;
|
|---|
| 727 | if (value == null) return this.tween(key, null);
|
|---|
| 728 | if (typeof value !== "function") throw new Error;
|
|---|
| 729 | return this.tween(key, textTween(value));
|
|---|
| 730 | }
|
|---|
| 731 |
|
|---|
| 732 | function transition_transition() {
|
|---|
| 733 | var name = this._name,
|
|---|
| 734 | id0 = this._id,
|
|---|
| 735 | id1 = newId();
|
|---|
| 736 |
|
|---|
| 737 | for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
|
|---|
| 738 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
|---|
| 739 | if (node = group[i]) {
|
|---|
| 740 | var inherit = get(node, id0);
|
|---|
| 741 | schedule(node, name, id1, i, group, {
|
|---|
| 742 | time: inherit.time + inherit.delay + inherit.duration,
|
|---|
| 743 | delay: 0,
|
|---|
| 744 | duration: inherit.duration,
|
|---|
| 745 | ease: inherit.ease
|
|---|
| 746 | });
|
|---|
| 747 | }
|
|---|
| 748 | }
|
|---|
| 749 | }
|
|---|
| 750 |
|
|---|
| 751 | return new Transition(groups, this._parents, name, id1);
|
|---|
| 752 | }
|
|---|
| 753 |
|
|---|
| 754 | function transition_end() {
|
|---|
| 755 | var on0, on1, that = this, id = that._id, size = that.size();
|
|---|
| 756 | return new Promise(function(resolve, reject) {
|
|---|
| 757 | var cancel = {value: reject},
|
|---|
| 758 | end = {value: function() { if (--size === 0) resolve(); }};
|
|---|
| 759 |
|
|---|
| 760 | that.each(function() {
|
|---|
| 761 | var schedule = set(this, id),
|
|---|
| 762 | on = schedule.on;
|
|---|
| 763 |
|
|---|
| 764 | // If this node shared a dispatch with the previous node,
|
|---|
| 765 | // just assign the updated shared dispatch and we’re done!
|
|---|
| 766 | // Otherwise, copy-on-write.
|
|---|
| 767 | if (on !== on0) {
|
|---|
| 768 | on1 = (on0 = on).copy();
|
|---|
| 769 | on1._.cancel.push(cancel);
|
|---|
| 770 | on1._.interrupt.push(cancel);
|
|---|
| 771 | on1._.end.push(end);
|
|---|
| 772 | }
|
|---|
| 773 |
|
|---|
| 774 | schedule.on = on1;
|
|---|
| 775 | });
|
|---|
| 776 |
|
|---|
| 777 | // The selection was empty, resolve end immediately
|
|---|
| 778 | if (size === 0) resolve();
|
|---|
| 779 | });
|
|---|
| 780 | }
|
|---|
| 781 |
|
|---|
| 782 | var id = 0;
|
|---|
| 783 |
|
|---|
| 784 | function Transition(groups, parents, name, id) {
|
|---|
| 785 | this._groups = groups;
|
|---|
| 786 | this._parents = parents;
|
|---|
| 787 | this._name = name;
|
|---|
| 788 | this._id = id;
|
|---|
| 789 | }
|
|---|
| 790 |
|
|---|
| 791 | function transition(name) {
|
|---|
| 792 | return d3Selection.selection().transition(name);
|
|---|
| 793 | }
|
|---|
| 794 |
|
|---|
| 795 | function newId() {
|
|---|
| 796 | return ++id;
|
|---|
| 797 | }
|
|---|
| 798 |
|
|---|
| 799 | var selection_prototype = d3Selection.selection.prototype;
|
|---|
| 800 |
|
|---|
| 801 | Transition.prototype = transition.prototype = {
|
|---|
| 802 | constructor: Transition,
|
|---|
| 803 | select: transition_select,
|
|---|
| 804 | selectAll: transition_selectAll,
|
|---|
| 805 | selectChild: selection_prototype.selectChild,
|
|---|
| 806 | selectChildren: selection_prototype.selectChildren,
|
|---|
| 807 | filter: transition_filter,
|
|---|
| 808 | merge: transition_merge,
|
|---|
| 809 | selection: transition_selection,
|
|---|
| 810 | transition: transition_transition,
|
|---|
| 811 | call: selection_prototype.call,
|
|---|
| 812 | nodes: selection_prototype.nodes,
|
|---|
| 813 | node: selection_prototype.node,
|
|---|
| 814 | size: selection_prototype.size,
|
|---|
| 815 | empty: selection_prototype.empty,
|
|---|
| 816 | each: selection_prototype.each,
|
|---|
| 817 | on: transition_on,
|
|---|
| 818 | attr: transition_attr,
|
|---|
| 819 | attrTween: transition_attrTween,
|
|---|
| 820 | style: transition_style,
|
|---|
| 821 | styleTween: transition_styleTween,
|
|---|
| 822 | text: transition_text,
|
|---|
| 823 | textTween: transition_textTween,
|
|---|
| 824 | remove: transition_remove,
|
|---|
| 825 | tween: transition_tween,
|
|---|
| 826 | delay: transition_delay,
|
|---|
| 827 | duration: transition_duration,
|
|---|
| 828 | ease: transition_ease,
|
|---|
| 829 | easeVarying: transition_easeVarying,
|
|---|
| 830 | end: transition_end,
|
|---|
| 831 | [Symbol.iterator]: selection_prototype[Symbol.iterator]
|
|---|
| 832 | };
|
|---|
| 833 |
|
|---|
| 834 | var defaultTiming = {
|
|---|
| 835 | time: null, // Set on use.
|
|---|
| 836 | delay: 0,
|
|---|
| 837 | duration: 250,
|
|---|
| 838 | ease: d3Ease.easeCubicInOut
|
|---|
| 839 | };
|
|---|
| 840 |
|
|---|
| 841 | function inherit(node, id) {
|
|---|
| 842 | var timing;
|
|---|
| 843 | while (!(timing = node.__transition) || !(timing = timing[id])) {
|
|---|
| 844 | if (!(node = node.parentNode)) {
|
|---|
| 845 | throw new Error(`transition ${id} not found`);
|
|---|
| 846 | }
|
|---|
| 847 | }
|
|---|
| 848 | return timing;
|
|---|
| 849 | }
|
|---|
| 850 |
|
|---|
| 851 | function selection_transition(name) {
|
|---|
| 852 | var id,
|
|---|
| 853 | timing;
|
|---|
| 854 |
|
|---|
| 855 | if (name instanceof Transition) {
|
|---|
| 856 | id = name._id, name = name._name;
|
|---|
| 857 | } else {
|
|---|
| 858 | id = newId(), (timing = defaultTiming).time = d3Timer.now(), name = name == null ? null : name + "";
|
|---|
| 859 | }
|
|---|
| 860 |
|
|---|
| 861 | for (var groups = this._groups, m = groups.length, j = 0; j < m; ++j) {
|
|---|
| 862 | for (var group = groups[j], n = group.length, node, i = 0; i < n; ++i) {
|
|---|
| 863 | if (node = group[i]) {
|
|---|
| 864 | schedule(node, name, id, i, group, timing || inherit(node, id));
|
|---|
| 865 | }
|
|---|
| 866 | }
|
|---|
| 867 | }
|
|---|
| 868 |
|
|---|
| 869 | return new Transition(groups, this._parents, name, id);
|
|---|
| 870 | }
|
|---|
| 871 |
|
|---|
| 872 | d3Selection.selection.prototype.interrupt = selection_interrupt;
|
|---|
| 873 | d3Selection.selection.prototype.transition = selection_transition;
|
|---|
| 874 |
|
|---|
| 875 | var root = [null];
|
|---|
| 876 |
|
|---|
| 877 | function active(node, name) {
|
|---|
| 878 | var schedules = node.__transition,
|
|---|
| 879 | schedule,
|
|---|
| 880 | i;
|
|---|
| 881 |
|
|---|
| 882 | if (schedules) {
|
|---|
| 883 | name = name == null ? null : name + "";
|
|---|
| 884 | for (i in schedules) {
|
|---|
| 885 | if ((schedule = schedules[i]).state > SCHEDULED && schedule.name === name) {
|
|---|
| 886 | return new Transition([[node]], root, name, +i);
|
|---|
| 887 | }
|
|---|
| 888 | }
|
|---|
| 889 | }
|
|---|
| 890 |
|
|---|
| 891 | return null;
|
|---|
| 892 | }
|
|---|
| 893 |
|
|---|
| 894 | exports.active = active;
|
|---|
| 895 | exports.interrupt = interrupt;
|
|---|
| 896 | exports.transition = transition;
|
|---|
| 897 |
|
|---|
| 898 | Object.defineProperty(exports, '__esModule', { value: true });
|
|---|
| 899 |
|
|---|
| 900 | })));
|
|---|