mxgraph icon indicating copy to clipboard operation
mxgraph copied to clipboard

Can MXGRAPH be used in Angular 4?

Open viskel opened this issue 9 years ago • 31 comments

viskel avatar Aug 04 '17 18:08 viskel

@Rajsmit at this time no, This implementation is not the best way to go about it. I'm working on a better implementation and I will post a working github repo when that is finished. Unfortunately, I don't have a timeline for completion.

NicCOConnor avatar Jan 12 '18 11:01 NicCOConnor

@khtan1987 and @NicCOConnor Please help me to get mxgraph worked in angular-4/5/6. Also please share any sample code. Its very urgent in my project.

ghost avatar May 15 '18 04:05 ghost

@TrickTrcker are you using TypeScript along with Angular?

cristophersfr avatar May 15 '18 04:05 cristophersfr

Yes,i am using TypeScript(2.7.2) . Please find my package.json { "name": "Angular 5", "version": "2.0.0-beta.1", "description": "Angular 5", "author": "TrickTrackers", "homepage": "", "copyright": "", "license": "MIT", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build --prod", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, "private": true, "dependencies": { "angular/animations": "5.2.10", "angular/cdk": "5.2.1", "angular/common": "5.2.10", "angular/compiler": "5.2.10", "angular/core": "5.2.10", "angular/forms": "5.2.10", "angular/http": "5.2.10", "angular/platform-browser": "5.2.10", "angular/platform-browser-dynamic": "5.2.10", "angular/router": "5.2.10", "coreui/angular": "^2.0.0-beta.2", "coreui/coreui-plugin-chartjs-custom-tooltips": "^1.1.0", "types/jquery": "^2.0.49", "Base64": "^1.0.1", "angular-sortablejs": "^2.5.2", "chart.js": "2.7.2", "core-js": "2.5.5", "flag-icon-css": "3.0.0", "font-awesome": "^4.7.0", "jquery": "^3.3.1", "moment": "2.22.1", "ng2-charts": "1.6.0", "ngx-bootstrap": "2.0.4", "ngx-ckeditor": "^0.3.1", "ngx-contextmenu": "4.2.0", "ngx-perfect-scrollbar": "5.3.5", "node-sass": "^4.9.0", "primeng": "^5.2.4", "rxjs": "5.5.10", "simple-line-icons": "^2.4.1", "sortablejs": "^1.7.0", "ts-helpers": "1.1.2", "zone.js": "0.8.26" }, "devDependencies": { "angular/cli": "1.7.4", "angular/compiler-cli": "5.2.10", "angular/language-service": "5.2.10", "types/jasmine": "2.8.6", "types/jasminewd2": "2.0.3", "types/node": "9.6.5", "codelyzer": "4.2.1", "jasmine-core": "2.9.1", "jasmine-spec-reporter": "4.2.1", "karma": "2.0.0", "karma-chrome-launcher": "2.2.0", "karma-coverage-istanbul-reporter": "1.4.2", "karma-jasmine": "1.1.1", "karma-jasmine-html-reporter": "0.2.2", "protractor": "5.3.1", "ts-node": "4.1.0", "tslint": "5.9.1", "typescript": "2.7.2" }, "engines": { "node": ">= 8.9.4", "npm": ">= 5.6.0" } }

ghost avatar May 15 '18 04:05 ghost

Do you have the types.ts for mxGraph usage? @TrickTrcker

cristophersfr avatar May 15 '18 04:05 cristophersfr

No i dont have. Now i am following @NicCOConnor instruction. Also found some resources https://github.com/lgleim/mxgraph-typings. But not worked,i am new to angular 4,5.

ghost avatar May 15 '18 04:05 ghost

@TrickTrcker Well, from my perspective, there is no easy way around this, mxGraph is a JavaScript library and it should work with TypeScript "compiled" JS, but, for having types and definitions into TS code, you will need to define those types, which are basically, a lot of interfaces telling Angular that these pieces of code will be further available into a .js, just like every other part of it.

So, I did a few steps to make it work:

(i) Into src/typings.d.ts:

I've references my predefined types:

/// <reference path="./typings/Util.d.ts" />
/// <reference path="./typings/Handlers.d.ts" />
/// <reference path="./typings/mxClient.d.ts" />
/// <reference path="./typings/Constants.d.ts" />
/// <reference path="./typings/Layout.d.ts" />
/// <reference path="./typings/Shape.d.ts" />
/// <reference path="./typings/View.d.ts" />
/// <reference path="./typings/mxGraph.d.ts" />

(...)

(ii) Then I'll define what types I'll require into my Angular app:

Into src/typings, I have these files:

https://github.com/gooddaytoday/mxgraph-typescript-definitions

Those headers I'll need for my app, I define by myself.

(iii) Into src/assets, I'll put mxClient.js file. This file will contain the real code for mxGraph to work.

(iv) For last, into src/index.html:

I'll define the path to mxClient.js

<script type="text/javascript">
     mxBasePath = 'assets/';
</script>

Most of this work is manual and you need to understand how does JavaScript, TypeScript and Angular communicate, I strongly recommend you have a deeper look into Angular docs.

cristophersfr avatar May 15 '18 04:05 cristophersfr

Here Is the solution for mxgraph with angular 6.x https://github.com/Cadmus/epicupsdraw

renjithsraj avatar Jul 25 '18 10:07 renjithsraj

@Cadmus this is not true implementation.You just included in index. it is not angular way.

morwalz avatar Aug 05 '18 19:08 morwalz

If anyone struggling with mxGraph integration in Angular 4/5/6. Then here is Complete Solution: https://stackoverflow.com/questions/49922708/how-to-integrate-mxgraph-with-angular-4/54689971#54689971

ViksYelapale avatar Aug 01 '19 06:08 ViksYelapale

I have not been able to get any of this to work with Angular 8.x unfortunately. @NicCOConnor Is the tsGraph project still being worked on? If so, what is the current state of it? If not, why not? Do you need help?

emilbonnek avatar Sep 12 '19 08:09 emilbonnek