Skip to content

Commit 276c4d8

Browse files
blackartgrasshoppergn
authored andcommitted
DVF-1905 Simple Text added for TagCloud
1 parent 75678bf commit 276c4d8

File tree

5 files changed

+170
-0
lines changed

5 files changed

+170
-0
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/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/SimpleText.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
goog.provide('acgraph.vector.SimpleText');
2+
3+
goog.require('acgraph.utils.IdGenerator');
4+
goog.require('acgraph.vector.Element');
5+
goog.require('goog.math.Rect');
6+
7+
8+
9+
/**
10+
Text class.<br>
11+
<b>Do not invoke constructor directly.</b> Use {@link acgraph.vector.Stage#text} or
12+
{@link acgraph.vector.Layer#text} to create layer or stage bound text.
13+
<br/> Use {@link acgraph.text} to create unbound text.
14+
@see acgraph.vector.Stage#text
15+
@see acgraph.vector.Layer#text
16+
@see acgraph.text
17+
@name acgraph.vector.SimpleText
18+
@constructor
19+
@extends {acgraph.vector.Element}
20+
*/
21+
acgraph.vector.SimpleText = function() {
22+
/**
23+
* Element bounds.
24+
* acgraph.vector.Element.DirtyState.DATA must be set with any changes.
25+
* @type {goog.math.Rect}
26+
* @protected
27+
*/
28+
this.bounds = new goog.math.Rect(0, 0, 0, 0);
29+
30+
goog.base(this);
31+
};
32+
goog.inherits(acgraph.vector.SimpleText, acgraph.vector.Element);
33+
34+
35+
/**
36+
* Text.
37+
* @type {?string}
38+
* @private
39+
*/
40+
acgraph.vector.SimpleText.prototype.text_ = null;
41+
42+
43+
/**
44+
* Supported states. Inherited from Element and text data added.
45+
* @type {number}
46+
*/
47+
acgraph.vector.SimpleText.prototype.SUPPORTED_DIRTY_STATES =
48+
acgraph.vector.Element.prototype.SUPPORTED_DIRTY_STATES |
49+
acgraph.vector.Element.DirtyState.DATA;
50+
51+
52+
/** @inheritDoc */
53+
acgraph.vector.SimpleText.prototype.getElementTypePrefix = function() {
54+
return acgraph.utils.IdGenerator.ElementTypePrefix.SIMPLE_TEXT;
55+
};
56+
57+
58+
/** @inheritDoc */
59+
acgraph.vector.SimpleText.prototype.getBoundsWithoutTransform = function() {
60+
return this.bounds.clone();
61+
};
62+
63+
64+
/** @inheritDoc */
65+
acgraph.vector.SimpleText.prototype.getBoundsWithTransform = acgraph.vector.SimpleText.prototype.getBoundsWithoutTransform;
66+
67+
68+
/**
69+
Get current text.
70+
@param {string=} opt_value .
71+
@return {string|acgraph.vector.SimpleText} .
72+
*/
73+
acgraph.vector.SimpleText.prototype.text = function(opt_value) {
74+
if (goog.isDef(opt_value)) {
75+
if (opt_value != this.text_) {
76+
this.text_ = String(opt_value);
77+
var stageSuspended = !this.getStage() || this.getStage().isSuspended();
78+
if (!stageSuspended) this.getStage().suspend();
79+
this.setDirtyState(acgraph.vector.Element.DirtyState.DATA);
80+
if (!stageSuspended) this.getStage().resume();
81+
}
82+
return this;
83+
}
84+
return this.text_;
85+
};
86+
87+
88+
//----------------------------------------------------------------------------------------------------------------------
89+
//
90+
// DOM element creation
91+
//
92+
//----------------------------------------------------------------------------------------------------------------------
93+
/** @inheritDoc */
94+
acgraph.vector.SimpleText.prototype.createDomInternal = function() {
95+
return acgraph.getRenderer().createTextElement();
96+
};
97+
98+
99+
/** @inheritDoc */
100+
acgraph.vector.SimpleText.prototype.renderInternal = function() {
101+
if (this.hasDirtyState(acgraph.vector.Element.DirtyState.DATA)) {
102+
acgraph.getRenderer().setTextData(this);
103+
this.clearDirtyState(acgraph.vector.Element.DirtyState.DATA);
104+
}
105+
106+
goog.base(this, 'renderInternal');
107+
};
108+
109+
110+
/** @inheritDoc */
111+
acgraph.vector.SimpleText.prototype.renderTransformation = function() {
112+
this.clearDirtyState(acgraph.vector.Element.DirtyState.TRANSFORMATION);
113+
this.clearDirtyState(acgraph.vector.Element.DirtyState.PARENT_TRANSFORMATION);
114+
};
115+
116+
117+
//exports
118+
(function() {
119+
var proto = acgraph.vector.SimpleText.prototype;
120+
proto['text'] = proto.text;
121+
goog.exportSymbol('acgraph.vector.SimpleText', acgraph.vector.SimpleText);
122+
})();

src/vector/svg/Renderer.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,20 @@ acgraph.vector.svg.Renderer.prototype.setTextPosition = function(element) {
672672
};
673673

674674

675+
/**
676+
* Sets data for simple text.
677+
* @param {acgraph.vector.SimpleText} element .
678+
*/
679+
acgraph.vector.svg.Renderer.prototype.setTextData = function(element) {
680+
// var tspan = this.createTextSegmentElement();
681+
// var textNode = this.createTextNode(element.text());
682+
//
683+
// tspan.appendChild(textNode);
684+
// element.domElement().appendChild(tspan);
685+
element.domElement().textContent = element.text();
686+
};
687+
688+
675689
/** @inheritDoc */
676690
acgraph.vector.svg.Renderer.prototype.setTextProperties = function(element) {
677691
var style = element.style();

0 commit comments

Comments
 (0)