Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diagram: Transfer to TS #2916

Merged
merged 13 commits into from
Nov 13, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Diagram from 'devextreme-react/diagram';
import 'whatwg-fetch';

export default function App() {
const diagramRef = React.useRef();
const diagramRef = React.useRef<Diagram>();

React.useEffect(() => {
const diagram = diagramRef.current.instance;
Expand Down
2 changes: 1 addition & 1 deletion JSDemos/Demos/Diagram/Adaptability/React/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<script src="../../../../../node_modules/systemjs/dist/system.js"></script>
<script type="text/javascript" src="config.js"></script>
<script type="text/javascript">
System.import("./index.js");
System.import("./index.tsx");
</script>
</head>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';

import App from './App.js';
import App from './App.tsx';

ReactDOM.render(
<App />,
Expand Down
25 changes: 25 additions & 0 deletions JSDemos/Demos/Diagram/Adaptability/ReactJs/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import Diagram from 'devextreme-react/diagram';
import 'whatwg-fetch';

export default function App() {
const diagramRef = React.useRef();
React.useEffect(() => {
const diagram = diagramRef.current.instance;
fetch('../../../../data/diagram-flow.json')
.then((response) => response.json())
.then((json) => {
diagram.import(JSON.stringify(json));
})
.catch(() => {
throw new Error('Data Loading Error');
});
}, []);
return (
<Diagram
id="diagram"
ref={diagramRef}
autoZoomMode="fitWidth"
/>
);
}
53 changes: 53 additions & 0 deletions JSDemos/Demos/Diagram/Adaptability/ReactJs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html>
<head>
<title>DevExtreme Demo</title>
<meta
http-equiv="X-UA-Compatible"
content="IE=edge"
/>
<meta
http-equiv="Content-Type"
content="text/html; charset=utf-8"
/>
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0"
/>
<link
rel="stylesheet"
type="text/css"
href="../../../../../node_modules/devextreme-dist/css/dx.light.css"
/>
<link
rel="stylesheet"
type="text/css"
href="../../../../../node_modules/devexpress-diagram/dist/dx-diagram.css"
/>
<link
rel="stylesheet"
type="text/css"
href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css"
/>
<link
rel="stylesheet"
type="text/css"
href="styles.css"
/>
<script src="../../../../../node_modules/core-js/client/shim.min.js"></script>
<script src="../../../../../node_modules/systemjs/dist/system.js"></script>
<script
type="text/javascript"
src="config.js"
></script>
<script type="text/javascript">
System.import("./index.js");
</script>
</head>

<body class="dx-viewport">
<div class="demo-container">
<div id="app"></div>
</div>
</body>
</html>
5 changes: 5 additions & 0 deletions JSDemos/Demos/Diagram/Adaptability/ReactJs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App.js';

ReactDOM.render(<App />, document.getElementById('app'));
5 changes: 5 additions & 0 deletions JSDemos/Demos/Diagram/Adaptability/ReactJs/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.demo-container,
#app,
#diagram {
height: 100%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Diagram, {
Nodes, AutoLayout, Edges, Toolbox, Group,
} from 'devextreme-react/diagram';
import ArrayStore from 'devextreme/data/array_store';
import service from './data.js';
import service from './data.ts';

const orgItemsDataSource = new ArrayStore({
key: 'id',
Expand All @@ -14,7 +14,7 @@ const orgLinksDataSource = new ArrayStore({
data: service.getOrgLinks(),
});

function itemTypeExpr(obj, value) {
function itemTypeExpr(obj: { type: string; }, value: string) {
if (value) {
obj.type = (value === 'rectangle') ? undefined : 'group';
} else {
Expand All @@ -23,7 +23,7 @@ function itemTypeExpr(obj, value) {
return null;
}

function itemWidthExpr(obj, value) {
function itemWidthExpr(obj: { width: number; type: string; }, value) {
if (value) {
obj.width = value;
} else {
Expand All @@ -32,7 +32,7 @@ function itemWidthExpr(obj, value) {
return null;
}

function itemHeightExpr(obj, value) {
function itemHeightExpr(obj: { height: number; type: string; }, value) {
if (value) {
obj.height = value;
} else {
Expand All @@ -41,15 +41,15 @@ function itemHeightExpr(obj, value) {
return null;
}

function itemTextStyleExpr(obj) {
function itemTextStyleExpr(obj: { level: string; }) {
if (obj.level === 'senior') {
return { 'font-weight': 'bold', 'text-decoration': 'underline' };
}
return {};
}

function itemStyleExpr(obj) {
const style = { stroke: '#444444' };
function itemStyleExpr(obj: { type: string; }) {
const style: React.CSSProperties = { stroke: '#444444' };
if (obj.type === 'group') {
style.fill = '#f3f3f3';
}
Expand Down
2 changes: 1 addition & 1 deletion JSDemos/Demos/Diagram/AdvancedDataBinding/React/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<script src="../../../../../node_modules/systemjs/dist/system.js"></script>
<script type="text/javascript" src="config.js"></script>
<script type="text/javascript">
System.import("./index.js");
System.import("./index.tsx");
</script>
</head>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';

import App from './App.js';
import App from './App.tsx';

ReactDOM.render(
<App />,
Expand Down
93 changes: 93 additions & 0 deletions JSDemos/Demos/Diagram/AdvancedDataBinding/ReactJs/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import React from 'react';
import Diagram, {
Nodes, AutoLayout, Edges, Toolbox, Group,
} from 'devextreme-react/diagram';
import ArrayStore from 'devextreme/data/array_store';
import service from './data.js';

const orgItemsDataSource = new ArrayStore({
key: 'id',
data: service.getOrgItems(),
});
const orgLinksDataSource = new ArrayStore({
key: 'id',
data: service.getOrgLinks(),
});
function itemTypeExpr(obj, value) {
if (value) {
obj.type = value === 'rectangle' ? undefined : 'group';
} else {
return obj.type === 'group' ? 'ellipse' : 'rectangle';
}
return null;
}
function itemWidthExpr(obj, value) {
if (value) {
obj.width = value;
} else {
return obj.width || (obj.type === 'group' && 1.5) || 1;
}
return null;
}
function itemHeightExpr(obj, value) {
if (value) {
obj.height = value;
} else {
return obj.height || (obj.type === 'group' && 1) || 0.75;
}
return null;
}
function itemTextStyleExpr(obj) {
if (obj.level === 'senior') {
return { 'font-weight': 'bold', 'text-decoration': 'underline' };
}
return {};
}
function itemStyleExpr(obj) {
const style = { stroke: '#444444' };
if (obj.type === 'group') {
style.fill = '#f3f3f3';
}
return style;
}
function linkStyleExpr() {
return { stroke: '#444444' };
}
function linkFromLineEndExpr() {
return 'none';
}
function linkToLineEndExpr() {
return 'none';
}
export default function App() {
return (
<Diagram id="diagram">
<Nodes
dataSource={orgItemsDataSource}
typeExpr={itemTypeExpr}
textExpr="name"
widthExpr={itemWidthExpr}
heightExpr={itemHeightExpr}
textStyleExpr={itemTextStyleExpr}
styleExpr={itemStyleExpr}
>
<AutoLayout
type="tree"
orientation="horizontal"
/>
</Nodes>
<Edges
dataSource={orgLinksDataSource}
styleExpr={linkStyleExpr}
fromLineEndExpr={linkFromLineEndExpr}
toLineEndExpr={linkToLineEndExpr}
/>
<Toolbox>
<Group
category="general"
title="General"
/>
</Toolbox>
</Diagram>
);
}
Loading
Loading