Skip to content

Commit 16d64a5

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents d9b5a06 + 69cd736 commit 16d64a5

File tree

13 files changed

+449
-86
lines changed

13 files changed

+449
-86
lines changed

src/acgraph.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ goog.require('acgraph.vector.Path');
1616
goog.require('acgraph.vector.PatternFill');
1717
goog.require('acgraph.vector.Rect');
1818
goog.require('acgraph.vector.Renderer');
19+
goog.require('acgraph.vector.SimpleText');
1920
goog.require('acgraph.vector.Text');
2021
goog.require('acgraph.vector.UnmanagedLayer');
2122
goog.require('acgraph.vector.primitives');
@@ -401,6 +402,20 @@ acgraph.text = function(opt_x, opt_y, opt_text, opt_style) {
401402
};
402403

403404

405+
/**
406+
Creates, depending on the technology used, an instance of the {@link acgraph.vector.SimpleText} class.<br/>
407+
<strong>Important:</strong> When an element is created this way, a parent element is not assigned to it automatically,
408+
so it is necessary to set the parent element manually.
409+
@param {string=} opt_text The text to display.
410+
@return {!acgraph.vector.SimpleText} An instance of the {@link acgraph.vector.SimpleText} class.
411+
*/
412+
acgraph.simpleText = function(opt_text) {
413+
var text = new acgraph.vector.SimpleText();
414+
if (opt_text) text.text(opt_text);
415+
return text;
416+
};
417+
418+
404419
/**
405420
Creates an instance of the{@link acgraph.vector.HatchFill} class in case a fill with such parameters does not
406421
exist. If there is already a fill with such parameters, an instance of it is returned.<br/>

src/utils/IdGenerator.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ acgraph.utils.IdGenerator.ElementTypePrefix = {
3838
LINEAR_GRADIENT: 'linearGradient',
3939
RADIAL_GRADIENT: 'radialGradient',
4040
TEXT: 'text',
41+
SIMPLE_TEXT: 'simpleText',
4142
TEXT_SEGMENT: 'tSegment',
4243
IMAGE: 'image',
4344
CLIP: 'clip',

src/vector/Element.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,11 +1027,12 @@ acgraph.vector.Element.prototype.getTransformationMatrix = function() {
10271027
* This method must be overloaded if you need more than one DOM operation to creat a DOM element.
10281028
* Even if you only want to define which DOM must be used - you need to overload.
10291029
* {@link acgraph.vector.Element#createDomInternal}.
1030+
* @param {boolean=} opt_force .
10301031
* @protected
10311032
*/
1032-
acgraph.vector.Element.prototype.createDom = function() {
1033+
acgraph.vector.Element.prototype.createDom = function(opt_force) {
10331034
var stage = this.getStage();
1034-
if (stage && stage.acquireDomChange(acgraph.vector.Stage.DomChangeType.ELEMENT_CREATE)) {
1035+
if (stage && stage.acquireDomChange(acgraph.vector.Stage.DomChangeType.ELEMENT_CREATE) || opt_force) {
10351036
this.domElement_ = this.createDomInternal();
10361037
acgraph.register(this);
10371038
this.clearDirtyState(acgraph.vector.Element.DirtyState.DOM_MISSING);
@@ -1090,13 +1091,21 @@ acgraph.vector.Element.prototype.render = function() {
10901091
this.drag(this.draggable_);
10911092
}
10921093

1094+
this.beforeRenderInternal();
1095+
10931096
this.renderInternal();
10941097

10951098
this.isRendering_ = false;
10961099
return this;
10971100
};
10981101

10991102

1103+
/**
1104+
* Before render internal hook.
1105+
*/
1106+
acgraph.vector.Element.prototype.beforeRenderInternal = function() {};
1107+
1108+
11001109
/**
11011110
* Renders element properties supposing DOM is created.
11021111
* @protected

src/vector/Layer.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,24 @@ acgraph.vector.Layer.prototype.text = function(opt_x, opt_y, opt_text, opt_style
372372
};
373373

374374

375+
/**
376+
Invokes {@link acgraph.vector.SimpleText} class constructor.<br/>
377+
<strong>Note:</strong><br>acgraph.vector.Layer does nothing to delete an object after it is used.
378+
You need to take care of used objects yourself.
379+
@param {string=} opt_text Text to be displayed.
380+
@return {!acgraph.vector.SimpleText} {@link acgraph.vector.SimpleText} instance for method chaining.
381+
@this {acgraph.vector.ILayer}
382+
*/
383+
acgraph.vector.Layer.prototype.simpleText = function(opt_text) {
384+
/** @type {!acgraph.vector.SimpleText} */
385+
var text = acgraph.simpleText();
386+
if (opt_text) text.text(opt_text);
387+
text.parent(this);
388+
389+
return text;
390+
};
391+
392+
375393
/**
376394
Invokes {@link acgraph.vector.Text} class constructor and applies {@link acgraph.vector.Text#htmlText} method
377395
to handle HTML formatting.<br/>

src/vector/PathBase.js

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,12 @@ acgraph.vector.PathBase.prototype.moveToInternal = function(x, y) {
516516
this.arguments_.push(x, y);
517517
this.currentPoint_ = this.closePoint_ = [x, y];
518518

519-
// A flag is set, indicating that data is not synchronized
520-
this.setDirtyState(acgraph.vector.Element.DirtyState.DATA);
521-
522519
// Borders cache is not reset as there is no extension for the time being and borders do not change
523520
this.transformedPathCache_ = null;
524521

522+
// A flag is set, indicating that data is not synchronized
523+
this.setDirtyState(acgraph.vector.Element.DirtyState.DATA);
524+
525525
return this;
526526
};
527527

@@ -550,13 +550,13 @@ acgraph.vector.PathBase.prototype.lineToInternal = function(x, y, var_args) {
550550
this.count_[this.count_.length - 1] += i / 2;
551551
this.currentPoint_ = [x, y];
552552

553-
// A flag is set, indicating that data is not synchronized
554-
this.setDirtyState(acgraph.vector.Element.DirtyState.DATA);
555-
556553
// Caches are reset
557554
this.dropBoundsCache();
558555
this.transformedPathCache_ = null;
559556

557+
// A flag is set, indicating that data is not synchronized
558+
this.setDirtyState(acgraph.vector.Element.DirtyState.DATA);
559+
560560
return this;
561561
};
562562

@@ -591,13 +591,13 @@ acgraph.vector.PathBase.prototype.curveToInternal = function(control1X, control1
591591
this.count_[this.count_.length - 1] += i / 6;
592592
this.currentPoint_ = [x, y];
593593

594-
// A flag is set, indicating that data is not synchronized
595-
this.setDirtyState(acgraph.vector.Element.DirtyState.DATA);
596-
597594
// Caches are reset
598595
this.dropBoundsCache();
599596
this.transformedPathCache_ = null;
600597

598+
// A flag is set, indicating that data is not synchronized
599+
this.setDirtyState(acgraph.vector.Element.DirtyState.DATA);
600+
601601
return this;
602602
};
603603

@@ -773,13 +773,13 @@ acgraph.vector.PathBase.prototype.arcToInternal = function(rx, ry, fromAngle, ex
773773
this.simple_ = false;
774774
this.currentPoint_ = [ex, ey];
775775

776-
// A flag is set, indicating that data is not synchronized
777-
this.setDirtyState(acgraph.vector.Element.DirtyState.DATA);
778-
779776
// Caches are reset
780777
this.dropBoundsCache();
781778
this.transformedPathCache_ = null;
782779

780+
// A flag is set, indicating that data is not synchronized
781+
this.setDirtyState(acgraph.vector.Element.DirtyState.DATA);
782+
783783
return this;
784784
};
785785

@@ -803,13 +803,13 @@ acgraph.vector.PathBase.prototype.arcToAsCurvesInternal = function(rx, ry, fromA
803803

804804
this.curveToInternal.apply(this, curveParams);
805805

806-
// A flag is set, indicating that data is not synchronized
807-
this.setDirtyState(acgraph.vector.Element.DirtyState.DATA);
808-
809806
// Caches are reset
810807
this.dropBoundsCache();
811808
this.transformedPathCache_ = null;
812809

810+
// A flag is set, indicating that data is not synchronized
811+
this.setDirtyState(acgraph.vector.Element.DirtyState.DATA);
812+
813813
return this;
814814
};
815815

@@ -1045,6 +1045,23 @@ acgraph.vector.PathBase.boundsCalculationMap_ = (function() {
10451045
// Serialize
10461046
//
10471047
//----------------------------------------------------------------------------------------------------------------------
1048+
/**
1049+
* Serialize only path arguments. For copy path data purposes.
1050+
* @param {Object=} opt_data .
1051+
* @return {Object}
1052+
*/
1053+
acgraph.vector.PathBase.prototype.serializePathArgs = function(opt_data) {
1054+
var data = opt_data || {};
1055+
data['closePoint'] = this.closePoint_ ? this.closePoint_.slice() : [];
1056+
data['currentPoint'] = this.currentPoint_ ? this.currentPoint_.slice() : [];
1057+
data['segments'] = this.segments_.slice();
1058+
data['count'] = this.count_.slice();
1059+
data['arguments'] = this.arguments_.slice();
1060+
1061+
return data;
1062+
};
1063+
1064+
10481065
/** @inheritDoc */
10491066
acgraph.vector.PathBase.prototype.deserialize = function(data) {
10501067
this.closePoint_ = data['closePoint'];
@@ -1061,11 +1078,7 @@ acgraph.vector.PathBase.prototype.deserialize = function(data) {
10611078
acgraph.vector.PathBase.prototype.serialize = function() {
10621079
var data = goog.base(this, 'serialize');
10631080
data['type'] = 'path';
1064-
data['closePoint'] = this.closePoint_ ? this.closePoint_.slice() : [];
1065-
data['currentPoint'] = this.currentPoint_ ? this.currentPoint_.slice() : [];
1066-
data['segments'] = this.segments_.slice();
1067-
data['count'] = this.count_.slice();
1068-
data['arguments'] = this.arguments_.slice();
1081+
data = this.serializePathArgs(data);
10691082
return data;
10701083
};
10711084

src/vector/Renderer.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ acgraph.vector.Renderer.prototype.getEmptyStringBounds = function(style) {
6868
* Returns simple hash of a passed style object.
6969
* @param {Object} value Style object.
7070
* @return {string} Hash of a style object.
71-
* @private
7271
*/
73-
acgraph.vector.Renderer.prototype.getStyleHash_ = function(value) {
72+
acgraph.vector.Renderer.prototype.getStyleHash = function(value) {
7473
var hash = '';
7574
for (var j = 0, l = this.settingsAffectingSize.length; j < l; j++) {
7675
var prop = value[this.settingsAffectingSize[j]];
@@ -92,7 +91,7 @@ acgraph.vector.Renderer.prototype.getStyleHash_ = function(value) {
9291
*/
9392
acgraph.vector.Renderer.prototype.textBounds = function(text, style, opt_bounds) {
9493
var boundsCache = this.textBoundsCache;
95-
var styleHash = this.getStyleHash_(style);
94+
var styleHash = this.getStyleHash(style);
9695
var styleCache = boundsCache[styleHash];
9796
if (!styleCache) styleCache = boundsCache[styleHash] = {};
9897
var textBoundsCache = styleCache[text];
@@ -103,6 +102,18 @@ acgraph.vector.Renderer.prototype.textBounds = function(text, style, opt_bounds)
103102
};
104103

105104

105+
/**
106+
* Measure DOM text element.
107+
* @param {Element} element .
108+
* @param {string} text .
109+
* @param {Object} style .
110+
* @return {goog.math.Rect} .
111+
*/
112+
acgraph.vector.Renderer.prototype.getBBox = function(element, text, style) {
113+
return this.textBounds(text, style);
114+
};
115+
116+
106117
/**
107118
* Whether the cache contains bounds of passed text and style.
108119
* @param {string} text .
@@ -111,7 +122,7 @@ acgraph.vector.Renderer.prototype.textBounds = function(text, style, opt_bounds)
111122
*/
112123
acgraph.vector.Renderer.prototype.isInBoundsCache = function(text, style) {
113124
var boundsCache = this.textBoundsCache;
114-
var styleHash = this.getStyleHash_(style);
125+
var styleHash = this.getStyleHash(style);
115126
var styleCache = boundsCache[styleHash];
116127

117128
return !!(styleCache && styleCache[text]);

src/vector/Shape.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,18 @@ acgraph.vector.Shape.prototype.strokeThickness = function(opt_value) {
145145
//
146146
//----------------------------------------------------------------------------------------------------------------------
147147
/** @inheritDoc */
148-
acgraph.vector.Shape.prototype.renderInternal = function() {
148+
acgraph.vector.Shape.prototype.beforeRenderInternal = function() {
149149
if (this.boundsAffectedColors_ && this.hasDirtyState(acgraph.vector.Element.DirtyState.DATA)) {
150150
if (!!(this.boundsAffectedColors_ & 1))
151151
this.setDirtyState(acgraph.vector.Element.DirtyState.FILL);
152152
if (!!(this.boundsAffectedColors_ & 2))
153153
this.setDirtyState(acgraph.vector.Element.DirtyState.STROKE);
154154
}
155+
};
156+
155157

158+
/** @inheritDoc */
159+
acgraph.vector.Shape.prototype.renderInternal = function() {
156160
goog.base(this, 'renderInternal');
157161

158162
// Apply stroke and fill settings if they were changed

0 commit comments

Comments
 (0)