Skip to content

Commit 5ff19a5

Browse files
authored
Merge pull request #10 from yWorks/dev
Fixes from dev (REA-452)
2 parents 48384b8 + 911a9fa commit 5ff19a5

File tree

4 files changed

+82
-68
lines changed

4 files changed

+82
-68
lines changed

docs/introduction/GettingStarted.mdx

+71-64
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ section: 1
44
tags: []
55
---
66
import TypeLink from '../../components/TypeLink.astro'
7+
import Video from '../../components/Video.astro'
8+
import videoImage from './yt-react-components_organization-chart.png'
79

810
# Getting Started
11+
<Video image={videoImage} url="https://youtu.be/bXjnKJkiApo"/>
912

1013
## Prerequisites
1114

@@ -19,95 +22,99 @@ You can learn how to work with the yFiles npm module in our [Developer’s Guide
1922

2023
1. **Installation**
2124

22-
In addition to yFiles, the Organization Chart component requires React to be installed in your project.
23-
If you want to start your project from scratch, we recommend using vite:
24-
```
25-
npm create vite@latest my-orgchart-app -- --template react-ts
26-
```
25+
In addition to yFiles, the Organization Chart component requires React to be installed in your project.
26+
If you want to start your project from scratch, we recommend using vite:
27+
```
28+
npm create vite@latest my-orgchart-app -- --template react-ts
29+
```
2730

28-
Add the yFiles dependency:
29-
```
30-
npm install <yFiles package path>/lib-dev/yfiles-26.0.0+dev.tgz
31-
```
31+
Add the yFiles dependency:
32+
```
33+
npm install <yFiles package path>/lib-dev/yfiles-26.0.0+dev.tgz
34+
```
3235

33-
<details>
36+
<details>
3437

35-
<summary>Sample <code>package.json</code> dependencies</summary>
36-
The resulting package.json dependencies should resemble the following:
38+
<summary>Sample <code>package.json</code> dependencies</summary>
39+
The resulting package.json dependencies should resemble the following:
3740

38-
```json
39-
"dependencies": {
40-
"react": "^18.2.0",
41-
"react-dom": "^18.2.0",
42-
"yfiles": "./lib-dev/yfiles-26.0.0.tgz"
43-
}
44-
```
45-
</details>
41+
```json
42+
"dependencies": {
43+
"react": "^18.2.0",
44+
"react-dom": "^18.2.0",
45+
"yfiles": "./lib-dev/yfiles-26.0.0.tgz"
46+
}
47+
```
48+
</details>
4649

47-
Now, the component itself can be installed:
48-
```bash
49-
npm install @yworks/react-yfiles-orgchart
50-
```
50+
Now, the component itself can be installed:
51+
```bash
52+
npm install @yworks/react-yfiles-orgchart
53+
```
5154

52-
2. **License**
55+
2. **License**
5356

54-
Be sure to invoke <TypeLink type="registerLicense" /> before using the Organization Chart React component.
55-
When evaluating yFiles, the license JSON file is found in the `lib/` folder of the yFiles for HTML evaluation package.
56-
For licensed users, the license data is provided separately.
57+
Be sure to invoke <TypeLink type="registerLicense" /> before using the Organization Chart React component.
58+
When evaluating yFiles, the license JSON file is found in the `lib/` folder of the yFiles for HTML evaluation package.
59+
For licensed users, the license data is provided separately.
5760

58-
<details>
61+
<details>
5962

60-
<summary>License registration</summary>
63+
<summary>License registration</summary>
6164

62-
Import or paste your license data and register the license, e.g. in `App.tsx`:
65+
Import or paste your license data and register the license, e.g. in `App.tsx`:
6366

64-
```js
65-
import yFilesLicense from './license.json'
67+
```js
68+
import yFilesLicense from './license.json'
6669

67-
registerLicense(yFilesLicense)
68-
```
69-
</details>
70+
registerLicense(yFilesLicense)
71+
```
72+
</details>
7073

71-
3. **Stylesheet**
74+
3. **Stylesheet**
7275

73-
Make sure to import the CSS stylesheet as well:
76+
Make sure to import the CSS stylesheet as well:
7477

75-
```js
76-
import '@yworks/react-yfiles-orgchart/dist/index.css'
77-
```
78+
```js
79+
import '@yworks/react-yfiles-orgchart/dist/index.css'
80+
```
7881

79-
4. **Usage**
82+
4. **Usage**
8083

81-
You are now all set to utilize the Organization Chart component with your data!
82-
See a basic example `App.tsx` below:
84+
You are now all set to utilize the Organization Chart component with your data!
85+
See a basic example `App.tsx` below:
8386

84-
```tsx
85-
import {
86-
CustomOrgChartData,
87-
OrgChart,
88-
registerLicense
89-
} from '@yworks/react-yfiles-orgchart'
87+
```tsx
88+
import {
89+
CustomOrgChartData,
90+
OrgChart,
91+
registerLicense
92+
} from '@yworks/react-yfiles-orgchart'
9093

91-
import '@yworks/react-yfiles-orgchart/dist/index.css'
94+
import '@yworks/react-yfiles-orgchart/dist/index.css'
9295

93-
import yFilesLicense from './license.json'
96+
import yFilesLicense from './license.json'
9497

95-
registerLicense(yFilesLicense)
98+
registerLicense(yFilesLicense)
9699

97-
const data = [
98-
{ id: 0, name: 'Eric Joplin', subordinates: [1, 2] },
99-
{ id: 1, name: 'Amy Kain' },
100-
{ id: 2, name: 'David Kerry' }
101-
] satisfies CustomOrgChartData<{name: string}>
100+
const data = [
101+
{id: 0, name: 'Eric Joplin', subordinates: [1, 2]},
102+
{id: 1, name: 'Amy Kain'},
103+
{id: 2, name: 'David Kerry'}
104+
] satisfies CustomOrgChartData
105+
<
106+
{name: string}>
102107

103-
function App() {
104-
return <OrgChart data={data}></OrgChart>
105-
}
108+
function App() {
109+
return <OrgChart data={data}></OrgChart>
110+
}
106111

107-
export default App
108-
```
112+
export default App
113+
```
109114

110-
> **Note:** By default, the <TypeLink type="OrgChart" /> component adjusts its size to match the size of its parent element. Therefore, it is necessary to set the dimensions of the containing element or apply styling directly to the <TypeLink type="OrgChart" /> component. This can be achieved by defining a CSS class or applying inline styles.
115+
> **Note:** By default, the <TypeLink
116+
type="OrgChart" /> component adjusts its size to match the size of its parent element. Therefore, it is necessary to set the dimensions of the containing element or apply styling directly to the
117+
<TypeLink type="OrgChart" /> component. This can be achieved by defining a CSS class or applying inline styles.
111118
112119
## Learn More
113120

Loading

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@yworks/react-yfiles-orgchart",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"author": {
55
"name": "yFiles for HTML team @ yWorks GmbH",
66
"email": "[email protected]"

src/OrgChartProvider.tsx

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createContext, PropsWithChildren, useContext, useMemo } from 'react'
22
import { CollapsibleTree } from './core/CollapsibleTree'
3-
import { INode } from 'yfiles'
3+
import type { GraphComponent, INode } from 'yfiles'
44
import { setCollapsedState } from './styles/orgchart-port-style.ts'
55
import { useGraphComponent, withGraphComponentProvider } from '@yworks/react-yfiles-core'
66
import { createOrgChartModel, OrgChartModel } from './OrgChartModel'
@@ -55,6 +55,8 @@ export function useOrgChartContext(): OrgChartModel {
5555
return context
5656
}
5757

