Skip to content

Commit

Permalink
add class Line and LineEnd
Browse files Browse the repository at this point in the history
  • Loading branch information
pointworld committed Oct 15, 2018
1 parent b005b08 commit d350a98
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 66 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
Note:
> Note:
- The first version of this project is almost based on [jTopo(v0.4.8)](http://www.jtopo.com/) or [jTopo(v0.4.8)](http://www.jtopo.cn/).
- The first version of pTopo is based on ES6.
- Sincere thanks to the contributions of the author(jTopo).
---

# pTopo
62 changes: 29 additions & 33 deletions dist/pTopo.js
Original file line number Diff line number Diff line change
Expand Up @@ -1400,45 +1400,41 @@
function (_InteractiveElement) {
_inherits(Link, _InteractiveElement);

function Link(nodeA, nodeZ, text) {
function Link(nodeA, nodeZ, text, opts) {
var _this;

_classCallCheck(this, Link);

_this = _possibleConstructorReturn(this, _getPrototypeOf(Link).call(this, nodeA, nodeZ, text));
_this = _possibleConstructorReturn(this, _getPrototypeOf(Link).call(this, nodeA, nodeZ, text, opts));
_this.elementType = "link";
_this.zIndex = zIndex_Link;

if (arguments.length) {
_this.text = text;
_this.nodeA = nodeA;
_this.nodeA && !_this.nodeA.inLinks && (_this.nodeA.inLinks = []);
_this.nodeA && !_this.nodeA.outLinks && (_this.nodeA.outLinks = []);
_this.nodeA && _this.nodeA.outLinks.push(_assertThisInitialized(_assertThisInitialized(_this)));
_this.nodeZ = nodeZ;
_this.nodeZ && !_this.nodeZ.inLinks && (_this.nodeZ.inLinks = []);
_this.nodeZ && !_this.nodeZ.outLinks && (_this.nodeZ.outLinks = []);
_this.nodeZ && _this.nodeZ.inLinks.push(_assertThisInitialized(_assertThisInitialized(_this)));

_this.caculateIndex();

_this.font = "12px Consolas";
_this.fontColor = "255,255,255";
_this.lineWidth = 2;
_this.lineJoin = "miter";
_this.transformAble = false;
_this.bundleOffset = 20;
_this.bundleGap = 12;
_this.textOffsetX = 0;
_this.textOffsetY = 0;
_this.arrowsRadius = null;
_this.arrowsOffset = 0;
_this.dashedPattern = null;
_this.path = [];
var keysArr = "text,font,fontColor,lineWidth,lineJoin".split(",");
_this.serializedProperties = _this.serializedProperties.concat(keysArr);
}

_this.text = text;
_this.nodeA = nodeA;
_this.nodeA && !_this.nodeA.inLinks && (_this.nodeA.inLinks = []);
_this.nodeA && !_this.nodeA.outLinks && (_this.nodeA.outLinks = []);
_this.nodeA && _this.nodeA.outLinks.push(_assertThisInitialized(_assertThisInitialized(_this)));
_this.nodeZ = nodeZ;
_this.nodeZ && !_this.nodeZ.inLinks && (_this.nodeZ.inLinks = []);
_this.nodeZ && !_this.nodeZ.outLinks && (_this.nodeZ.outLinks = []);
_this.nodeZ && _this.nodeZ.inLinks.push(_assertThisInitialized(_assertThisInitialized(_this)));

_this.caculateIndex();

_this.font = opts.font || "12px Consolas";
_this.fontColor = opts.fontColor || "255,255,255";
_this.lineWidth = opts.lineWidth || 2;
_this.lineJoin = opts.lineJoin || "miter";
_this.transformAble = false;
_this.bundleOffset = opts.bundleOffset || 20;
_this.bundleGap = opts.bundleGap || 12;
_this.textOffsetX = opts.textOffsetX || 0;
_this.textOffsetY = opts.textOffsetY || 0;
_this.arrowsRadius = opts.arrowsRadius || null;
_this.arrowsOffset = opts.arrowsOffset || 0;
_this.dashedPattern = opts.dashedPattern || null;
_this.path = opts.path || [];
var keysArr = "text,font,fontColor,lineWidth,lineJoin".split(",");
_this.serializedProperties = _this.serializedProperties.concat(keysArr);
return _this;
}

Expand Down
15 changes: 15 additions & 0 deletions src/core/link/Line.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default class Line {
constructor (opts) {
// dashed, curve, fold, straight, parabola ...
this.lineType = opts.lineType || 'default'
this.lineStyle = opts.lineStyle || ''
this.lineWidth = opts.lineWidth || 2
this.lineColor = opts.lineColor || '0,0,0'
this.lineDirection = opts.lineDirection || 'horizontal'
this.linePaths = opts.linePaths || []
this.lineFn = opts.lineFn || null

}

paintLine(ctx) {}
}
58 changes: 28 additions & 30 deletions src/core/link/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,38 @@ import {getIntersectionPointObj, unsharedLinks, getSharedLinksLen} from './util'
import {zIndex_Link} from "../../shared/constants"

export default class Link extends InteractiveElement {
constructor(nodeA, nodeZ, text) {
super(nodeA, nodeZ, text)
constructor(nodeA, nodeZ, text, opts) {
super(nodeA, nodeZ, text, opts)

this.elementType = "link"
this.zIndex = zIndex_Link
this.text = text
this.nodeA = nodeA
this.nodeA && !this.nodeA.inLinks && (this.nodeA.inLinks = [])
this.nodeA && !this.nodeA.outLinks && (this.nodeA.outLinks = [])
this.nodeA && this.nodeA.outLinks.push(this)
this.nodeZ = nodeZ
this.nodeZ && !this.nodeZ.inLinks && (this.nodeZ.inLinks = [])
this.nodeZ && !this.nodeZ.outLinks && (this.nodeZ.outLinks = [])
this.nodeZ && this.nodeZ.inLinks.push(this)
this.caculateIndex()
this.font = opts.font || "12px Consolas"
this.fontColor = opts.fontColor || "255,255,255"
this.lineWidth = opts.lineWidth || 2
this.lineJoin = opts.lineJoin || "miter"
this.transformAble = false
this.bundleOffset = opts.bundleOffset || 20
this.bundleGap = opts.bundleGap || 12
this.textOffsetX = opts.textOffsetX || 0
this.textOffsetY = opts.textOffsetY || 0
this.arrowsRadius = opts.arrowsRadius || null
this.arrowsOffset = opts.arrowsOffset || 0
this.dashedPattern = opts.dashedPattern || null
this.path = opts.path || []

const keysArr = "text,font,fontColor,lineWidth,lineJoin".split(",")
this.serializedProperties = this.serializedProperties.concat(keysArr)

if (arguments.length) {
this.text = text
this.nodeA = nodeA
this.nodeA && !this.nodeA.inLinks && (this.nodeA.inLinks = [])
this.nodeA && !this.nodeA.outLinks && (this.nodeA.outLinks = [])
this.nodeA && this.nodeA.outLinks.push(this)
this.nodeZ = nodeZ
this.nodeZ && !this.nodeZ.inLinks && (this.nodeZ.inLinks = [])
this.nodeZ && !this.nodeZ.outLinks && (this.nodeZ.outLinks = [])
this.nodeZ && this.nodeZ.inLinks.push(this)
this.caculateIndex()
this.font = "12px Consolas"
this.fontColor = "255,255,255"
this.lineWidth = 2
this.lineJoin = "miter"
this.transformAble = false
this.bundleOffset = 20
this.bundleGap = 12
this.textOffsetX = 0
this.textOffsetY = 0
this.arrowsRadius = null
this.arrowsOffset = 0
this.dashedPattern = null
this.path = []

const keysArr = "text,font,fontColor,lineWidth,lineJoin".split(",")
this.serializedProperties = this.serializedProperties.concat(keysArr)
}
}

caculateIndex() {
Expand Down
31 changes: 31 additions & 0 deletions src/core/link/LinkEnd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export default class LinKEnd {
constructor (opts) {
// default, arrow, circle, triangle, user-defined, ...
this.linkEndType = opts.linkEndType || 'default'
this.linkEndStyle = opts.linkEndStyle || ''
this.linkEndColor = opts.linkEndColor || ''
this.linkEndWidth = opts.linkEndWidth || ''
this.linkEndColor = opts.linkEndColor || ''
}

paintLinkEnd(ctx) {
switch (this.linkEndType) {
case 'arrow':
this.paintArrow(ctx)
break
case 'circle':
this.paintCircle(ctx)
break
case 'triangle':
this.paintTriangle(ctx)
break
default:
}
}

paintArrow(ctx) {}

paintCircle(ctx) {}

paintTriangle(ctx) {}
}

0 comments on commit d350a98

Please sign in to comment.