Skip to content

Commit b401e2f

Browse files
authored
Merge pull request #2 from yWorks/dev
Dev
2 parents 6cb07f6 + 61b690b commit b401e2f

38 files changed

+607
-432
lines changed

README.md

Lines changed: 33 additions & 299 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
Welcome to the *yFiles React Organization Chart* component, a powerful and versatile React component based on the [yFiles](https://www.yworks.com/yfiles-overview) library.
66
This component enables seamless integration for displaying organization charts in your React applications.
77

8-
## [Documentation, Examples, and Live Playground](https://docs.yworks.com/react-yfiles-orgchart)
9-
108
## Getting Started
119

12-
1310
1. **Installation:**
1411
Install the component via npm by running the following command in your project directory:
1512
```bash
@@ -64,308 +61,45 @@ This component enables seamless integration for displaying organization charts i
6461

6562
> **Note:** By default, the `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 `OrgChart` component. This can be achieved by defining a CSS class or applying inline styles.
6663

64+
## Documentation
6765

68-
## Features
69-
70-
### Customization
71-
72-
This component includes styling and options tailored for general organizational charts. The items in the `data` array must satisfy the `OrgChartItem` type.
73-
74-
```ts
75-
type OrgChartItem = {
76-
id: any
77-
subordinates?: any[]
78-
assistant?: boolean
79-
width?: number
80-
height?: number
81-
}
82-
```
83-
* The optional `subordinates` define the parent-child relationships and should only contain ids of other data items.
84-
* If `assistant` is `true`, an item is an assistant to its superior and is placed on a separate layer between the superior and the non-assistant subordinates.
85-
* The optional `width` and `height` define the render size of the item. If no values are given, the size is determined automatically.
86-
87-
The default visualization expects data items of type `CustomOrgChartItem<Employee>` where `Employee` is defined like this:
88-
```ts
89-
type Employee = {
90-
name?: string
91-
status?: string
92-
position?: string
93-
email?: string
94-
phone?: string
95-
icon?: string
96-
}
97-
```
98-
99-
Moreover, the visualization of items is highly customizable. You can specify custom React components to render the items according to your specific requirements.
100-
Note that, to optimize performance and depending on the implementation, it might be necessary to use memoization for these custom components.
101-
102-
```tsx
103-
function MyOrgChartItem(props: RenderItemProps<CustomOrgChartItem<Employee>>) {
104-
const { dataItem } = props
105-
return (
106-
<div
107-
style={{
108-
width: '100%',
109-
height: '100%',
110-
backgroundColor: 'gold',
111-
display: 'flex',
112-
justifyContent: 'center',
113-
alignItems: 'center'
114-
}}
115-
>
116-
<div>{dataItem.name}</div>
117-
</div>
118-
)
119-
}
120-
121-
function OrganizationChart () {
122-
return (
123-
<OrgChart
124-
data={data}
125-
renderItem={MyOrgChartItem}
126-
itemSize={{ width: 300, height: 200 }}
127-
></OrgChart>
128-
)
129-
}
130-
```
131-
132-
The background and size of the `OrgChart` component can be adjusted using the properties `className` or `style`.
133-
134-
By default, the organizational chart component offers interactive expanding and collapsing of subordinates and supervisors. If you wish to transform it into a viewer-only component, set the `interactive` property to `false`.
135-
136-
The organizational chart component includes a rendering feature that enables users to customize connection visualizations. It grants control over parameters such as stroke, bend smoothing, thickness, and arrow styles.
137-
The rendering process employs an SVG path element, allowing for the utilization of CSS to customize the stroke or incorporate transitions by defining a `className`. Note that, to optimize performance and depending on the implementation,
138-
it might be necessary to memoize the rendering function.
139-
140-
```tsx
141-
function connectionStyles(
142-
source: CustomOrgChartItem,
143-
target: CustomOrgChartItem
144-
): ConnectionStyle | undefined {
145-
if (source.assistant || target.assistant) {
146-
return {
147-
thickness: 10,
148-
className: 'dashed-line',
149-
targetArrow: { type: 'triangle' }
150-
}
151-
} else {
152-
return { thickness: 5 }
153-
}
154-
}
155-
156-
function OrganizationChart() {
157-
return <OrgChart data={data} connectionStyles={connectionStyles}></OrgChart>
158-
}
159-
```
160-
161-
```html
162-
<style>
163-
.dashed-line {
164-
color: #665008;
165-
stroke-dasharray: 3px;
166-
stroke-dashoffset: 6px;
167-
}
168-
</style>
169-
```
170-
171-
### Events
172-
173-
The organization chart component includes event notifications that inform users when an item is focused, selected or hovered over. This functionality provides the flexibility to respond to these state changes, allowing for the dynamic updating of external information panels, among other possibilities.
174-
To optimize performance, it is recommended to cache the corresponding functions.
175-
176-
```tsx
177-
function OrganizationChart() {
178-
const onItemFocus = useCallback(
179-
(item: CustomOrgChartItem | null) => item && console.log(`focused: ${item.name}`),
180-
[]
181-
)
182-
const onItemSelect = useCallback(
183-
(selectedItems: CustomOrgChartItem[]) =>
184-
console.log(selectedItems.length ? `selected: ${selectedItems[0].name}` : 'nothing selected'),
185-
[]
186-
)
187-
const onItemHover = useCallback(
188-
(item: CustomOrgChartItem | null) => item && console.log(`hovered: ${item.name}`),
189-
[]
190-
)
191-
192-
return <OrgChart data={data} onItemFocus={onItemFocus} onItemSelect={onItemSelect} onItemHover={onItemHover}></OrgChart>
193-
}
194-
```
195-
196-
### Search
197-
198-
The component introduces a search feature which offers a way to focus on specific elements within the chart. By binding a needle `object` or `string`, items fitting the search criteria are highlighted.
199-
200-
```tsx
201-
function OrganizationChart() {
202-
const [searchQuery, setSearchQuery] = useState('')
203-
return (
204-
<>
205-
<input
206-
type={'search'}
207-
onChange={event => {
208-
setSearchQuery(event.target.value)
209-
}}
210-
></input>
211-
212-
<OrgChart data={data} searchNeedle={searchQuery}></OrgChart>
213-
</>
214-
)
215-
}
216-
```
217-
To further tailor the search functionality, developers can customize the process by registering a function to the `onSearch` event, which returns a `boolean` value indicating if the search was successful for the given item.
218-
219-
220-
### Tooltip
66+
Find the full documentation, API and many code examples in our [documentation](https://docs.yworks.com/react-yfiles-orgchart).
22167

222-
Tooltips display specific information when hovering over an item. Users can configure the tooltip by setting a custom React component in the `renderTooltip` prop.
223-
The organization chart component provides a default tooltip that displays the name of a person.
68+
## Live Playground
22469

225-
```tsx
226-
function OrganizationChart () {
227-
return (
228-
<OrgChart
229-
data={data}
230-
renderTooltip={OrgChartTooltipTemplate}>
231-
</OrgChart>
232-
)
233-
}
234-
```
70+
[![Live Playground](https://raw.githubusercontent.com/yWorks/react-yfiles-orgchart/main/assets/playground.png)](https://docs.yworks.com/react-yfiles-orgchart/introduction/welcome)
23571

236-
### Context Menu
237-
The context menu provides context-specific actions for items.
238-
You can use the `contextMenuItems` to populate the context menu with actions. The organization chart component introduces a default context menu which provides actions to interact with the chart.
72+
Try the yFiles React Organization Chart component directly in our browser with our [playground](https://docs.yworks.com/react-yfiles-orgchart/introduction/welcome)
23973

240-
```tsx
241-
function OrganizationChart() {
242-
return (
243-
<OrgChart data={data} contextMenuItems={OrgChartContextMenuItems}></OrgChart>
244-
)
245-
}
246-
```
247-
248-
To adjust the context menu visualization, add a custom React component using the `renderContextMenu` property.
249-
250-
```tsx
251-
function OrganizationChart() {
252-
return (
253-
<OrgChart
254-
data={data}
255-
renderContextMenu={() => <button onClick={() => alert('Clicked')}>Click here!</button>}
256-
></OrgChart>
257-
)
258-
}
259-
```
260-
261-
### Popup
262-
263-
The popup provides a custom overlay that displays contextual information for organization chart data.
264-
The position of the popup relative to the clicked item can be configured with the `popupPosition` property.
265-
To adjust the popup visualization, add a custom React component using the `renderPopup` property.
266-
267-
```tsx
268-
function OrganizationChart () {
269-
return (
270-
<OrgChart data={data}
271-
popupPosition="north-east"
272-
renderPopup={(props: RenderPopupProps<CustomOrgChartItem>) => (<div>{props.item.name}</div>)}
273-
></OrgChart>
274-
)
275-
}
276-
```
277-
278-
### Built-In Components
279-
280-
There are optional components available to enhance the interaction with the organization chart, which can be added as children of the organization chart component:
281-
282-
- **Overview**: Presents a simplified view of the entire graph along with the current viewport.
283-
- **Controls**: Features a toolbar with buttons to adjust the viewport.
284-
285-
The controls component comes with a default implementation for organization charts.
286-
287-
```tsx
288-
function OrganizationChart() {
289-
return (
290-
<OrgChart data={data}>
291-
<Overview></Overview>
292-
<Controls buttons={OrgChartControlButtons}></Controls>
293-
</OrgChart>
294-
)
295-
}
296-
```
297-
298-
299-
### Hook & OrgChartProvider
300-
301-
Through the `useOrgChartContext()` hook, users gain access to the organization chart model, allowing them to utilize its functions for further customization of the interaction with the organization chart.
302-
303-
This hook is accessible only when used in a child component of an `OrgChartProvider`. This condition is consistently met when implementing child components for the `OrgChart` component. However, if the hook is called outside the organization chart component, the `OrgChartProvider` must be a common ancestor.
304-
305-
The following example demonstrates how to use the hook for a button in a sidebar or a customized context menu.
306-
307-
```tsx
308-
function OrgChartWrapper() {
309-
const { fitContent, zoomToItem } = useOrgChartContext()!
310-
311-
return (
312-
<>
313-
<OrgChart data={data} contextMenuItems={(item: CustomOrgChartItem | null) => {
314-
if (item) {
315-
return [{ title: 'Zoom to Item', action: () => item && zoomToItem(item) }]
316-
}
317-
return []
318-
}}>
319-
</OrgChart>
320-
<Sidebar>
321-
<button onClick={fitContent}>Fit Content</button>
322-
</Sidebar>
323-
</>
324-
)
325-
}
326-
327-
function OrganizationChart () {
328-
return (
329-
<OrgChartProvider>
330-
<OrgChartWrapper></OrgChartWrapper>
331-
</OrgChartProvider>
332-
)
333-
}
334-
```
335-
336-
### Export Capabilities
337-
338-
The component allows users to export either the entire diagram or a specific part of it in SVG or PNG format.
339-
Furthermore, it incorporates a print function that leverages the browser's capabilities, enabling users to generate
340-
hard copies or save the diagram as PDF for offline access.
341-
342-
Access to the corresponding export functions is provided through the `useOrgChartContext()` hook described above.
343-
344-
```tsx
345-
function OrgChartWrapper() {
346-
const { print, exportToSvg, exportToPng } = useOrgChartContext()!
347-
348-
return (
349-
<>
350-
<OrgChart data={data}></OrgChart>
351-
<Sidebar>
352-
<button onClick={async () => await print({ scale: 2 })}>Print</button>
353-
<button onClick={async () => await exportToSvg({ scale: 2 })}>Export to SVG</button>
354-
<button onClick={async () => await exportToPng({ scale: 2 })}>Export to PNG</button>
355-
</Sidebar>
356-
</>
357-
)
358-
}
359-
360-
function OrganizationChart () {
361-
return (
362-
<OrgChartProvider>
363-
<OrgChartWrapper></OrgChartWrapper>
364-
</OrgChartProvider>
365-
)
366-
}
367-
```
74+
## Features
36875

76+
The component provides versatile features out of the box that can be further tailored to specific use cases.
77+
78+
<table>
79+
<tr>
80+
<td>
81+
<a href="https://docs.yworks.com/react-yfiles-orgchart/introduction/welcome"><img src="https://raw.githubusercontent.com/yWorks/react-yfiles-orgchart/main/assets/level-of-detail.png" title="Level of detail visualization" alt="Level of detail visualization"></a><br>
82+
<a href="https://docs.yworks.com/react-yfiles-orgchart/introduction/welcome">Level of detail visualization</a>
83+
</td>
84+
<td>
85+
<a href="https://docs.yworks.com/react-yfiles-orgchart/features/custom-items"><img src="https://raw.githubusercontent.com/yWorks/react-yfiles-orgchart/main/assets/custom-visualization.png" title="Custom visualization" alt="Custom visualization"></a><br>
86+
<a href="https://docs.yworks.com/react-yfiles-orgchart/features/custom-items">Custom visualization</a>
87+
</td>
88+
</tr>
89+
<tr>
90+
<td>
91+
<a href="https://docs.yworks.com/react-yfiles-orgchart/features/hook-orgchartprovider"><img src="https://raw.githubusercontent.com/yWorks/react-yfiles-orgchart/main/assets/collapse-expand.png" title="Collapse / Expand" alt="Collapse / Expand"></a><br>
92+
<a href="https://docs.yworks.com/react-yfiles-orgchart/features/hook-orgchartprovider">Custom visualization</a>
93+
</td>
94+
<td>
95+
<a href="https://docs.yworks.com/react-yfiles-orgchart/features/search"><img src="https://raw.githubusercontent.com/yWorks/react-yfiles-orgchart/main/assets/search.png" title="Search" alt="Search"></a><br>
96+
<a href="https://docs.yworks.com/react-yfiles-orgchart/features/search">Search</a>
97+
</td>
98+
</tr>
99+
</table>
100+
101+
Find all features in the [documentation](https://docs.yworks.com/react-yfiles-orgchart) and try them directly in the
102+
browser with our integrated code playground.
369103

370104
## Learn More
371105

assets/collapse-expand.png

23.7 KB
Loading

assets/custom-visualization.png

27.8 KB
Loading

assets/level-of-detail.png

45.8 KB
Loading

assets/playground.png

46.9 KB
Loading

assets/search.png

13.6 KB
Loading

docs/assets/usericon_female1.svg

Lines changed: 36 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)