Do explicit imports for d3 instead of wildcards

This commit is contained in:
Adrian Hall
2020-05-11 07:10:04 +01:00
parent 8ef3aee7e7
commit 053a86c0d4
20 changed files with 136 additions and 118 deletions

View File

@@ -1,5 +1,5 @@
import graphlib from 'graphlib';
import * as d3 from 'd3';
import { select, curveLinear, selectAll } from 'd3';
import flowDb from './flowDb';
import flow from './parser/flow';
@@ -25,7 +25,7 @@ export const setConf = function(cnf) {
* @param g The graph that is to be drawn.
*/
export const addVertices = function(vert, g, svgId) {
const svg = d3.select(`[id="${svgId}"]`);
const svg = select(`[id="${svgId}"]`);
const keys = Object.keys(vert);
// Iterate through each item in the vertex object (containing all the vertices found) in the graph definition
@@ -224,11 +224,11 @@ export const addEdges = function(edges, g) {
edgeData.labelStyle = labelStyle;
if (typeof edge.interpolate !== 'undefined') {
edgeData.curve = interpolateToCurve(edge.interpolate, d3.curveLinear);
edgeData.curve = interpolateToCurve(edge.interpolate, curveLinear);
} else if (typeof edges.defaultInterpolate !== 'undefined') {
edgeData.curve = interpolateToCurve(edges.defaultInterpolate, d3.curveLinear);
edgeData.curve = interpolateToCurve(edges.defaultInterpolate, curveLinear);
} else {
edgeData.curve = interpolateToCurve(conf.curve, d3.curveLinear);
edgeData.curve = interpolateToCurve(conf.curve, curveLinear);
}
if (typeof edge.text === 'undefined') {
@@ -336,7 +336,7 @@ export const draw = function(text, id) {
for (i = subGraphs.length - 1; i >= 0; i--) {
subG = subGraphs[i];
d3.selectAll('cluster').append('text');
selectAll('cluster').append('text');
for (let j = 0; j < subG.nodes.length; j++) {
g.setParent(subG.nodes[j], subG.id);
@@ -349,10 +349,10 @@ export const draw = function(text, id) {
// flowChartShapes.addToRenderV2(addShape);
// Set up an SVG group so that we can translate the final graph.
const svg = d3.select(`[id="${id}"]`);
const svg = select(`[id="${id}"]`);
// Run the renderer. This is what draws the final graph.
const element = d3.select('#' + id + ' g');
const element = select('#' + id + ' g');
render(element, g, ['point', 'circle', 'cross'], 'flowchart', id);
// dagre.layout(g);
@@ -433,7 +433,7 @@ export const draw = function(text, id) {
const vertex = vert[key];
if (vertex.link) {
const node = d3.select('#' + id + ' [id="' + key + '"]');
const node = select('#' + id + ' [id="' + key + '"]');
if (node) {
const link = document.createElementNS('http://www.w3.org/2000/svg', 'a');
link.setAttributeNS('http://www.w3.org/2000/svg', 'class', vertex.classes.join(' '));