Fix errors

This commit is contained in:
Nikolay Rozhkov
2023-06-18 01:32:45 +03:00
parent afaf87e414
commit 81542142f5
3 changed files with 28 additions and 33 deletions

View File

@@ -412,7 +412,7 @@ export interface FlowchartDiagramConfig extends BaseDiagramConfig {
wrappingWidth?: number; wrappingWidth?: number;
} }
export interface SankeyDiagramConfig extends BaseDiagramConfig {} export type SankeyDiagramConfig = BaseDiagramConfig;
export interface FontConfig { export interface FontConfig {
fontSize?: string | number; fontSize?: string | number;

View File

@@ -9,10 +9,7 @@ import {
// rgb as d3rgb, // rgb as d3rgb,
map as d3map, map as d3map,
} from 'd3'; } from 'd3';
import { import { sankey as d3sankey, sankeyLinkHorizontal } from 'd3-sankey';
sankey as d3sankey,
sankeyLinkHorizontal
} from 'd3-sankey';
import { configureSvgSize } from '../../setupGraphViewbox.js'; import { configureSvgSize } from '../../setupGraphViewbox.js';
import sankeyDB from './sankeyDB.js'; import sankeyDB from './sankeyDB.js';
@@ -25,12 +22,12 @@ import sankeyDB from './sankeyDB.js';
* @param diagObj - A standard diagram containing the db and the text and type etc of the diagram * @param diagObj - A standard diagram containing the db and the text and type etc of the diagram
*/ */
export const draw = function (text: string, id: string, _version: string, diagObj: Diagram): void { export const draw = function (text: string, id: string, _version: string, diagObj: Diagram): void {
// First of all parse sankey language // First of all parse sankey language
// Everything that is parsed will be stored in diagObj.DB // Everything that is parsed will be stored in diagObj.DB
// That is why we need to clear DB first // That is why we need to clear DB first
// //
if (typeof (diagObj?.db?.clear) !== 'undefined') { // why do we need to check for undefined? typescript complains if (diagObj?.db?.clear !== undefined) {
// why do we need to check for undefined? typescript complains
diagObj?.db?.clear(); diagObj?.db?.clear();
} }
// Launch parsing // Launch parsing
@@ -75,21 +72,17 @@ export const draw = function (text: string, id: string, _version: string, diagOb
// { "source": "Bob", "target": "Carol", "value": 43 } // { "source": "Bob", "target": "Carol", "value": 43 }
// ] // ]
// }; // };
// //
let graph = { const graph = {
"nodes": [ nodes: [{ id: 'Alice' }, { id: 'Bob' }, { id: 'Carol' }],
{ "id": "Alice" }, links: [
{ "id": "Bob" }, { source: 'Alice', target: 'Bob', value: 23 },
{ "id": "Carol" } { source: 'Bob', target: 'Carol', value: 43 },
], ],
"links": [
{ "source": "Alice", "target": "Bob", "value": 23 },
{ "source": "Bob", "target": "Carol", "value": 43 }
]
}; };
// Construct and configure a Sankey generator // Construct and configure a Sankey generator
// That will be a functino that calculates nodes and links dimentions // That will be a function that calculates nodes and links dimensions
// //
const sankey = d3sankey() const sankey = d3sankey()
.nodeId((d) => d.id) // we use 'id' property to identify node .nodeId((d) => d.id) // we use 'id' property to identify node
@@ -102,10 +95,10 @@ export const draw = function (text: string, id: string, _version: string, diagOb
// .nodePadding(10) // .nodePadding(10)
// .extent([[1, 5], [width - 1, height - 5]]); // .extent([[1, 5], [width - 1, height - 5]]);
// .nodeId(d => d['id']) // .nodeId(d => d['id'])
// //
// Compute the Sankey layout // Compute the Sankey layout
// Namely calalculate nodes and links positions // Namely calculate nodes and links positions
// Our `graph` object will be mutated by this // Our `graph` object will be mutated by this
// //
sankey(graph); sankey(graph);
@@ -125,19 +118,19 @@ export const draw = function (text: string, id: string, _version: string, diagOb
// // .attr("stroke-opacity", nodeStrokeOpacity) // // .attr("stroke-opacity", nodeStrokeOpacity)
// // .attr("stroke-linejoin", nodeStrokeLinejoin) // // .attr("stroke-linejoin", nodeStrokeLinejoin)
var color = d3scaleOrdinal(d3schemeTableau10); const color = d3scaleOrdinal(d3schemeTableau10);
// Creates the rects that represent the nodes. // Creates the rects that represent the nodes.
const rect = svg.append("g") const rect = svg
.attr("stroke", "#000") .append('g')
.selectAll("rect") .attr('stroke', '#000')
.selectAll('rect')
.data(graph.nodes) .data(graph.nodes)
.join("rect") .join('rect')
.attr("x", d => d.x0) .attr('x', (d) => d.x0)
.attr("y", d => d.y0) .attr('y', (d) => d.y0)
.attr("height", d => d.y1 - d.y0) .attr('height', (d) => d.y1 - d.y0)
.attr("width", d => d.x1 - d.x0) .attr('width', (d) => d.x1 - d.x0)
.attr("fill", d => color(d.node)); .attr('fill', (d) => color(d.node));
// // add in the links // // add in the links
// var link = svg.append("g") // var link = svg.append("g")
@@ -163,7 +156,6 @@ export const draw = function (text: string, id: string, _version: string, diagOb
// // .on("drag", dragmove)) // // .on("drag", dragmove))
// ; // ;
// // add the rectangles for the nodes // // add the rectangles for the nodes
// node // node
// .append("rect") // .append("rect")
@@ -175,7 +167,6 @@ export const draw = function (text: string, id: string, _version: string, diagOb
// .append("title") // .append("title")
// .text(function (d) { return d.name + "\n" + "There is " + d.value + " stuff in this node"; }); // .text(function (d) { return d.name + "\n" + "There is " + d.value + " stuff in this node"; });
// // add in the title for the nodes // // add in the title for the nodes
// node // node
// .append("text") // .append("text")

4
pnpm-lock.yaml generated
View File

@@ -15810,3 +15810,7 @@ packages:
/zwitch@2.0.2: /zwitch@2.0.2:
resolution: {integrity: sha512-JZxotl7SxAJH0j7dN4pxsTV6ZLXoLdGME+PsjkL/DaBrVryK9kTGq06GfKrwcSOqypP+fdXGoCHE36b99fWVoA==} resolution: {integrity: sha512-JZxotl7SxAJH0j7dN4pxsTV6ZLXoLdGME+PsjkL/DaBrVryK9kTGq06GfKrwcSOqypP+fdXGoCHE36b99fWVoA==}
dev: true dev: true
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false