Skip to content

Commit 9d072e7

Browse files
committed
Release 1.3.4
1 parent f7fbc40 commit 9d072e7

File tree

11 files changed

+17629
-16818
lines changed

11 files changed

+17629
-16818
lines changed

dist/graphics.js

Lines changed: 16973 additions & 16231 deletions
Large diffs are not rendered by default.

dist/graphics.min.js

Lines changed: 397 additions & 384 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "graphicsjs",
33
"filename": "graphics.min.js",
4-
"version": "1.3.3",
4+
"version": "1.3.4",
55
"description": "A lightweight JavaScript graphics library with the intuitive API, based on SVG/VML technology",
66
"repository": {
77
"type": "git",

src/acgraph.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ acgraph.WRAPPER_ID_PROP_NAME_ = 'data-ac-wrapper-id';
3535

3636

3737
/**
38-
* Wrappers map.
38+
* Public Wrappers map.
3939
* @type {Object.<string, acgraph.vector.Element|acgraph.vector.Stage>}
40-
* @private
4140
*/
42-
acgraph.wrappers_ = {};
41+
acgraph.wrappers = {};
4342

4443

4544
/**
@@ -50,7 +49,7 @@ acgraph.register = function(wrapper) {
5049
var node = wrapper.domElement();
5150
if (node) {
5251
var id = String(goog.getUid(wrapper));
53-
acgraph.wrappers_[id] = wrapper;
52+
acgraph.wrappers[id] = wrapper;
5453
node.setAttribute(acgraph.WRAPPER_ID_PROP_NAME_, id);
5554
}
5655
};
@@ -61,7 +60,7 @@ acgraph.register = function(wrapper) {
6160
* @param {acgraph.vector.Element|acgraph.vector.Stage} wrapper
6261
*/
6362
acgraph.unregister = function(wrapper) {
64-
delete acgraph.wrappers_[String(goog.getUid(wrapper))];
63+
delete acgraph.wrappers[String(goog.getUid(wrapper))];
6564
var node = wrapper.domElement();
6665
if (node)
6766
node.removeAttribute(acgraph.WRAPPER_ID_PROP_NAME_);
@@ -83,7 +82,7 @@ acgraph.getWrapperForDOM = function(node, stage) {
8382
break;
8483
node = /** @type {Element} */(node.parentNode);
8584
}
86-
var res = acgraph.wrappers_[uid || ''] || null;
85+
var res = acgraph.wrappers[uid || ''] || null;
8786
return (res && res.domElement() == node) ? res : null;
8887
};
8988

@@ -533,9 +532,9 @@ acgraph.updateReferences = function() {
533532
var wrapper;
534533
var renderer = acgraph.getRenderer();
535534

536-
for (var id in acgraph.wrappers_) {
537-
if (!acgraph.wrappers_.hasOwnProperty(id)) continue;
538-
wrapper = acgraph.wrappers_[id];
535+
for (var id in acgraph.wrappers) {
536+
if (!acgraph.wrappers.hasOwnProperty(id)) continue;
537+
wrapper = acgraph.wrappers[id];
539538
var wrapperStage = wrapper.getStage();
540539
if (!wrapperStage) continue;
541540

src/math.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -436,25 +436,36 @@ acgraph.math.fitWithProportion = function(targetWidth, targetHeight, sourceWidth
436436
//
437437
//------------------------------------------------------------------------------
438438
/**
439-
Getter for the X-coordinate.
440-
@this {goog.math.Coordinate}
441-
@return {number} X-coordinate.
439+
* Getter for the X-coordinate.
440+
* @this {goog.math.Coordinate}
441+
* @return {number} X-coordinate.
442442
*/
443443
goog.math.Coordinate.prototype.getX = function() {
444444
return this.x;
445445
};
446446

447447

448448
/**
449-
Getter for the Y-coordinate.
450-
@this {goog.math.Coordinate}
451-
@return {number} The Y-coordinate.
449+
* Getter for the Y-coordinate.
450+
* @this {goog.math.Coordinate}
451+
* @return {number} The Y-coordinate.
452452
*/
453453
goog.math.Coordinate.prototype.getY = function() {
454454
return this.y;
455455
};
456456

457457

458+
/**
459+
* Coordinate constructor method.
460+
* @param {number=} opt_x Left, defaults to 0.
461+
* @param {number=} opt_y Top, defaults to 0.
462+
* @return {goog.math.Coordinate}
463+
*/
464+
acgraph.math.coordinate = function(opt_x, opt_y) {
465+
return new goog.math.Coordinate(opt_x, opt_y);
466+
};
467+
468+
458469
//endregion
459470
//region --- Rect
460471
//------------------------------------------------------------------------------
@@ -522,6 +533,19 @@ goog.math.Rect.prototype.getBottom = function() {
522533
};
523534

524535

536+
/**
537+
* Rect constructor method.
538+
* @param {number} x Left.
539+
* @param {number} y Top.
540+
* @param {number} w Width.
541+
* @param {number} h Height.
542+
* @return {goog.math.Rect}
543+
*/
544+
acgraph.math.rect = function(x, y, w, h) {
545+
return new goog.math.Rect(x, y, w, h);
546+
};
547+
548+
525549
//endregion
526550
//region --- Size
527551
//------------------------------------------------------------------------------
@@ -552,9 +576,10 @@ goog.math.Size.prototype.getHeight = function() {
552576
//endregion
553577
//exports
554578
(function() {
555-
goog.exportSymbol('acgraph.math.Coordinate', goog.math.Coordinate);
556-
goog.exportSymbol('acgraph.math.Rect', goog.math.Rect);
557579
goog.exportSymbol('acgraph.math.Size', goog.math.Size);
580+
goog.exportSymbol('acgraph.math.coordinate', acgraph.math.coordinate);
581+
goog.exportSymbol('acgraph.math.rect', acgraph.math.rect);
582+
goog.exportSymbol('acgraph.math.Rect', goog.math.Rect);
558583
var proto = goog.math.Coordinate.prototype;
559584
proto['getX'] = proto.getX;
560585
proto['getY'] = proto.getY;

src/utils/HTMLParser.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,9 @@ acgraph.utils.HTMLParser.prototype.parseText = function(textElem) {
768768

769769
var isNotLetterOrDigit = /(_|\W)/.test(symbol); //Whether current symbol is not letter and not digit.
770770
if (isNotLetterOrDigit) {
771-
var nextState = (symbol == '<') ? s.READ_TAG : s.READ_TEXT;
772-
this.finalizeEntity_(nextState, symbol);
771+
var openTag = symbol == '<';
772+
var nextState = openTag ? s.READ_TAG : s.READ_TEXT;
773+
this.finalizeEntity_(nextState, openTag ? '' : symbol);
773774
break;
774775
}
775776

src/vector/Shape.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ goog.require('goog.math.Rect');
1515
acgraph.vector.Shape = function() {
1616
/**
1717
* Fill settings object.
18-
* @type {acgraph.vector.Fill}
18+
* Null value means that fill will not be rendered.
19+
* @type {?acgraph.vector.Fill}
1920
* @private
2021
*/
2122
this.fill_ = 'none';
2223

2324
/**
2425
* Stroke settings object.
25-
* @type {acgraph.vector.Stroke}
26+
* Null value means that fill will not be rendered.
27+
* @type {?acgraph.vector.Stroke}
2628
* @private
2729
*/
2830
this.stroke_ = 'black';
@@ -65,7 +67,7 @@ acgraph.vector.Shape.prototype.SUPPORTED_DIRTY_STATES =
6567
@param {number=} opt_opacity .
6668
@param {number=} opt_fx .
6769
@param {number=} opt_fy .
68-
@return {!(acgraph.vector.Fill|acgraph.vector.Shape)} .
70+
@return {(acgraph.vector.Fill|acgraph.vector.Shape|null)} .
6971
*/
7072
acgraph.vector.Shape.prototype.fill = function(opt_fillOrColorOrKeys, opt_opacityOrAngleOrCx, opt_modeOrCy, opt_opacityOrMode,
7173
opt_opacity, opt_fx, opt_fy) {
@@ -95,7 +97,7 @@ acgraph.vector.Shape.prototype.fill = function(opt_fillOrColorOrKeys, opt_opacit
9597
@param {string=} opt_dashpattern .
9698
@param {acgraph.vector.StrokeLineJoin=} opt_lineJoin .
9799
@param {acgraph.vector.StrokeLineCap=} opt_lineCap .
98-
@return {(!acgraph.vector.Shape|acgraph.vector.Stroke)} .
100+
@return {(acgraph.vector.Shape|acgraph.vector.Stroke|null)} .
99101
*/
100102
acgraph.vector.Shape.prototype.stroke = function(opt_strokeOrFill, opt_thickness, opt_dashpattern, opt_lineJoin, opt_lineCap) {
101103
if (!goog.isDef(opt_strokeOrFill))
@@ -113,6 +115,19 @@ acgraph.vector.Shape.prototype.stroke = function(opt_strokeOrFill, opt_thickness
113115
};
114116

115117

118+
/**
119+
* Adds possibility to nullify fill and stroke for alternative coloring
120+
* like text color since text becomes the shape (DVF-3872).
121+
* Null value prevents fill/stroke attribute rendering.
122+
*
123+
* DEV NOTE: Do not abuse this method because it sets no dirty state.
124+
*/
125+
acgraph.vector.Shape.prototype.setNullFillAndStroke = function() {
126+
this.fill_ = null;
127+
this.stroke_ = null;
128+
};
129+
130+
116131
/**
117132
Gets/sets stroke thickness.
118133
@param {number=} opt_value Thickness value.

src/vector/Stage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2197,7 +2197,8 @@ acgraph.vector.Stage.prototype.disposeInternal = function() {
21972197
delete this.internalContainer_;
21982198
this.domElement_ = null;
21992199

2200-
acgraph.getRenderer().disposeMeasurement();
2200+
if (goog.object.isEmpty(acgraph.wrappers))
2201+
acgraph.getRenderer().disposeMeasurement();
22012202

22022203
if (this.credits_) {
22032204
this.credits_.dispose();

src/vector/Text.js

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ goog.provide('acgraph.vector.Text.TextOverflow');
33

44
goog.require('acgraph.utils.HTMLParser');
55
goog.require('acgraph.utils.IdGenerator');
6-
goog.require('acgraph.vector.Element');
6+
goog.require('acgraph.vector.Shape');
77
goog.require('acgraph.vector.TextSegment');
88
goog.require('goog.math.Rect');
99

@@ -21,7 +21,7 @@ goog.require('goog.math.Rect');
2121
@param {number=} opt_x Coordinate X (Left) of left top corner of text bounds.
2222
@param {number=} opt_y Coordinate Y (Top) of left top corner of text bounds.
2323
@constructor
24-
@extends {acgraph.vector.Element}
24+
@extends {acgraph.vector.Shape}
2525
*/
2626
acgraph.vector.Text = function(opt_x, opt_y) {
2727

@@ -218,8 +218,9 @@ acgraph.vector.Text = function(opt_x, opt_y) {
218218
this.textPath = null;
219219

220220
goog.base(this);
221+
this.setNullFillAndStroke();
221222
};
222-
goog.inherits(acgraph.vector.Text, acgraph.vector.Element);
223+
goog.inherits(acgraph.vector.Text, acgraph.vector.Shape);
223224

224225

225226
//----------------------------------------------------------------------------------------------------------------------
@@ -419,7 +420,7 @@ acgraph.vector.Text.Direction = {
419420
* @type {number}
420421
*/
421422
acgraph.vector.Text.prototype.SUPPORTED_DIRTY_STATES =
422-
acgraph.vector.Element.prototype.SUPPORTED_DIRTY_STATES |
423+
acgraph.vector.Shape.prototype.SUPPORTED_DIRTY_STATES |
423424
acgraph.vector.Element.DirtyState.DATA |
424425
acgraph.vector.Element.DirtyState.STYLE |
425426
acgraph.vector.Element.DirtyState.POSITION |
@@ -1690,41 +1691,42 @@ acgraph.vector.Text.prototype.textDefragmentation = function() {
16901691
this.text_ = goog.string.canonicalizeNewlines(goog.string.normalizeSpaces(this.text_));
16911692
var textArr = this.text_.split(q);
16921693

1693-
if (textArr.length == 1 && !goog.isDef(this.style_['width']) && !this.path()) {
1694-
if (!this.domElement()) {
1695-
this.createDom(true);
1696-
}
1697-
if (this.hasDirtyState(acgraph.vector.Element.DirtyState.STYLE))
1698-
this.renderStyle();
1699-
1700-
segment = new acgraph.vector.TextSegment(this.text_, {});
1701-
this.currentLine_.push(segment);
1702-
this.segments_.push(segment);
1703-
segment.parent(this);
1704-
1705-
if (this.hasDirtyState(acgraph.vector.Element.DirtyState.DATA))
1706-
this.renderData();
1707-
1708-
var bounds = acgraph.getRenderer().getBBox(this.domElement(), this.text_, this.style_);
1709-
1710-
segment.baseLine = -bounds.top;
1711-
segment.height = bounds.height;
1712-
segment.width = bounds.width;
1713-
1714-
// calculate line params with newly added segment.
1715-
this.currentLineHeight_ = bounds.height;
1716-
this.currentLineWidth_ = bounds.width + this.textIndent_;
1717-
this.currentBaseLine_ = segment.baseLine;
1718-
this.currentLineEmpty_ = this.text_.length == 0;
1719-
1720-
this.finalizeTextLine();
1721-
this.currentNumberSeqBreaks_++;
1722-
var height = this.currentLine_[0] ? this.currentLine_[0].height : 0;
1723-
this.accumulatedHeight_ += goog.isString(this.lineHeight_) ?
1724-
parseInt(this.lineHeight_, 0) + height :
1725-
this.lineHeight_ * height;
1726-
1727-
} else {
1694+
// if (textArr.length == 1 && !goog.isDefAndNotNull(this.style_['width']) && !this.path()) {
1695+
// if (!this.domElement()) {
1696+
// this.createDom(true);
1697+
// }
1698+
//
1699+
// if (this.hasDirtyState(acgraph.vector.Element.DirtyState.STYLE))
1700+
// this.renderStyle();
1701+
//
1702+
// if (this.hasDirtyState(acgraph.vector.Element.DirtyState.DATA)) {
1703+
// segment = new acgraph.vector.TextSegment(this.text_, {});
1704+
// this.currentLine_.push(segment);
1705+
// this.segments_.push(segment);
1706+
// segment.parent(this);
1707+
//
1708+
// this.renderData();
1709+
// }
1710+
//
1711+
// var bounds = acgraph.getRenderer().getBBox(this.domElement(), this.text_, this.style_);
1712+
//
1713+
// segment.baseLine = -bounds.top;
1714+
// segment.height = bounds.height;
1715+
// segment.width = bounds.width;
1716+
//
1717+
// // calculate line params with newly added segment.
1718+
// this.currentLineHeight_ = bounds.height;
1719+
// this.currentLineWidth_ = bounds.width + this.textIndent_;
1720+
// this.currentBaseLine_ = segment.baseLine;
1721+
// this.currentLineEmpty_ = this.text_.length == 0;
1722+
//
1723+
// this.finalizeTextLine();
1724+
// this.currentNumberSeqBreaks_++;
1725+
// var height = this.currentLine_[0] ? this.currentLine_[0].height : 0;
1726+
// this.accumulatedHeight_ += goog.isString(this.lineHeight_) ?
1727+
// parseInt(this.lineHeight_, 0) + height :
1728+
// this.lineHeight_ * height;
1729+
// } else {
17281730
for (i = 0; i < textArr.length; i++) {
17291731
text = goog.string.trimLeft(textArr[i]);
17301732
if (goog.isDefAndNotNull(text)) {
@@ -1736,7 +1738,7 @@ acgraph.vector.Text.prototype.textDefragmentation = function() {
17361738
}
17371739
}
17381740
}
1739-
}
1741+
// }
17401742
}
17411743

17421744
if (this.textIndent_ && this.textLines_.length > 0) {

0 commit comments

Comments
 (0)