Fix empty arrays

This commit is contained in:
Nathan Bierema 2023-01-02 14:05:24 -05:00
parent e50698b6e8
commit a3ba875560
3 changed files with 12 additions and 10 deletions

View File

@ -2,9 +2,9 @@
'd3tooltip': major 'd3tooltip': major
--- ---
- Remove UMD build - Remove UMD build.
- Upgrade d3 peer dependency from v3 to v4 - Upgrade d3 peer dependency from v3 to v4.
- Remove `attr` configuration method - Remove `attr` configuration method.
- Rename `style` configuration method to `styles` and move to options - Rename `style` configuration method to `styles` and move to options.
- Move `text` configuration method to options - Move `text` configuration method to options.
- Remove d3 parameter as first parameter for `tooltip` - Remove d3 parameter as first parameter for `tooltip`.

View File

@ -2,4 +2,4 @@
'map2tree': major 'map2tree': major
--- ---
Remove UMD build - Remove UMD build.

View File

@ -396,9 +396,9 @@ export default function (DOMNode: HTMLElement, options: Partial<Options> = {}) {
.style('stroke', 'black') .style('stroke', 'black')
.style('stroke-width', '1.5px') .style('stroke-width', '1.5px')
.style('fill', (d) => .style('fill', (d) =>
d.data._children d.data._children && d.data._children.length > 0
? nodeStyleOptions.colors.collapsed ? nodeStyleOptions.colors.collapsed
: d.data.children : d.data.children && d.data.children.length > 0
? nodeStyleOptions.colors.parent ? nodeStyleOptions.colors.parent
: nodeStyleOptions.colors.default : nodeStyleOptions.colors.default
); );
@ -418,7 +418,9 @@ export default function (DOMNode: HTMLElement, options: Partial<Options> = {}) {
.style('fill-opacity', 1) .style('fill-opacity', 1)
.attr('transform', function transform(d) { .attr('transform', function transform(d) {
const x = const x =
(d.data.children || d.data._children ? -1 : 1) * (((d.data.children ?? d.data._children)?.length ?? 0) > 0
? -1
: 1) *
(this.getBBox().width / 2 + nodeStyleOptions.radius + 5); (this.getBBox().width / 2 + nodeStyleOptions.radius + 5);
return `translate(${x},0)`; return `translate(${x},0)`;
}); });