@d3fc/d3fc-data-join
Advanced tools
Comparing version 6.0.2 to 6.0.3
@@ -16,3 +16,6 @@ (function (global, factory) { | ||
// - https://github.com/mbostock/d3/wiki/Transitions#d3_interpolateNumber | ||
var effectivelyZero = 1e-6; // Wrapper around d3's selectAll/data data-join, which allows decoration of the result. | ||
var effectivelyZero = 1e-6; | ||
var isTransition = function isTransition(selectionOrTransition) { | ||
return selectionOrTransition.selection() !== selectionOrTransition; | ||
}; // Wrapper around d3's selectAll/data data-join, which allows decoration of the result. | ||
// This is achieved by appending the element to the enter selection before exposing it. | ||
@@ -35,13 +38,5 @@ // A default transition of fade in/out is also implicitly added but can be modified. | ||
var implicitTransition = container.selection ? container : null; | ||
if (implicitTransition) { | ||
container = container.selection(); | ||
} | ||
var selected = container.selectAll(function (d, i, nodes) { | ||
return Array.from(nodes[i].childNodes).filter(function (node) { | ||
return node.nodeType === 1; | ||
}); | ||
}).filter(className == null ? element : "".concat(element, ".").concat(className)); | ||
var selection = container.selection(); | ||
var implicitTransition = isTransition(container) ? container : null; | ||
var selected = selection.selectChildren(className == null ? element : "".concat(element, ".").concat(className)); | ||
var update = selected.data(data, key); | ||
@@ -115,2 +110,3 @@ var enter = update.enter().append(element).attr('class', className); | ||
exports.effectivelyZero = effectivelyZero; | ||
exports.isTransition = isTransition; | ||
@@ -117,0 +113,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -1,1 +0,1 @@ | ||
(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports):"function"==typeof define&&define.amd?define(["exports"],b):(a="undefined"==typeof globalThis?a||self:globalThis,b(a.fc=a.fc||{}))})(this,function(a){'use strict';var b=1e-6;a.dataJoin=function(a,c){a=a||"g";var d=function(a,b){return b},e=null,f=function(f,g){g=g||function(a){return a};var h=f.selection?f:null;h&&(f=f.selection());var i=f.selectAll(function(a,b,c){return Array.from(c[b].childNodes).filter(function(a){return 1===a.nodeType})}).filter(null==c?a:"".concat(a,".").concat(c)),j=i.data(g,d),k=j.enter().append(a).attr("class",c),l=j.exit();j=j.merge(k);var m=h||e;return m&&(j=j.transition(m).style("opacity",1),k.style("opacity",b),l=l.transition(m).style("opacity",b)),l.remove(),j.enter=function(){return k},j.exit=function(){return l},j};return f.element=function(){return arguments.length?(a=0>=arguments.length?void 0:arguments[0],f):a},f.className=function(){return arguments.length?(c=0>=arguments.length?void 0:arguments[0],f):c},f.key=function(){return arguments.length?(d=0>=arguments.length?void 0:arguments[0],f):d},f.transition=function(){return arguments.length?(e=0>=arguments.length?void 0:arguments[0],f):e},f},a.effectivelyZero=b,Object.defineProperty(a,"__esModule",{value:!0})}); | ||
(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports):"function"==typeof define&&define.amd?define(["exports"],b):(a="undefined"==typeof globalThis?a||self:globalThis,b(a.fc=a.fc||{}))})(this,function(a){'use strict';var b=1e-6,c=function(a){return a.selection()!==a};a.dataJoin=function(a,d){a=a||"g";var e=function(a,b){return b},f=null,g=function(g,h){h=h||function(a){return a};var i=g.selection(),j=c(g)?g:null,k=i.selectChildren(null==d?a:"".concat(a,".").concat(d)),l=k.data(h,e),m=l.enter().append(a).attr("class",d),n=l.exit();l=l.merge(m);var o=j||f;return o&&(l=l.transition(o).style("opacity",1),m.style("opacity",b),n=n.transition(o).style("opacity",b)),n.remove(),l.enter=function(){return m},l.exit=function(){return n},l};return g.element=function(){return arguments.length?(a=0>=arguments.length?void 0:arguments[0],g):a},g.className=function(){return arguments.length?(d=0>=arguments.length?void 0:arguments[0],g):d},g.key=function(){return arguments.length?(e=0>=arguments.length?void 0:arguments[0],g):e},g.transition=function(){return arguments.length?(f=0>=arguments.length?void 0:arguments[0],g):f},g},a.effectivelyZero=b,a.isTransition=c,Object.defineProperty(a,"__esModule",{value:!0})}); |
@@ -6,2 +6,13 @@ # Change Log | ||
## [6.0.3](https://github.com/d3fc/d3fc/compare/@d3fc/d3fc-data-join@6.0.2...@d3fc/d3fc-data-join@6.0.3) (2020-09-23) | ||
### Bug Fixes | ||
* d3v6 selection.selection changes ([c0175ae](https://github.com/d3fc/d3fc/commit/c0175ae)) | ||
## [6.0.2](https://github.com/d3fc/d3fc/compare/@d3fc/d3fc-data-join@6.0.1...@d3fc/d3fc-data-join@6.0.2) (2020-09-16) | ||
@@ -8,0 +19,0 @@ |
@@ -1,1 +0,1 @@ | ||
export { default as dataJoin, effectivelyZero } from './src/dataJoin'; | ||
export { default as dataJoin, effectivelyZero, isTransition } from './src/dataJoin'; |
{ | ||
"name": "@d3fc/d3fc-data-join", | ||
"version": "6.0.2", | ||
"version": "6.0.3", | ||
"description": "A component that simplifies the D3 data join and supports the d3fc decorate pattern", | ||
@@ -28,3 +28,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "03c76aba48931e9ab149cc11dcaabc93f2e9d0c1" | ||
"gitHead": "a7f1db4d1fd44f696c7ead067284851953c18e6c" | ||
} |
@@ -12,2 +12,5 @@ // "Caution: avoid interpolating to or from the number zero when the interpolator is used to generate | ||
export const isTransition = selectionOrTransition => | ||
selectionOrTransition.selection() !== selectionOrTransition; | ||
// Wrapper around d3's selectAll/data data-join, which allows decoration of the result. | ||
@@ -23,17 +26,14 @@ // This is achieved by appending the element to the enter selection before exposing it. | ||
const dataJoin = function(container, data) { | ||
data = data || ((d) => d); | ||
data = data || (d => d); | ||
const implicitTransition = container.selection ? container : null; | ||
if (implicitTransition) { | ||
container = container.selection(); | ||
} | ||
const selection = container.selection(); | ||
const implicitTransition = isTransition(container) ? container : null; | ||
const selected = container.selectAll((d, i, nodes) => | ||
Array.from(nodes[i].childNodes) | ||
.filter(node => node.nodeType === 1) | ||
) | ||
.filter(className == null ? element : `${element}.${className}`); | ||
const selected = selection.selectChildren( | ||
className == null ? element : `${element}.${className}` | ||
); | ||
let update = selected.data(data, key); | ||
const enter = update.enter() | ||
const enter = update | ||
.enter() | ||
.append(element) | ||
@@ -50,6 +50,6 @@ .attr('class', className); | ||
if (transition) { | ||
update = update.transition(transition) | ||
.style('opacity', 1); | ||
update = update.transition(transition).style('opacity', 1); | ||
enter.style('opacity', effectivelyZero); | ||
exit = exit.transition(transition) | ||
exit = exit | ||
.transition(transition) | ||
.style('opacity', effectivelyZero); | ||
@@ -56,0 +56,0 @@ } |
@@ -10,6 +10,3 @@ import jsdom from 'jsdom'; | ||
}), | ||
scripts: [ | ||
require.resolve('d3/dist/d3.js'), | ||
require.resolve('..') | ||
], | ||
scripts: [require.resolve('d3/dist/d3.js'), require.resolve('..')], | ||
done: (_, win) => { | ||
@@ -29,6 +26,3 @@ const dataJoin = win.fc.dataJoin(); | ||
}), | ||
scripts: [ | ||
require.resolve('d3/dist/d3.js'), | ||
require.resolve('..') | ||
], | ||
scripts: [require.resolve('d3/dist/d3.js'), require.resolve('..')], | ||
done: (_, win) => { | ||
@@ -35,0 +29,0 @@ const dataJoin = win.fc.dataJoin(); |
@@ -42,4 +42,3 @@ import { select, selection } from 'd3-selection'; | ||
container.datum(data); | ||
join(container) | ||
.each(d => expect(d).toBe(data[0])); | ||
join(container).each(d => expect(d).toBe(data[0])); | ||
}); | ||
@@ -49,4 +48,3 @@ | ||
const join = dataJoin(); | ||
join(container, data) | ||
.append('g'); | ||
join(container, data).append('g'); | ||
expect(element.childNodes).toHaveLength(1); | ||
@@ -60,4 +58,3 @@ expect(element.childNodes[0].childNodes).toHaveLength(1); | ||
it('should use key if specified', () => { | ||
const join = dataJoin() | ||
.key(d => d); | ||
const join = dataJoin().key(d => d); | ||
join(container, [1]); | ||
@@ -79,4 +76,3 @@ const exit = join(container, [2, 3]).exit(); | ||
it('should insert specified element w/o className', () => { | ||
const join = dataJoin() | ||
.element('rect'); | ||
const join = dataJoin().element('rect'); | ||
join(container, data); | ||
@@ -103,4 +99,3 @@ expect(element.childNodes).toHaveLength(1); | ||
it('should insert new elements in an order consistent with the data', () => { | ||
const join = dataJoin() | ||
.key(d => d); | ||
const join = dataJoin().key(d => d); | ||
let data = [1, 2, 3]; | ||
@@ -129,7 +124,6 @@ | ||
join = dataJoin(); | ||
container = container.transition() | ||
.duration(1); | ||
container = container.transition().duration(1); | ||
}); | ||
it('should apply a fade in transition', (done) => { | ||
it('should apply a fade in transition', done => { | ||
const update = join(container, data); | ||
@@ -148,7 +142,7 @@ const node = update.enter().node(); | ||
it('should apply transitions to the update selection', (done) => { | ||
it('should apply transitions to the update selection', done => { | ||
const update = join(container, [1]); | ||
const node = update.node(); | ||
update.style('opacity', (d) => d); | ||
update.style('opacity', d => d); | ||
expect(Number(node.style.opacity)).toBeCloseTo(0.000001, 6); | ||
@@ -162,4 +156,5 @@ | ||
it('should apply a fade out transition', (done) => { | ||
container.selection() | ||
it('should apply a fade out transition', done => { | ||
container | ||
.selection() | ||
.append('g') | ||
@@ -181,3 +176,4 @@ .style('opacity', '1'); | ||
it('should return the untransitioned exit selection', () => { | ||
container.selection() | ||
container | ||
.selection() | ||
.append('g') | ||
@@ -187,4 +183,3 @@ .style('opacity', '1'); | ||
update.exit() | ||
.remove(); | ||
update.exit().remove(); | ||
@@ -206,3 +201,3 @@ const node = update.exit().node(); | ||
it('should use explicit transition', (done) => { | ||
it('should use explicit transition', done => { | ||
join.transition(container); | ||
@@ -224,3 +219,3 @@ container = container.selection(); | ||
it('should use implicit rather than explicit transition', (done) => { | ||
it('should use implicit rather than explicit transition', done => { | ||
const explicit = container | ||
@@ -227,0 +222,0 @@ .transition() |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27286
391