mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-19 15:30:03 +02:00
Fix graph width
This commit is contained in:
@@ -66,8 +66,8 @@ record
|
|||||||
const target = yy.findOrCreateNode($target.trim());
|
const target = yy.findOrCreateNode($target.trim());
|
||||||
const value = parseFloat($value.trim());
|
const value = parseFloat($value.trim());
|
||||||
$$ = yy.addLink(source,target,value);
|
$$ = yy.addLink(source,target,value);
|
||||||
} // parse only 3 fields, this is not part of standard
|
} // 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
|
| // allow empty record to handle empty lines, this is not part of CSV standard either
|
||||||
;
|
;
|
||||||
|
|
||||||
field
|
field
|
||||||
|
@@ -5,7 +5,6 @@ import { parser } from './sankey.jison';
|
|||||||
import db from '../sankeyDB.js';
|
import db from '../sankeyDB.js';
|
||||||
// import { fail } from 'assert';
|
// import { fail } from 'assert';
|
||||||
|
|
||||||
|
|
||||||
describe('Sankey diagram', function () {
|
describe('Sankey diagram', function () {
|
||||||
// TODO - these examples should be put into ./parser/stateDiagram.spec.js
|
// TODO - these examples should be put into ./parser/stateDiagram.spec.js
|
||||||
describe('when parsing an info graph it', function () {
|
describe('when parsing an info graph it', function () {
|
||||||
@@ -16,18 +15,15 @@ describe('Sankey diagram', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('parses csv', async () => {
|
it('parses csv', async () => {
|
||||||
|
|
||||||
const fs = require('fs');
|
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) => {
|
await fs.readFile(path, 'utf8', (err: Error, data: string) => {
|
||||||
if (err) throw(err);
|
if (err) throw err;
|
||||||
|
|
||||||
const str = `sankey\\n${data}`;
|
const str = `sankey\\n${data}`;
|
||||||
|
|
||||||
parser.parse(str);
|
parser.parse(str);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -88,17 +88,19 @@ export const draw = function (text: string, id: string, _version: string, diagOb
|
|||||||
|
|
||||||
const graph = diagObj.db.getGraph();
|
const graph = diagObj.db.getGraph();
|
||||||
|
|
||||||
|
const nodeWidth = 10;
|
||||||
// Construct and configure a Sankey generator
|
// Construct and configure a Sankey generator
|
||||||
// That will be a function that calculates nodes and links dimensions
|
// 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
|
||||||
.nodeWidth(10)
|
.nodeWidth(nodeWidth)
|
||||||
.nodePadding(10)
|
.nodePadding(10)
|
||||||
.nodeAlign(d3SankeyJustify) // d3.sankeyLeft, etc.
|
.nodeAlign(d3SankeyJustify) // d3.sankeyLeft, etc.
|
||||||
.size([width, height]);
|
.extent([
|
||||||
// .extent([[5, 20], [width - 5, height - 20]]); alias for size
|
[0, 0],
|
||||||
// paddings
|
[width - nodeWidth, height],
|
||||||
|
]);
|
||||||
|
|
||||||
//["left", "sankeyLeft"], ["right", "sankeyRight"], ["center", "sankeyCenter"], ["justify", "sankeyJustify"]
|
//["left", "sankeyLeft"], ["right", "sankeyRight"], ["center", "sankeyCenter"], ["justify", "sankeyJustify"]
|
||||||
// .nodeWidth(15)
|
// .nodeWidth(15)
|
||||||
@@ -169,11 +171,6 @@ export const draw = function (text: string, id: string, _version: string, diagOb
|
|||||||
.attr('d', d3SankeyLinkHorizontal())
|
.attr('d', d3SankeyLinkHorizontal())
|
||||||
.attr('stroke', (d) => color(d.source.id))
|
.attr('stroke', (d) => color(d.source.id))
|
||||||
.attr('stroke-width', (d) => Math.max(1, d.width));
|
.attr('stroke-width', (d) => Math.max(1, d.width));
|
||||||
|
|
||||||
// const { nodes, links } = generator({
|
|
||||||
// nodes: graph.nodes,
|
|
||||||
// links: graph.links,
|
|
||||||
// });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
Reference in New Issue
Block a user