Я использую vis для отображения некоторого графика в моей сети. Я могу использовать этот кусок кода для отображения:
import { Component, AfterViewInit, ElementRef, ViewChild } from '@angular/core';
import { Network, DataSet, DataView} from 'vis';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.scss']
})
export class TestComponent implements AfterViewInit {
@ViewChild('network', {static: false}) el: ElementRef;
@ViewChild('nodeFilterSelect', {static:false}) nodeFilter: ElementRef;
@ViewChild('edgesFilter', {static: false}) edgeFilter: ElementRef;
private networkInstance: any;
ngAfterViewInit() {
const nodes_set = new DataSet<any>([
{ id: 1, label: 'Eric Cartman', age: 'kid', gender: 'male' },
{ id: 2, label: 'Stan Marsh', age: 'kid', gender: 'male' },
{ id: 3, label: 'Wendy Testaburger', age: 'kid', gender: 'female' },
{ id: 4, label: 'Mr Mackey', age: 'adult', gender: 'male' },
{ id: 5, label: 'Sharon Marsh', age: 'adult', gender: 'female' }
],{});
const edges_set = new DataSet<any>([
{ from: 1, to: 2, relation: 'friend', arrows: 'to, from', color: { color: 'red'} },
{ from: 1, to: 3, relation: 'friend', arrows: 'to, from', color: { color: 'red'} },
{ from: 2, to: 3, relation: 'friend', arrows: 'to, from', color: { color: 'red'} },
{ from: 5, to: 2, relation: 'parent', arrows: 'to', color: { color: 'green'} },
{ from: 4, to: 1, relation: 'teacher', arrows: 'to', color: { color: 'blue'} },
{ from: 4, to: 2, relation: 'teacher', arrows: 'to', color: { color: 'blue'} },
{ from: 4, to: 3, relation: 'teacher', arrows: 'to', color: { color: 'blue'} },
],{});
const container = this.el.nativeElement;
// this.networkInstance = new Network(container, {nodes_set, edges_set}, {});
// // this.startNetwork({ nodes: nodesView, edges: edgesView })
const data = { nodes: nodes_set, edges: edges_set };
this.networkInstance = new Network(container, data, {});
}
}
это работает.
Но теперь я хочу использовать DataView в vis, чтобы выполнить некоторую фильтрацию для графика. Я добавил это, чтобы изменить DataSet на DataView:
const nodesView = new DataView(nodes_set, {})
const edgesView = new DataView(edges_set, {})
и использовать данные просмотра в сети:
const data = { nodes: nodesView, edges: edgesView };
this.networkInstance = new Network(container, data, {});
, затем я получил эту ошибку:
edgeData .forEach - это не функция
AppComponent.ngfactory.js:30 ERROR TypeError: edgesData.forEach is not a function
at EdgesHandler._addMissingEdges (vendor.js:157837)
at EdgesHandler._updateState (vendor.js:157792)
at Network.<anonymous> (vendor.js:152776)
at Network.Emitter.emit (vendor.js:116593)
at Network.setData (vendor.js:152837)
at new Network (vendor.js:152622)
at TestComponent.ngAfterViewInit (main.js:300)
at callProviderLifecycles (vendor.js:64080)
at callElementProvidersLifecycles (vendor.js:64045)
at callLifecycleHooksChildrenFirst (vendor.js:64027)
Мне кажется, в DataView не было функции для каждой функции? Кто-нибудь знает, как это исправить?