58+
const gcToModel = new WeakMap<GraphComponent, OrgChartModel>()
59+
5860
/**
5961
* The OrgChartProvider component is a [context provider]{@link https://react.dev/learn/passing-data-deeply-with-context},
6062
* granting external access to the organization chart beyond the {@link OrgChart} component itself.
@@ -102,13 +104,18 @@ export const OrgChartProvider = withGraphComponentProvider(({ children }: PropsW
102104
}
103105

104106
const orgChart = useMemo(() => {
107+
if (gcToModel.has(graphComponent)) {
108+
return gcToModel.get(graphComponent)!
109+
}
105110
const collapsibleTree = new CollapsibleTree(graphComponent)
106111
graphComponent.graph = collapsibleTree.filteredGraph
107112
collapsibleTree.addCollapsedStateUpdatedListener(setCollapsedState)
108113
collapsibleTree.isAssistantNode = (node: INode): boolean => node.tag?.assistant ?? false
109114
// TODO provide customizable out-edge comparer
110-
return createOrgChartModel(collapsibleTree, graphComponent)
111-
}, [])
115+
const orgChartModel = createOrgChartModel(collapsibleTree, graphComponent)
116+
gcToModel.set(graphComponent, orgChartModel)
117+
return orgChartModel
118+
}, [graphComponent])
112119

113120
return <OrgChartContext.Provider value={orgChart}>{children}</OrgChartContext.Provider>
114121
})

0 commit comments

Comments
 (0)