From 635d8f253512df2f82d0067f346772f5e0c14916 Mon Sep 17 00:00:00 2001 From: Hans Sponberg Date: Sun, 9 Feb 2020 14:39:36 -0800 Subject: [PATCH] allow user to change default settings --- lib/DiagramParser.js | 29 ++++++++++------------------- lib/SvgDiagramFactory.js | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/lib/DiagramParser.js b/lib/DiagramParser.js index 144e7ec..ed0eb5e 100644 --- a/lib/DiagramParser.js +++ b/lib/DiagramParser.js @@ -3,15 +3,6 @@ const InputFile = require('./InputFile') const ShapeParser = require('./ShapeParser') const Util = require('./Util') -const defaultSettings = { - 'horizontal-spacer': 20, - 'vertical-spacer': 20, - 'text-width': 5, - 'text-height': 30, - 'grid-align': 'center', - 'grid-valign': 'middle', -} - module.exports = class DiagramParser { constructor(diagramFactory) { @@ -28,18 +19,18 @@ module.exports = class DiagramParser { this.lastGridAlignment = null this.globalStyles = {} this.margin = { - left: 30, - right: 30, - top: 30, - bottom: 30 + left: this.diagramFactory.margin.left, + right: this.diagramFactory.margin.right, + top: this.diagramFactory.margin.top, + bottom: this.diagramFactory.margin.bottom } this.settings = { - 'horizontal-spacer': defaultSettings['horizontal-spacer'], - 'vertical-spacer': defaultSettings['vertical-spacer'], - 'text-width': defaultSettings['text-width'], - 'text-height': defaultSettings['text-height'], - 'grid-align': defaultSettings['grid-align'], - 'grid-valign': defaultSettings['grid-valign'], + 'horizontal-spacer': this.diagramFactory.defaultSettings['horizontal-spacer'], + 'vertical-spacer': this.diagramFactory.defaultSettings['vertical-spacer'], + 'text-width': this.diagramFactory.defaultSettings['text-width'], + 'text-height': this.diagramFactory.defaultSettings['text-height'], + 'grid-align': this.diagramFactory.defaultSettings['grid-align'], + 'grid-valign': this.diagramFactory.defaultSettings['grid-valign'], } this.debug = { showGrid: false diff --git a/lib/SvgDiagramFactory.js b/lib/SvgDiagramFactory.js index 3cc14cb..fcdb0b6 100644 --- a/lib/SvgDiagramFactory.js +++ b/lib/SvgDiagramFactory.js @@ -20,6 +20,20 @@ module.exports = class SvgDiagramFactory { this.basePath = basePath this.parsersProducersRenderers = new ParsersProducersRenderers([...builtinPaths, ...pluginPathArray]) this.convertRelativePathsToAbsolute = false + this.margin = { + left: 30, + right: 30, + top: 30, + bottom: 30 + } + this.defaultSettings = { + 'horizontal-spacer': 20, + 'vertical-spacer': 20, + 'text-width': 5, + 'text-height': 30, + 'grid-align': 'center', + 'grid-valign': 'middle', + } } getParsers() {