Skip to content

Commit e3f02c4

Browse files
committed
DVF-3144 export server
1 parent e36af2c commit e3f02c4

File tree

5 files changed

+77
-9
lines changed

5 files changed

+77
-9
lines changed

src/acgraph.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,29 @@ acgraph.getRenderer = function() {
190190
* all supported technologies.
191191
*/
192192
acgraph.create = function(opt_container, opt_width, opt_height) {
193+
var stage;
193194
if (acgraph.type_ == acgraph.StageType.VML) {
194195
var vml = goog.global['acgraph']['vml'];
195196
if (vml) {
196-
return new vml['Stage'](opt_container, opt_width, opt_height);
197+
stage = new vml['Stage'](opt_container, opt_width, opt_height);
197198
} else {
198199
throw Error('VML module should be included to render AnyChart in IE8-');
199200
}
200201
} else {
201-
return new acgraph.vector.svg.Stage(opt_container, opt_width, opt_height);
202+
stage = new acgraph.vector.svg.Stage(opt_container, opt_width, opt_height);
202203
}
204+
205+
return stage;
206+
};
207+
208+
209+
/**
210+
* Retruns stage by id.
211+
* @param {string} id .
212+
* @return {acgraph.vector.Stage}
213+
*/
214+
acgraph.getStage = function(id) {
215+
return goog.global['acgraph'].stages[id];
203216
};
204217

205218

@@ -503,7 +516,7 @@ acgraph.getReference = function() {
503516

504517
return acgraph.getReferenceValue_ = acgraph.compatibility.USE_ABSOLUTE_REFERENCES ||
505518
(goog.isNull(acgraph.compatibility.USE_ABSOLUTE_REFERENCES) && goog.dom.getElementsByTagNameAndClass('base').length) ?
506-
window.location.origin + window.location.pathname + window.location.search :
519+
goog.global.location.origin + goog.global.location.pathname + goog.global.location.search :
507520
'';
508521
};
509522

@@ -550,6 +563,7 @@ acgraph.updateReferences = function() {
550563
//exports
551564
(function() {
552565
goog.exportSymbol('acgraph.create', acgraph.create);
566+
goog.exportSymbol('acgraph.getStage', acgraph.getStage);
553567
goog.exportSymbol('acgraph.type', acgraph.type);
554568
goog.exportSymbol('acgraph.rect', acgraph.rect);
555569
goog.exportSymbol('acgraph.circle', acgraph.circle);

src/utils/exporting.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ acgraph.utils.exporting.openPrint_ = function() {
229229
//end listening onBefore/onAfterPrint events
230230

231231
if (goog.userAgent.EDGE) {
232-
acgraph.utils.exporting.printWindow_ = window.open();
232+
acgraph.utils.exporting.printWindow_ = goog.global.open();
233233
acgraph.utils.exporting.printWindow_.document.write(iFrameWindow.document.documentElement.innerHTML);
234234
acgraph.utils.exporting.disposePrint_();
235235
acgraph.utils.exporting.printWindow_['onafterprint'] = function() {

src/utils/utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,11 @@ acgraph.utils.partialApplyingArgsToFunction = function(func, args, opt_obj) {
6767
};
6868

6969

70+
/**
71+
* Define whether value is set in percent.
72+
* @param {*} value Value to define.
73+
* @return {boolean} Is value set in percent.
74+
*/
75+
acgraph.utils.isPercent = function(value) {
76+
return goog.isString(value) && goog.string.endsWith(value, '%') && !isNaN(parseFloat(value));
77+
};

src/vector/Stage.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ acgraph.vector.Stage = function(opt_container, opt_width, opt_height) {
6060

6161
this.renderAsync_ = goog.bind(this.renderAsync_, this);
6262
this.checkSize = goog.bind(this.checkSize, this);
63+
var doc = goog.global['document'];
64+
65+
if (!goog.global['acgraph'].stages)
66+
goog.global['acgraph'].stages = {};
67+
68+
var id = acgraph.utils.IdGenerator.getInstance().identify(this, acgraph.utils.IdGenerator.ElementTypePrefix.STAGE);
69+
goog.global['acgraph'].stages[id] = this;
70+
71+
this.charts = {};
6372

6473
/**
6574
* Event handler of the stage.
@@ -73,7 +82,9 @@ acgraph.vector.Stage = function(opt_container, opt_width, opt_height) {
7382
* @type {!Element}
7483
* @private
7584
*/
76-
this.internalContainer_ = goog.dom.createDom(goog.dom.TagName.DIV, {style: 'position:relative;left:0;top:0;overflow:hidden;'});
85+
// this.internalContainer_ = goog.dom.createDom(goog.dom.TagName.DIV, {style: 'position:relative;left:0;top:0;overflow:hidden;'});
86+
this.internalContainer_ = doc.createElement(goog.dom.TagName.DIV);
87+
goog.style.setStyle(this.internalContainer_, {'position': 'relative', 'left': 0, 'top': 0, 'overflow': 'hidden'});
7788

7889
/**
7990
* Root DOM element of stage object.
@@ -90,6 +101,8 @@ acgraph.vector.Stage = function(opt_container, opt_width, opt_height) {
90101
// Add class for check anychart-ui.css attached. (DVF-1619)
91102
goog.dom.classlist.add(this.domElement_, 'anychart-ui-support');
92103
goog.dom.appendChild(this.internalContainer_, this.domElement_);
104+
this.domElement_.setAttribute('ac-id', id);
105+
93106

94107
/**
95108
* Array of clips that should be rendered when stage is rendering.
@@ -137,7 +150,8 @@ acgraph.vector.Stage = function(opt_container, opt_width, opt_height) {
137150

138151
this.setWidth_(opt_width || '100%');
139152
this.setHeight_(opt_height || '100%');
140-
this.container_ = goog.dom.getElement(opt_container || null);
153+
this.container_ = goog.isString(opt_container) ?
154+
doc.getElementById(opt_container) : opt_container;
141155
if (this.container_)
142156
this.updateContainer_();
143157
this.checkSize(true, true);
@@ -765,6 +779,15 @@ acgraph.vector.Stage.prototype.clip = function(opt_value) {
765779
};
766780

767781

782+
/**
783+
* Returns anychart charts for this stage.
784+
* @return {Object}
785+
*/
786+
acgraph.vector.Stage.prototype.getCharts = function() {
787+
return this.charts;
788+
};
789+
790+
768791
//endregion
769792
//region --- Internal methods
770793
//------------------------------------------------------------------------------
@@ -837,7 +860,7 @@ acgraph.vector.Stage.prototype.checkSize = function(opt_directCall, opt_silent)
837860
if (!opt_silent)
838861
this.dispatchEvent(acgraph.vector.Stage.EventType.STAGE_RESIZE);
839862
}
840-
if (this.container_ && isDynamicSize) {
863+
if (this.container_ && isDynamicSize && !goog.global['isNodeJS']) {
841864
this.checkSizeTimer_ = setTimeout(this.checkSize, this.maxResizeDelay_);
842865
}
843866
};
@@ -2125,6 +2148,8 @@ acgraph.vector.Stage.prototype.disposeInternal = function() {
21252148
delete this.internalContainer_;
21262149
this.domElement_ = null;
21272150

2151+
acgraph.getRenderer().disposeMeasurement();
2152+
21282153
if (this.credits_) {
21292154
this.credits_.dispose();
21302155
this.credits_ = null;
@@ -2226,5 +2251,6 @@ acgraph.vector.Stage.prototype.disposeInternal = function() {
22262251
proto['removeAllListeners'] = proto.removeAllListeners;
22272252
proto['title'] = proto.title;
22282253
proto['desc'] = proto.desc;
2254+
proto['getCharts'] = proto.getCharts;
22292255
})();
22302256
//endregion

src/vector/svg/Renderer.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ acgraph.vector.svg.Renderer.prototype.imageLoader_ = null;
101101
* @private
102102
*/
103103
acgraph.vector.svg.Renderer.prototype.createSVGElement_ = function(tag) {
104-
return goog.dom.getDocument().createElementNS(
104+
return goog.global['document'].createElementNS(
105105
acgraph.vector.svg.Renderer.SVG_NS_,
106106
tag
107107
);
@@ -125,7 +125,7 @@ acgraph.vector.svg.Renderer.prototype.createMeasurement = function() {
125125
goog.dom.appendChild(this.measurementText_, this.measurementTextNode_);
126126
goog.dom.appendChild(this.measurement_, this.measurementText_);
127127
goog.dom.appendChild(this.measurement_, this.mesurmentDef_);
128-
goog.dom.appendChild(goog.dom.getDocument().body, this.measurement_);
128+
goog.dom.appendChild(goog.global['document'].body, this.measurement_);
129129

130130
this.measurementLayerForBBox_ = this.createLayerElement();
131131
goog.dom.appendChild(this.measurement_, this.measurementLayerForBBox_);
@@ -138,6 +138,26 @@ acgraph.vector.svg.Renderer.prototype.createMeasurement = function() {
138138
};
139139

140140

141+
/**
142+
* Measurements disposing.
143+
*/
144+
acgraph.vector.svg.Renderer.prototype.disposeMeasurement = function() {
145+
goog.dom.removeNode(this.measurementText_);
146+
goog.dom.removeNode(this.measurementTextNode_);
147+
goog.dom.removeNode(this.mesurmentDef_);
148+
goog.dom.removeNode(this.measurementLayerForBBox_);
149+
goog.dom.removeNode(this.measurementGroupNode_);
150+
goog.dom.removeNode(this.measurement_);
151+
152+
this.measurementText_ = null;
153+
this.measurementTextNode_ = null;
154+
this.mesurmentDef_ = null;
155+
this.measurementLayerForBBox_ = null;
156+
this.measurementGroupNode_ = null;
157+
this.measurement_ = null;
158+
};
159+
160+
141161
/**
142162
* Measures text.
143163
* @param {string} text The text to measure.

0 commit comments

Comments
 (0)