Browse Source

Allow node labels to be left-justified with textAlign: 'left'

Will only apply to Network nodes with a shape: 'box' property, as most
other shapes this will not make sense for. This enables the box shape
to be used, for instance, for diagraming CFG data from source code.
codeClimate
Coleman Kane 9 years ago
parent
commit
486f89ca1b
2 changed files with 9 additions and 2 deletions
  1. +2
    -1
      lib/network/modules/NodesHandler.js
  2. +7
    -1
      lib/network/modules/components/shared/Label.js

+ 2
- 1
lib/network/modules/NodesHandler.js View File

@ -49,7 +49,8 @@ class NodesHandler {
background: 'none',
strokeWidth: 0, // px
strokeColor: '#ffffff',
align: 'horizontal'
align: 'horizontal',
textAlign: 'center'
},
group: undefined,
hidden: false,

+ 7
- 1
lib/network/modules/components/shared/Label.js View File

@ -127,7 +127,13 @@ class Label {
// configure context for drawing the text
ctx.font = (selected && this.nodeOptions.labelHighlightBold ? 'bold ' : '') + fontSize + "px " + this.fontOptions.face;
ctx.fillStyle = fontColor;
ctx.textAlign = 'center';
// When the shape is a box and the textAlign property is 'left', make label left-justified
if (this.options.shape === 'box' && this.options.font.textAlign === 'left') {
ctx.textAlign = 'left';
x = x - (this.size.wideth >> 1); // Shift label 1/2-way (>>1 == div by 2) left
} else {
ctx.textAlign = 'center';
}
// set the strokeWidth
if (this.fontOptions.strokeWidth > 0) {

Loading…
Cancel
Save