const alphabet = [
{ characters: [{ char: 'a' }, { char: 'b' }] },
{ characters: [{ char: 'c' }, { char: 'd' }] }
];
<svg>
<g transform="translate(0, 10)">
<g transform="translate(0,0)">
<text fill="green" x="0" dy=".35em" y="0">
b
</text>
</g>
<g transform="translate(32,0)">
<text fill="green" x="0" dy=".35em" y="0">
d
</text>
</g>
</g>
</svg>
const groups = select('svg')
.select('g')
.selectAll('g')
.data(data, d => JSON.stringify(d));
const a = 'a';
const b = 'b';
const c = 'c';
const d = 'd';
const alphabet = [[a, b], [c, d]];
const alphabet2 = [[b], [d]];
update(alphabet);
setTimeout(() => {
update(alphabet2);
}, 1000);
function update(data) {
const t = d3.transition().duration(1000);
const groups = d3.select('svg')
.select('g')
.selectAll('g')
.data(data);
groups
.exit()
.transition(t)
.remove();
groups.transition(t).attr('transform', (d, i) => `translate(${i * 32},0)`);
groups
.enter()
.append('g')
.transition(t)
.attr('transform', (d, i) => `translate(${i * 32},0)`);
const texts = groups.selectAll('text').data(d => d, d => d);
texts
.exit()
.transition(t)
.attr('fill', 'brown')
.attr('y', 60)
.style('fill-opacity', 1e-6)
.remove();
texts
.attr('fill', 'black')
.attr('y', 0)
.style('fill-opacity', 1)
.transition(t)
.attr('x', (d, i) => i * 10);
texts
.enter()
.append('text')
.attr('fill', 'green')
.attr('dy', '.35em')
.attr('y', -60)
.attr('x', (d, i) => i * 10)
.style('fill-opacity', 1e-6)
.text(d => d)
.transition(t)
.attr('y', 0)
.style('fill-opacity', 1);
}
const a = 'a';
const b = 'b';
const c = 'c';
const d = 'd';
const alphabet = [[a, b], [c, d]];
const alphabet2 = [[b], [d]];
update(alphabet);
setTimeout(() => {
update(alphabet2);
}, 1000);
function update(data) {
const t = d3.transition().duration(1000);
const groups = d3.select('svg')
.select('g')
.selectAll('g')
.data(data);
groups
.exit()
.transition(t)
.remove();
groups.transition(t).attr('transform', (d, i) => `translate(${i * 32},0)`);
const groupsEnter = groups
.enter()
.append('g')
.transition(t)
.attr('transform', (d, i) => `translate(${i * 32},0)`);
const texts = groups.merge(groupsEnter).selectAll('text').data(d => d, d => d);
--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.