Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Fix Typescript error in force_directed_graph.ts #74

Merged
merged 2 commits into from
Oct 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/force_directed_graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import * as d3 from 'd3';
import {AVisInstance, IVisInstance, assignVis, IVisInstanceOptions} from 'phovea_core/src/vis';
import {mixin} from 'phovea_core/src';
import GraphProxy from 'phovea_core/src/graph/GraphProxy';
import { GraphNode } from 'phovea_core/src/graph/graph';

export interface IForceDirectedGraphOptions extends IVisInstanceOptions {
/**
Expand All @@ -17,6 +18,13 @@ export interface IForceDirectedGraphOptions extends IVisInstanceOptions {
colors?: boolean;
}

/**
* Extends the D3 Node with a Phovea GraphNode property
*/
interface IMixedNode extends d3.layout.force.Node {
v: GraphNode;
}

export class ForceDirectedGraphVis extends AVisInstance implements IVisInstance {
private readonly $node: d3.Selection<any>;

Expand Down Expand Up @@ -107,7 +115,7 @@ export class ForceDirectedGraphVis extends AVisInstance implements IVisInstance
const colors = d3.scale.category10().range().slice();

this.data.impl().then((graph) => {
const nodes = graph.nodes.map((n) => ({v: n}));
const nodes: IMixedNode[] = graph.nodes.map((n) => ({v: n}));
const lookup = d3.map(nodes, (d) => String(d.v.id));
const edges = graph.edges.map((n) => ({
v: n,
Expand Down