joint.shapes.uml. js: Uncaught TypeError: Невозможно прочитать свойство 'Generi c' из неопределенного - PullRequest
1 голос
/ 20 февраля 2020

Я отображаю диаграмму uml из Joint JS demo https://github.com/clientIO/joint/tree/master/demo/umlcd in Angular 8 и получаю ошибку: joint.shapes.uml. js: 13 Uncaught TypeError: Невозможно прочитать свойство 'Generi c' из неопределенного

на joint.shapes.uml. js: 13
на joint.shapes.uml. js: 280

joint.shapes.uml. js: https://github.com/clientIO/joint/blob/master/dist/joint.shapes.uml.js

Что я делаю не так?

Вот мой код:

angular. json

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "Inspector": {
      "projectType": "application",
      "schematics": {},
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/Inspector",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": false,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css",
              "./node_modules/jointjs/dist/joint.css",
              "./src/app/shared/umlcd.css"
            ],
            "scripts": [
              "./node_modules/jquery/dist/jquery.js",
              "./node_modules/lodash/lodash.js",
              "./node_modules/backbone/backbone.js",
              "./plugin/joint.shapes.uml.js",
              "./node_modules/jointjs/dist/joint.js"
            ]
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "5mb"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb",
                  "maximumError": "10kb"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "Inspector:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "Inspector:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "Inspector:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.spec.json",
            "karmaConfig": "karma.conf.js",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "tsconfig.app.json",
              "tsconfig.spec.json",
              "e2e/tsconfig.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        },
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "Inspector:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "Inspector:serve:production"
            }
          }
        }
      }
    }},
  "defaultProject": "Inspector"
}

Файл машинописного текста с объединенным JS демонстрационный код :

(Мне пришлось внести изменения в демонстрационный код, например: каждый объект диаграммы должен иметь массив атрибутов и методов, а свойство name должно иметь тип String [] String. Без этих изменений демонстрационный код не работал.)

import { Component, OnInit} from '@angular/core';

import * as _ from 'lodash';
import * as joint from 'jointjs';

@Component({
  selector: 'app-demo',
  templateUrl: './demo.component.html',
  styleUrls: ['./demo.component.css']
})
export class DemoComponent implements OnInit{

  constructor() { }

  ngOnInit() {
    this.createDiagram();
  }

