Fix graph width

This commit is contained in:
Nikolay Rozhkov
2023-06-21 01:48:48 +03:00
parent 362648b74b
commit 6c6efb24f4
3 changed files with 12 additions and 19 deletions

View File

@@ -66,8 +66,8 @@ record
const target = yy.findOrCreateNode($target.trim());
const value = parseFloat($value.trim());
$$ = yy.addLink(source,target,value);
} // parse only 3 fields, this is not part of standard
| // allow empty record to handle empty lines, this is not part of csv standard either
} // parse only 3 fields, this is not part of CSV standard
| // allow empty record to handle empty lines, this is not part of CSV standard either
;
field

View File

@@ -5,7 +5,6 @@ import { parser } from './sankey.jison';
import db from '../sankeyDB.js';
// import { fail } from 'assert';
describe('Sankey diagram', function () {
// TODO - these examples should be put into ./parser/stateDiagram.spec.js
describe('when parsing an info graph it', function () {
@@ -14,20 +13,17 @@ describe('Sankey diagram', function () {
diagram.parser.yy = db;
diagram.parser.yy.clear();
});
it('parses csv', async () => {
const fs = require('fs');
const path = require('path').resolve(__dirname, "./energy.csv");
const path = require('path').resolve(__dirname, './energy.csv');
await fs.readFile(path, 'utf8', (err: Error, data: string) => {
if (err) throw(err);
if (err) throw err;
const str = `sankey\\n${data}`;
parser.parse(str);
});
});
});
});

View File

@@ -88,17 +88,19 @@ export const draw = function (text: string, id: string, _version: string, diagOb
const graph = diagObj.db.getGraph();
const nodeWidth = 10;
// Construct and configure a Sankey generator
// That will be a function that calculates nodes and links dimensions
//
const sankey = d3Sankey()
.nodeId((d) => d.id) // we use 'id' property to identify node
.nodeWidth(10)
.nodeWidth(nodeWidth)
.nodePadding(10)
.nodeAlign(d3SankeyJustify) // d3.sankeyLeft, etc.
.size([width, height]);
// .extent([[5, 20], [width - 5, height - 20]]); alias for size
// paddings
.extent([
[0, 0],
[width - nodeWidth, height],
]);
//["left", "sankeyLeft"], ["right", "sankeyRight"], ["center", "sankeyCenter"], ["justify", "sankeyJustify"]
// .nodeWidth(15)
@@ -169,11 +171,6 @@ export const draw = function (text: string, id: string, _version: string, diagOb
.attr('d', d3SankeyLinkHorizontal())
.attr('stroke', (d) => color(d.source.id))
.attr('stroke-width', (d) => Math.max(1, d.width));
// const { nodes, links } = generator({
// nodes: graph.nodes,
// links: graph.links,
// });
};
export default {