diff --git a/packages/treemap/src/TreeMapHtmlNode.tsx b/packages/treemap/src/TreeMapHtmlNode.tsx
index 418d31b30e..32918c1d79 100644
--- a/packages/treemap/src/TreeMapHtmlNode.tsx
+++ b/packages/treemap/src/TreeMapHtmlNode.tsx
@@ -23,6 +23,7 @@ const NonMemoizedTreeMapHtmlNode = ({
return (
({
/>
{showLabel && (
({
)}
{showParentLabel && (
({
return (
Math.max(v, 0))}
height={to(animatedProps.height, v => Math.max(v, 0))}
fill={node.fill ? node.fill : animatedProps.color}
@@ -37,6 +38,7 @@ const NonMemoizedTreeMapNode = ({
/>
{showLabel && (
({
)}
{showParentLabel && (
{
Globals.assign({ skipAnimation: false })
})
-it('should render a basic treemap chart', () => {})
+it('should render a basic treemap chart', () => {
+ const wrapper = mount()
-/*
-it('should render a basic network chart', () => {
- const wrapper = mount()
-
- sampleData.nodes.forEach(node => {
- const nodeElement = wrapper.find(`circle[data-testid='node.${node.id}']`)
+ nodes.forEach(node => {
+ const nodeElement = wrapper.find(`rect[data-testid='node.${node.id}']`)
expect(nodeElement.exists()).toBeTruthy()
- })
- sampleData.links.forEach(link => {
- const linkElement = wrapper.find(`line[data-testid='link.${link.source}.${link.target}']`)
- expect(linkElement.exists()).toBeTruthy()
+ if (node.value !== undefined) {
+ const label = wrapper.find(`text[data-testid='label.${node.id}']`)
+ expect(label.exists()).toBeTruthy()
+ expect(label.text()).toEqual(`${node.value}`)
+ } else {
+ const parentLabel = wrapper.find(`text[data-testid='parentLabel.${node.id}']`)
+ expect(parentLabel.exists()).toBeTruthy()
+ expect(parentLabel.text()).toEqual(node.id)
+ }
})
})
describe('nodes', () => {
- it('static node color', () => {
- const color = 'rgba(255, 0, 255, 1)'
- const wrapper = mount()
-
- sampleData.nodes.forEach(node => {
- expect(wrapper.find(`circle[data-testid='node.${node.id}']`).prop('fill')).toEqual(
- color
- )
- })
- })
-
- it('static node size', () => {
- const size = 32
- const wrapper = mount()
-
- sampleData.nodes.forEach(node => {
- expect(wrapper.find(`circle[data-testid='node.${node.id}']`).prop('r')).toEqual(
- size / 2
- )
- })
- })
-
- it('dynamic node size', () => {
- const computeSize = (node: { id: string; index: number }) => 10 + node.index * 2
- const nodesWithIndex = sampleData.nodes.map((node, index) => ({
- ...node,
- index,
- }))
- const wrapper = mount(
-
- {...baseProps}
- data={{
- nodes: nodesWithIndex,
- links: sampleData.links,
- }}
- nodeSize={computeSize}
- />
- )
-
- nodesWithIndex.forEach(node => {
- expect(wrapper.find(`circle[data-testid='node.${node.id}']`).prop('r')).toEqual(
- computeSize(node) / 2
- )
- })
- })
-
it('custom node component', () => {
- const CustomNode = ({ node }: NodeProps) => (
+ const CustomNode = ({ node }: NodeProps) => (
)
+ const wrapper = mount()
- const wrapper = mount()
-
- sampleData.nodes.forEach(node => {
+ nodes.forEach(node => {
expect(wrapper.find(`g[data-testid='node.${node.id}.custom']`).exists()).toBeTruthy()
})
})
})
-describe('active/inactive nodes', () => {
- it('styles depending on nodes status', () => {
- const wrapper = mount(
-
- )
-
- sampleData.nodes.forEach(activeNode => {
- wrapper.find(`circle[data-testid='node.${activeNode.id}']`).simulate('mouseenter')
-
- expect(
- wrapper.find(`circle[data-testid='node.${activeNode.id}']`).parent().prop('r').get()
- ).toEqual(10)
-
- sampleData.nodes
- .filter(node => node.id !== activeNode.id)
- .forEach(otherNode => {
- expect(
- wrapper
- .find(`circle[data-testid='node.${otherNode.id}']`)
- .parent()
- .prop('r')
- .get()
- ).toEqual(0)
- })
- })
- })
-
- it('default active node ids', () => {
- const activeIds = ['A', 'C']
- const wrapper = mount(
-
- )
-
- sampleData.nodes.forEach(node => {
- const nodeElement = wrapper.find(`circle[data-testid='node.${node.id}']`)
-
- if (activeIds.includes(node.id)) {
- expect(nodeElement.prop('r')).toEqual(10)
- } else {
- expect(nodeElement.prop('r')).toEqual(0)
- }
- })
- })
-
- it('ignored if non interactive', () => {
- const wrapper = mount(
-
- )
-
- sampleData.nodes.forEach(node => {
- expect(wrapper.find(`circle[data-testid='node.${node.id}']`).prop('r')).toEqual(5)
- })
- })
-})
-
-describe('links', () => {
- it('static link thickness', () => {
- const wrapper = mount()
-
- sampleData.links.forEach(link => {
- expect(
- wrapper
- .find(`line[data-testid='link.${link.source}.${link.target}']`)
- .prop('strokeWidth')
- ).toEqual(3)
- })
- })
-
- it('dynamic link thickness', () => {
- const wrapper = mount( 1 + link.index} />)
-
- sampleData.links.forEach((link, index) => {
- expect(
- wrapper
- .find(`line[data-testid='link.${link.source}.${link.target}']`)
- .prop('strokeWidth')
- ).toEqual(1 + index)
- })
- })
-
- it('static link color', () => {
- const color = 'rgba(255, 0, 0, 1)'
- const wrapper = mount()
-
- sampleData.links.forEach(link => {
- expect(
- wrapper
- .find(`line[data-testid='link.${link.source}.${link.target}']`)
- .prop('stroke')
- ).toEqual(color)
- })
- })
-
- it('dynamic link color', () => {
- const wrapper = mount(
- `rgba(${link.index * 10}, 0, 0, 1)`} />
- )
-
- sampleData.links.forEach((link, index) => {
- expect(
- wrapper
- .find(`line[data-testid='link.${link.source}.${link.target}']`)
- .prop('stroke')
- ).toEqual(`rgba(${index * 10}, 0, 0, 1)`)
- })
- })
-
- it('link color from source node color', () => {
- const color = 'rgba(125, 255, 125, 1)'
- const wrapper = mount(
-
- )
-
- sampleData.links.forEach(link => {
- expect(
- wrapper
- .find(`line[data-testid='link.${link.source}.${link.target}']`)
- .prop('stroke')
- ).toEqual(color)
- })
- })
-
- it('link color from target node color', () => {
- const color = 'rgba(125, 125, 255, 1)'
- const wrapper = mount(
-
- )
-
- sampleData.links.forEach(link => {
- expect(
- wrapper
- .find(`line[data-testid='link.${link.source}.${link.target}']`)
- .prop('stroke')
- ).toEqual(color)
- })
- })
-
- it('link blend mode', () => {
- const wrapper = mount()
-
- sampleData.links.forEach(link => {
- expect(
- wrapper.find(`line[data-testid='link.${link.source}.${link.target}']`).prop('style')
- ).toEqual({ mixBlendMode: 'multiply' })
- })
- })
-
- it('custom link component', () => {
- const CustomLink = ({ link }: LinkProps) => (
-
- )
-
- const wrapper = mount()
-
- sampleData.links.forEach(link => {
- expect(
- wrapper.find(`g[data-testid='link.${link.source}.${link.target}.custom']`).exists()
- ).toBeTruthy()
- })
- })
-})
-
describe('tooltip', () => {
it('default node tooltip', () => {
- const wrapper = mount()
+ const wrapper = mount()
- sampleData.nodes.forEach(node => {
- const nodeElement = wrapper.find(`circle[data-testid='node.${node.id}']`)
+ nodes.forEach(node => {
+ const nodeElement = wrapper.find(`rect[data-testid='node.${node.id}']`)
nodeElement.simulate('mouseenter')
- const tooltip = wrapper.find(svgDefaultProps.nodeTooltip).childAt(0).childAt(0)
+ const tooltip = wrapper.find(svgDefaultProps.tooltip).childAt(0).childAt(0)
expect(tooltip.exists()).toBeTruthy()
- expect(tooltip.text()).toEqual(node.id)
+
+ if (node.value !== undefined) {
+ expect(tooltip.text()).toEqual(`${node.id}: ${node.value}`)
+ } else {
+ expect(tooltip.text()).toEqual(`${node.id}: ${node.sum}`)
+ }
nodeElement.simulate('mouseleave')
- expect(wrapper.find(svgDefaultProps.nodeTooltip).children()).toHaveLength(0)
+ expect(wrapper.find(svgDefaultProps.tooltip).children()).toHaveLength(0)
})
})
it('disabled if non interactive', () => {
- const wrapper = mount()
+ const wrapper = mount()
- sampleData.nodes.forEach(node => {
- const nodeElement = wrapper.find(`circle[data-testid='node.${node.id}']`)
+ nodes.forEach(node => {
+ const nodeElement = wrapper.find(`rect[data-testid='node.${node.id}']`)
nodeElement.simulate('mouseenter')
- expect(wrapper.find(svgDefaultProps.nodeTooltip).children()).toHaveLength(0)
+ expect(wrapper.find(svgDefaultProps.tooltip).children()).toHaveLength(0)
})
})
- it('custom node tooltip', () => {
- const CustomTooltip = ({ node }: { node: ComputedNode }) => (
+ it('custom tooltip', () => {
+ const CustomTooltip = ({ node }: TooltipProps) => (
Custom: {node.id}
)
- const wrapper = mount()
+ const wrapper = mount()
- sampleData.nodes.forEach(node => {
- const nodeElement = wrapper.find(`circle[data-testid='node.${node.id}']`)
+ nodes.forEach(node => {
+ const nodeElement = wrapper.find(`rect[data-testid='node.${node.id}']`)
nodeElement.simulate('mouseenter')
@@ -363,10 +134,10 @@ describe('tooltip', () => {
describe('interactivity', () => {
it('onClick', () => {
const onClick = jest.fn()
- const wrapper = mount()
+ const wrapper = mount()
- sampleData.nodes.forEach(node => {
- wrapper.find(`circle[data-testid='node.${node.id}']`).simulate('click')
+ nodes.forEach(node => {
+ wrapper.find(`rect[data-testid='node.${node.id}']`).simulate('click')
expect(onClick).toHaveBeenCalledTimes(1)
const [datum] = onClick.mock.calls[0]
@@ -378,10 +149,10 @@ describe('interactivity', () => {
it('onMouseEnter', () => {
const onMouseEnter = jest.fn()
- const wrapper = mount()
+ const wrapper = mount()
- sampleData.nodes.forEach(node => {
- wrapper.find(`circle[data-testid='node.${node.id}']`).simulate('mouseenter')
+ nodes.forEach(node => {
+ wrapper.find(`rect[data-testid='node.${node.id}']`).simulate('mouseenter')
expect(onMouseEnter).toHaveBeenCalledTimes(1)
const [datum] = onMouseEnter.mock.calls[0]
@@ -393,10 +164,10 @@ describe('interactivity', () => {
it('onMouseMove handler', () => {
const onMouseMove = jest.fn()
- const wrapper = mount()
+ const wrapper = mount()
- sampleData.nodes.forEach(node => {
- wrapper.find(`circle[data-testid='node.${node.id}']`).simulate('mousemove')
+ nodes.forEach(node => {
+ wrapper.find(`rect[data-testid='node.${node.id}']`).simulate('mousemove')
expect(onMouseMove).toHaveBeenCalledTimes(1)
const [datum] = onMouseMove.mock.calls[0]
@@ -408,10 +179,10 @@ describe('interactivity', () => {
it('onMouseLeave handler', () => {
const onMouseLeave = jest.fn()
- const wrapper = mount()
+ const wrapper = mount()
- sampleData.nodes.forEach(node => {
- wrapper.find(`circle[data-testid='node.${node.id}']`).simulate('mouseleave')
+ nodes.forEach(node => {
+ wrapper.find(`rect[data-testid='node.${node.id}']`).simulate('mouseleave')
expect(onMouseLeave).toHaveBeenCalledTimes(1)
const [datum] = onMouseLeave.mock.calls[0]
@@ -428,7 +199,7 @@ describe('interactivity', () => {
const onMouseLeave = jest.fn()
const wrapper = mount(
- {
/>
)
- sampleData.nodes.forEach(node => {
- const nodeElement = wrapper.find(`circle[data-testid='node.${node.id}']`)
+ nodes.forEach(node => {
+ const nodeElement = wrapper.find(`rect[data-testid='node.${node.id}']`)
nodeElement.simulate('mouseenter')
expect(onMouseEnter).not.toHaveBeenCalled()
@@ -457,68 +228,22 @@ describe('interactivity', () => {
})
describe('layers', () => {
- it('custom order', () => {
- const wrapper = mount()
-
- const layers = wrapper.find('svg > g').children()
- expect(layers.at(0).is('NetworkNodes')).toBeTruthy()
- expect(layers.at(1).is('NetworkLinks')).toBeTruthy()
- })
-
it('custom layer', () => {
const CustomLayer = () => null
- const wrapper = mount()
+ const wrapper = mount()
const customLayer = wrapper.find(CustomLayer)
expect(customLayer.exists()).toBeTruthy()
const customLayerProps = customLayer.props()
expect(customLayerProps).toHaveProperty('nodes')
- expect(customLayerProps).toHaveProperty('links')
- expect(customLayerProps).toHaveProperty('activeNodeIds')
- expect(customLayerProps).toHaveProperty('setActiveNodeIds')
- })
-})
-
-describe('annotations', () => {
- it('circle annotation using id', () => {
- const annotatedNodeId = 'C'
- const wrapper = mount(
-
- )
-
- const annotation = wrapper.find(Annotation)
- expect(annotation.exists()).toBeTruthy()
-
- const annotatedNode = wrapper.find(`circle[data-testid='node.${annotatedNodeId}']`)
- const [nodeX, nodeY] = Array.from(
- annotatedNode.prop('transform').match(/translate\(([0-9.]+),([0-9.]+)\)/)
- )
- .slice(1)
- .map(Number)
-
- expect(annotation.find('circle').first().prop('cx')).toEqual(nodeX)
- expect(annotation.find('circle').first().prop('cy')).toEqual(nodeY)
})
})
describe('accessibility', () => {
it('aria properties', () => {
const wrapper = mount(
- {
expect(svg.prop('aria-describedby')).toBe('AriaDescribedBy')
})
})
-*/