  private createDiagram(): void {
    var graph = new joint.dia.Graph();

    new joint.dia.Paper({
        el: document.getElementById('paper'),
        width: 1000,
        height: 600,
        model: graph,
        gridSize: 1,
    });

    var uml = joint.shapes.uml;

    var classes = {

        mammal: new uml.Interface({
            position: { x:300  , y: 150 },
            size: { width: 240, height: 100 },
            name: ['Mammal'],
            attributes: ['dob: Date'],
            methods: ['+ setDateOfBirth(dob: Date): Void','+ getAgeAsDays(): Numeric'],
            attrs: {
                '.uml-class-name-rect': {
                    fill: '#feb662',
                    stroke: '#000000',
                    'stroke-width': 0.5
                },
                '.uml-class-attrs-rect': {
                    fill: '#fdc886',
                    stroke: '#fff',
                    'stroke-width': 0.5
                },
                '.uml-class-methods-rect': {
                    fill: '#fdc886',
                    stroke: '#fff',
                    'stroke-width': 0.5
                },
                '.uml-class-attrs-text': {
                    ref: '.uml-class-attrs-rect',
                    'ref-y': 0.5,
                    'y-alignment': 'middle'
                },
                '.uml-class-methods-text': {
                    ref: '.uml-class-methods-rect',
                    'ref-y': 0.5,
                    'y-alignment': 'middle'
                }

            }
        }),

        person: new uml.Abstract({
            position: { x:300  , y: 300 },
            size: { width: 260, height: 100 },
            name: ['Person'],
            attributes: ['firstName: String','lastName: String'],
            methods: ['+ setName(first: String, last: String): Void','+ getName(): String'],
            attrs: {
                '.uml-class-name-rect': {
                    fill: '#68ddd5',
                    stroke: '#ffffff',
                    'stroke-width': 0.5
                },
                '.uml-class-attrs-rect': {
                    fill: '#9687fe',
                    stroke: '#fff',
                    'stroke-width': 0.5
                },
                '.uml-class-methods-rect': {
                    fill: '#9687fe',
                    stroke: '#fff',
                    'stroke-width': 0.5
                },
                '.uml-class-methods-text, .uml-class-attrs-text': {
                    fill: '#fff'
                }
            }
        }),

        bloodgroup: new uml.Class({
            position: { x:20  , y: 190 },
            size: { width: 220, height: 100 },
            name: ['BloodGroup'],
            attributes: ['bloodGroup: String'],
            methods: ['+ isCompatible(bG: String): Boolean'],
            attrs: {
                '.uml-class-name-rect': {
                    fill: '#ff8450',
                    stroke: '#fff',
                    'stroke-width': 0.5,
                },
                '.uml-class-attrs-rect': {
                    fill: '#fe976a',
                    stroke: '#fff',
                    'stroke-width': 0.5
                },
                '.uml-class-methods-rect': {
                    fill: '#fe976a',
                    stroke: '#fff',
                    'stroke-width': 0.5
                },
                '.uml-class-attrs-text': {
                    ref: '.uml-class-attrs-rect',
                    'ref-y': 0.5,
                    'y-alignment': 'middle'
                },
                '.uml-class-methods-text': {
                    ref: '.uml-class-methods-rect',
                    'ref-y': 0.5,
                    'y-alignment': 'middle'
                }
            }
        }),

        address: new uml.Class({
            position: { x:630  , y: 190 },
            size: { width: 160, height: 100 },
            name: ['Address'],
            attributes: ['houseNumber: Integer','streetName: String','town: String','postcode: String'],
            methods: [],
            attrs: {
                '.uml-class-name-rect': {
                    fill: '#ff8450',
                    stroke: '#fff',
                    'stroke-width': 0.5
                },
                '.uml-class-attrs-rect': {
                    fill: '#fe976a',
                    stroke: '#fff',
                    'stroke-width': 0.5
                },
                '.uml-class-methods-rect': {
                    fill: '#fe976a',
                    stroke: '#fff',
                    'stroke-width': 0.5
                },
                '.uml-class-attrs-text': {
                    'ref-y': 0.5,
                    'y-alignment': 'middle'
                }
            }

        }),

        man: new uml.Class({
            position: { x:200  , y: 500 },
            size: { width: 180, height: 50 },
            name: ['Man'],
            attributes: [],
            methods: [],
            attrs: {
                '.uml-class-name-rect': {
                    fill: '#ff8450',
                    stroke: '#fff',
                    'stroke-width': 0.5
                },
                '.uml-class-attrs-rect': {
                    fill: '#fe976a',
                    stroke: '#fff',
                    'stroke-width': 0.5
                },
                '.uml-class-methods-rect': {
                    fill: '#fe976a',
                    stroke: '#fff',
                    'stroke-width': 0.5
                }
            }
        }),

        woman: new uml.Class({
            position: { x:450  , y: 500 },
            size: { width: 180, height: 50 },
            name: ['Woman'],
            attributes: [],
            methods: ['+ giveABrith(): Person []'],
            attrs: {
                '.uml-class-name-rect': {
                    fill: '#ff8450',
                    stroke: '#fff',
                    'stroke-width': 0.5
                },
                '.uml-class-attrs-rect': {
                    fill: '#fe976a',
                    stroke: '#fff',
                    'stroke-width': 0.5
                },
                '.uml-class-methods-rect': {
                    fill: '#fe976a',
                    stroke: '#fff',
                    'stroke-width': 0.5
                },
                '.uml-class-methods-text': {
                    'ref-y': 0.5,
                    'y-alignment': 'middle'
                }
            }
        })
    };

    Object.keys(classes).forEach(function(key) {
        graph.addCell(classes[key]);
    });

    var relations = [
        new uml.Generalization({ source: { id: classes.man.id }, target: { id: classes.person.id }}),
        new uml.Generalization({ source: { id: classes.woman.id }, target: { id: classes.person.id }}),
        new uml.Implementation({ source: { id: classes.person.id }, target: { id: classes.mammal.id }}),
        new uml.Aggregation({ source: { id: classes.person.id }, target: { id: classes.address.id }}),
        new uml.Composition({ source: { id: classes.person.id }, target: { id: classes.bloodgroup.id }})
    ];

    Object.keys(relations).forEach(function(key) {
        graph.addCell(relations[key]);
    });
  }

}

1 Ответ

0 голосов
/ 20 февраля 2020

В вашем angular.json порядок сценариев для включения в сборку неправильный.

joint.shapes.uml.js должен выполняться после выполнения joint.js.

Правильный порядок

 "scripts": [
              "./node_modules/jquery/dist/jquery.js",
              "./node_modules/lodash/lodash.js",
              "./node_modules/backbone/backbone.js",
              "./node_modules/jointjs/dist/joint.js"
              "./plugin/joint.shapes.uml.js",
            ]
...