-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathStage.js
More file actions
2308 lines (1977 loc) · 70.7 KB
/
Stage.js
File metadata and controls
2308 lines (1977 loc) · 70.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
goog.provide('acgraph.vector.Stage');
goog.require('acgraph.error');
goog.require('acgraph.events.BrowserEvent');
goog.require('acgraph.utils.IdGenerator');
goog.require('acgraph.utils.exporting');
goog.require('acgraph.vector.Circle');
goog.require('acgraph.vector.Clip');
goog.require('acgraph.vector.Defs');
goog.require('acgraph.vector.Ellipse');
goog.require('acgraph.vector.HatchFill');
goog.require('acgraph.vector.ILayer');
goog.require('acgraph.vector.Image');
goog.require('acgraph.vector.Layer');
goog.require('acgraph.vector.Path');
goog.require('acgraph.vector.PatternFill');
goog.require('acgraph.vector.Rect');
goog.require('acgraph.vector.Text');
goog.require('acgraph.vector.UnmanagedLayer');
goog.require('goog.array');
goog.require('goog.dom');
goog.require('goog.dom.classlist');
goog.require('goog.dom.fullscreen');
goog.require('goog.events.EventHandler');
goog.require('goog.events.EventTarget');
goog.require('goog.events.Listenable');
goog.require('goog.math.Coordinate');
goog.require('goog.math.Rect');
goog.require('goog.math.Size');
goog.require('goog.style');
/**
This class provide tools for cross-browser display with the single interface for
both (SVG and VML).
<b>Do not invoke constructor directly.</b> Use {@link acgraph.create}.
<p><b>Note:</b><br>
acgraph.vector.Stage delegates all work with DOM elements, style and attributes
to its renderer. You can get renderer using <a href="acgraph.vector.Stage#.getRenderer">getRenderer
</a> method.<br/>
<strong>Note:</strong> Renderer is a singleton must not contain own fields.
</p><p>
<b>Rendering:</b><br/>
acgraph.vector.Stage has the <code>rootLayer_</code> private field of <a href="acgraph.vector.Layer">Layer</a>
type. All layers and elements you add to a stage go there, so rendering and other stuff happens
when this layer is rendered.
</p>
@see acgraph.create
@name acgraph.vector.Stage
@param {(Element|string)=} opt_container Container. Can be set later.
@param {(number|string)=} opt_width Stage width in pixels.
@param {(number|string)=} opt_height Stage width in pixels.
@constructor
@extends {goog.events.EventTarget}
@implements {acgraph.vector.ILayer}
@implements {goog.events.Listenable}
*/
acgraph.vector.Stage = function(opt_container, opt_width, opt_height) {
goog.base(this);
this.renderAsync_ = goog.bind(this.renderAsync_, this);
this.checkSize = goog.bind(this.checkSize, this);
var doc = acgraph.window['document'];
if (!acgraph.module.stages)
acgraph.module.stages = {};
var id = acgraph.utils.IdGenerator.getInstance().identify(this, acgraph.utils.IdGenerator.ElementTypePrefix.STAGE);
acgraph.module.stages[id] = this;
this.charts = {};
/**
* Event handler of the stage.
* @type {goog.events.EventHandler}
* @private
*/
this.eventHandler_ = new goog.events.EventHandler(this);
/**
* Wrapper container DOM element.
* @type {!Element}
* @private
*/
// this.internalContainer_ = goog.dom.createDom(goog.dom.TagName.DIV, {style: 'position:relative;left:0;top:0;overflow:hidden;'});
this.internalContainer_ = doc.createElement(goog.dom.TagName.DIV);
goog.style.setStyle(this.internalContainer_, {'position': 'relative', 'left': 0, 'top': 0, 'overflow': 'hidden'});
/**
* Root DOM element of stage object.
* Root DOM element of stage object can't be null, it is created
* in constructor using #createDomElement method.
* @type {Element}
* @private
*/
this.domElement_ = acgraph.getRenderer().createStageElement();
acgraph.register(this);
acgraph.getRenderer().setStageSize(this.domElement_, '100%', '100%');
//We need set 'display: block' for <svg> element to prevent scrollbar on 100% height of parent container (see DVF-620)
goog.style.setStyle(this.domElement_, 'display', 'block');
// Add class for check anychart-ui.css attached. (DVF-1619)
goog.dom.classlist.add(this.domElement_, 'anychart-ui-support');
goog.dom.appendChild(this.internalContainer_, this.domElement_);
this.domElement_.setAttribute('ac-id', id);
/**
* Array of clips that should be rendered when stage is rendering.
* @type {Array.<acgraph.vector.Clip>}
* @private
*/
this.clipsToRender_ = [];
/**
* Container to store elements which can be reused by reference in other elements.
* For SVG ({@link http://www.w3.org/TR/SVG/struct.html#DefsElement=|Defs})
* For VML ({@link http://www.w3.org/TR/NOTE-VML#_Toc416858387|ShapeType})
* @type {!acgraph.vector.Defs}
* @private
*/
this.defs_ = this.createDefs();
this.defs_.render();
/**
* Root layer for Stage. All layer and elements added to stage go in this layer.
* So all rendering and other stuff happens here.
* @type {!acgraph.vector.Layer}
* @private
*/
this.rootLayer_ = new acgraph.vector.Layer();
this.rootLayer_.setParent(this).render();
goog.dom.appendChild(this.domElement_, this.rootLayer_.domElement());
acgraph.getRenderer().createMeasurement();
this.eventHandler_.listen(this.domElement(), [
goog.events.EventType.MOUSEDOWN,
goog.events.EventType.MOUSEOVER,
goog.events.EventType.MOUSEOUT,
goog.events.EventType.CLICK,
goog.events.EventType.DBLCLICK,
goog.events.EventType.TOUCHSTART,
goog.events.EventType.TOUCHEND,
goog.events.EventType.TOUCHCANCEL,
goog.events.EventType.MSPOINTERDOWN,
goog.events.EventType.MSPOINTERUP,
goog.events.EventType.POINTERDOWN,
goog.events.EventType.POINTERUP,
goog.events.EventType.CONTEXTMENU
], this.handleMouseEvent_, false);
this.setWidth_(opt_width || '100%');
this.setHeight_(opt_height || '100%');
this.container_ = goog.isString(opt_container) ?
doc.getElementById(opt_container) : opt_container;
if (this.container_)
this.updateContainer_();
this.checkSize(true, true);
this.resume();
};
goog.inherits(acgraph.vector.Stage, goog.events.EventTarget);
//region --- Enums and consts
//----------------------------------------------------------------------------------------------------------------------
//
// Enums and consts
//
//----------------------------------------------------------------------------------------------------------------------
/**
* DOM changes. Used for to assign quotas.
* @enum {number}
*/
acgraph.vector.Stage.DomChangeType = {
/**
* Creating element
*/
ELEMENT_CREATE: 1,
/**
* Adding child
*/
ELEMENT_ADD: 2,
/**
* Removing child
*/
ELEMENT_REMOVE: 3,
/**
* Apply fill
*/
APPLY_FILL: 4,
/**
* Apply stroke
*/
APPLY_STROKE: 5
};
/**
* Stage events
* @enum {string}
*/
acgraph.vector.Stage.EventType = {
/** Rendering start */
RENDER_START: 'renderstart',
/** Rendering end */
RENDER_FINISH: 'renderfinish',
/** Fires when resize event occurs */
STAGE_RESIZE: 'stageresize',
/** Fires when image loader finished loading all images */
STAGE_RENDERED: 'stagerendered'
};
/**
* Export types.
* @enum {string}
*/
acgraph.vector.Stage.ExportType = {
SVG: 'svg',
JPG: 'jpg',
PNG: 'png',
PDF: 'pdf'
};
/**
* This is a lsh (<< - left shift) second argument to convert simple HANDLED_EVENT_TYPES code to a
* CAPTURE HANDLED_EVENT_TYPES code.
* @type {number}
*/
acgraph.vector.Stage.HANDLED_EVENT_TYPES_CAPTURE_SHIFT = 12;
//endregion
//region --- Properties
//----------------------------------------------------------------------------------------------------------------------
//
// Properties
//
//----------------------------------------------------------------------------------------------------------------------
/**
* Actual pixel stage width. Anything displayed on stage must be within this
* range or it will be clipped.
* @type {number}
* @private
*/
acgraph.vector.Stage.prototype.width_ = NaN;
/**
* Actual pixel stage height. Anything displayed on stage must be within this
* range or it will be clipped.
* @type {number}
* @private
*/
acgraph.vector.Stage.prototype.height_ = NaN;
/**
* Contains fixed width value. If the width is set in percent - contains NaN.
* @type {number}
* @private
*/
acgraph.vector.Stage.prototype.fixedWidth_ = NaN;
/**
* Contains fixed height value. If the height is set in percent - contains NaN.
* @type {number}
* @private
*/
acgraph.vector.Stage.prototype.fixedHeight_ = NaN;
/**
* Current width settings.
* @type {number|string}
* @private
*/
acgraph.vector.Stage.prototype.currentWidth_ = NaN;
/**
* Current height settings.
* @type {number|string}
* @private
*/
acgraph.vector.Stage.prototype.currentHeight_ = NaN;
/**
* Max resize reaction delay.
* @type {number}
* @private
*/
acgraph.vector.Stage.prototype.maxResizeDelay_ = 100;
/**
* Resize timeout handler.
* @type {number}
* @private
*/
acgraph.vector.Stage.prototype.checkSizeTimer_ = NaN;
/**
* The number of DOM changes done in one rendering frame. Used in async rendering to count quotas
* of DOM operations in one rendering frame.
* @type {number}
* @protected
*/
acgraph.vector.Stage.prototype.currentDomChangesCount = 0;
// todo (Anton Saukh): Automatic quota assignment depending on performance.
/**
* Maximum number of DOM changes in one frame. Used in async rendering as the quota.
* @type {number}
* @protected
*/
acgraph.vector.Stage.prototype.maxDomChanges = 500;
/**
* Path to radial gradient image. VML renderer required.
* @type {string}
*
*/
acgraph.vector.Stage.prototype['pathToRadialGradientImage'] = 'RadialGradient.png';
/**
* Stage id (id attribute of DOM element).
* @type {string|undefined}
* @private
*/
acgraph.vector.Stage.prototype.id_ = undefined;
/**
* Rendering mode (>0 - suspended, 0 - instant)
* Initially we suspend to render root layer and stage,
* then release.
* @type {number}
* @private
*/
acgraph.vector.Stage.prototype.suspended_ = 1;
/**
* Container DOM element.
* @type {Element}
* @private
*/
acgraph.vector.Stage.prototype.container_ = null;
/**
* Title element. A subnode.
* @type {?Element}
*/
acgraph.vector.Stage.prototype.titleElement = null;
/**
* Text of title.
* @type {string|null|undefined}
* @private
*/
acgraph.vector.Stage.prototype.titleVal_ = void 0;
/**
* Desc element. A subnode.
* @type {?Element}
*/
acgraph.vector.Stage.prototype.descElement = null;
/**
* Text of desc.
* @type {string|null|undefined}
* @private
*/
acgraph.vector.Stage.prototype.descVal_ = void 0;
/**
* If the stage is in async mode.
* @type {boolean}
* @private
*/
acgraph.vector.Stage.prototype.asyncMode_ = false;
/**
* Whether the stage is in process of rendering.
* @type {boolean}
* @private
*/
acgraph.vector.Stage.prototype.isRendering_ = false;
//endregion
//region --- Published methods
//------------------------------------------------------------------------------
//
// Published methods
//
//------------------------------------------------------------------------------
/**
Gets stage identifier. If it was not set, than it will be generated.
@param {string=} opt_value Custom id.
@return {(!acgraph.vector.Stage|string)} Returns element identifier.
*/
acgraph.vector.Stage.prototype.id = function(opt_value) {
if (goog.isDef(opt_value)) {
var id = opt_value || '';
if (this.id_ != id) {
this.id_ = id;
acgraph.getRenderer().setIdInternal(this.domElement_, this.id_);
}
return this;
}
if (!goog.isDef(this.id_))
this.id(acgraph.utils.IdGenerator.getInstance().generateId(this));
return /** @type {string} */(this.id_);
};
/**
Returns self. We need this method to sync layer and stage api.
@return {!acgraph.vector.Stage} {@link acgraph.vector.Stage} for method chaining.
*/
acgraph.vector.Stage.prototype.getStage = function() {
return this;
};
/**
Returns self. We need this method to sync layer and stage api.
@return {!acgraph.vector.Stage} {@link acgraph.vector.Stage} for method chaining.
*/
acgraph.vector.Stage.prototype.parent = function() {
return this;
};
/**
Returns stage root DOM element.
@return {Element} Stage root DOM element.
*/
acgraph.vector.Stage.prototype.domElement = function() {
return this.domElement_;
};
/**
* If opt_value defined then it will be set as stage width else returns current stage width.
* Stage width can be defined as pixel or percent value.
* @param {(string|number)=} opt_value Width of stage.
* @return {number|acgraph.vector.Stage} Width of stage.
*
*/
acgraph.vector.Stage.prototype.width = function(opt_value) {
if (goog.isDef(opt_value)) {
if (this.setWidth_(opt_value)) {
this.checkSize(true);
// it seems that we have no need to initialize rendering here
// this.render();
}
return this;
}
return this.width_ || 0;
};
/**
* If opt_value defined then it will be set as stage height else returns current stage height.
* Stage height can be defined as pixel or percent value.
* @param {(string|number)=} opt_value Height of stage.
* @return {number|acgraph.vector.Stage} Height of stage.
*/
acgraph.vector.Stage.prototype.height = function(opt_value) {
if (goog.isDef(opt_value)) {
if (this.setHeight_(opt_value)) {
this.checkSize(true);
// it seems that we have no need to initialize rendering here
// this.render();
}
return this;
}
return this.height_ || 0;
};
/**
* Stage resize. Anything drawn on stage must fit in it
* So any part that doesn't fit will be clipped.
* @param {number|string} width Width.
* @param {number|string} height Height.
*/
acgraph.vector.Stage.prototype.resize = function(width, height) {
var widthChanged = this.setWidth_(width);
var heightChanged = this.setHeight_(height);
if (widthChanged || heightChanged) {
this.checkSize(true);
// it seems that we have no need to initialize rendering here
// this.render();
}
};
/**
* Getter and setter for max delay in milliseconds between the container resize and
* the stage reaction on it.
* @param {number=} opt_value
* @return {number|acgraph.vector.Stage}
*/
acgraph.vector.Stage.prototype.maxResizeDelay = function(opt_value) {
if (goog.isDef(opt_value)) {
var val = parseFloat(opt_value);
if (val >= 0) {
if (this.maxResizeDelay_ > val && !isNaN(this.checkSizeTimer_))
clearTimeout(this.checkSizeTimer_);
this.maxResizeDelay_ = val;
this.checkSize(true);
}
return this;
}
return this.maxResizeDelay_;
};
/**
Returns DOM element where everything is drawn upon rendering.
@param {(Element|string)=} opt_value Container element.
@return {Element|acgraph.vector.Stage} Stage.
*/
acgraph.vector.Stage.prototype.container = function(opt_value) {
if (goog.isDef(opt_value)) {
var container = goog.dom.getElement(opt_value || null);
if (this.container_ != container) {
this.container_ = container;
this.updateContainer_();
this.checkSize(true);
this.render();
}
return this;
}
return this.container_ ? this.internalContainer_ : null;
};
/**
* Returns stage container element.
* @return {Element}
*/
acgraph.vector.Stage.prototype.getContainerElement = function() {
return this.container_;
};
/**
* Returns wrapper div that contains.
* @return {!Element}
*/
acgraph.vector.Stage.prototype.getDomWrapper = function() {
return this.internalContainer_;
};
/**
Suspends rendering (changes instant to suspended).<br/>
When Stage is in this state changes do not affect DOM.<br/>
To wake Stage up from this state you need to invoke {@link acgraph.vector.Stage#resume}.<br/>
Suspended rendering is much faster than instant, when there are a lot of operations with Stage.
@return {acgraph.vector.Stage} Stage.
*/
acgraph.vector.Stage.prototype.suspend = function() {
this.suspended_++;
return this;
};
/**
Removes Suspend state and applies all changes in sync (if any).<br/>
Read more at {@link acgraph.vector.Stage#suspend}.
@param {boolean=} opt_force
@return {acgraph.vector.Stage} Stage.
*/
acgraph.vector.Stage.prototype.resume = function(opt_force) {
this.suspended_ = opt_force ? 0 : Math.max(this.suspended_ - 1, 0);
this.render();
return this;
};
/**
* Getter and setter for the stage rendering mode. If set to true - stage is rendered in async manner allowing the
* page to interact while the rendering is in process. In this mode you should listen the RENDER_FINISH or
* STAGE_RENDERED event on the stage.
* @param {boolean=} opt_value
* @return {acgraph.vector.Stage|boolean}
*/
acgraph.vector.Stage.prototype.asyncMode = function(opt_value) {
if (goog.isDef(opt_value)) {
this.asyncMode_ = !!opt_value;
return this;
}
return this.asyncMode_;
};
/**
Returns rendering state (true - suspended, false - instant
@return {boolean} Rendering state.
*/
acgraph.vector.Stage.prototype.isSuspended = function() {
return !!this.suspended_;
};
/**
Indicates if stage is in rendering process.
@return {boolean} State of rendering process.
*/
acgraph.vector.Stage.prototype.isRendering = function() {
return this.isRendering_;
};
/**
* Gets/sets element's title value.
* @param {?string=} opt_value - Value to be set.
* @return {(string|null|!acgraph.vector.Stage|undefined)} - Current value or itself for method chaining.
*/
acgraph.vector.Stage.prototype.title = function(opt_value) {
if (goog.isDef(opt_value)) {
if (this.titleVal_ != opt_value) {
this.titleVal_ = opt_value;
acgraph.getRenderer().setTitle(this, this.titleVal_);
}
return this;
} else {
return this.titleVal_;
}
};
/**
* Gets/sets element's desc value.
* @param {?string=} opt_value - Value to be set.
* @return {(string|null|!acgraph.vector.Stage|undefined)} - Current value or itself for method chaining.
*/
acgraph.vector.Stage.prototype.desc = function(opt_value) {
if (goog.isDef(opt_value)) {
if (this.descVal_ != opt_value) {
this.descVal_ = opt_value;
acgraph.getRenderer().setDesc(this, this.descVal_);
}
return this;
} else {
return this.descVal_;
}
};
/**
Returns stage visibility.
@param {boolean=} opt_isVisible Visibility.
@return {!acgraph.vector.Stage|boolean} Returns self for method chaining, if
opt_visible is set, current state otherwise.
*/
acgraph.vector.Stage.prototype.visible = function(opt_isVisible) {
if (arguments.length == 0) return /** @type {boolean} */ (this.rootLayer_.visible());
this.rootLayer_.visible(opt_isVisible);
return this;
};
/**
Returns Stage JSON. Serializes stage and all its object in JSON.
@param {Object=} opt_value .
@return {acgraph.vector.Stage|Object} JSON data of stage.
*/
acgraph.vector.Stage.prototype.data = function(opt_value) {
if (arguments.length == 0) {
return this.serialize();
} else {
var primitive;
var type = opt_value['type'];
if (!type) this.deserialize(opt_value);
else {
switch (type) {
case 'rect':
primitive = this.rect();
break;
case 'circle':
primitive = this.circle();
break;
case 'ellipse':
primitive = this.ellipse();
break;
case 'image':
primitive = this.image();
break;
case 'text':
primitive = this.text();
break;
case 'path':
primitive = this.path();
break;
case 'layer':
primitive = this.layer();
break;
default:
primitive = null;
break;
}
}
if (primitive) primitive.deserialize(opt_value);
return this;
}
};
/**
Removes everything.
@return {!acgraph.vector.Stage} {@link acgraph.vector.Stage} for method chaining.
*/
acgraph.vector.Stage.prototype.remove = function() {
return /** @type {!acgraph.vector.Stage} */(this.container(null));
};
/**
Returns X of top left corner.
@return {number} X of top left corner.
*/
acgraph.vector.Stage.prototype.getX = function() {
return 0;
};
/**
Returns Y of top left corner.
@return {number} Y of top left corner.
*/
acgraph.vector.Stage.prototype.getY = function() {
return 0;
};
/**
Returns bounds.
@return {!goog.math.Rect} Bounds.
*/
acgraph.vector.Stage.prototype.getBounds = function() {
return new goog.math.Rect(0, 0, /** @type {number} */ (this.width()), /** @type {number} */ (this.height()));
};
/**
Clips a stage.
Works only after render() is invoked.<br/>
Read more at: {@link acgraph.vector.Element#clip}.
@param {(goog.math.Rect|acgraph.vector.Clip)=} opt_value Clipping rectangle.
@return {acgraph.vector.Element|goog.math.Rect|acgraph.vector.Clip} {@link acgraph.vector.Stage} for method chaining
or {@link goog.math.Rect} clipping rectangle.
*/
acgraph.vector.Stage.prototype.clip = function(opt_value) {
return this.rootLayer_.clip(opt_value);
};
/**
* Returns anychart charts for this stage.
* @return {Object}
*/
acgraph.vector.Stage.prototype.getCharts = function() {
return this.charts;
};
/**
* Getter/setter for full screen status of the stage.
* @param {boolean=} opt_value
* @return {acgraph.vector.Stage|boolean}
*/
acgraph.vector.Stage.prototype.fullScreen = function(opt_value) {
var container = /** @type {Element} */(this.getDomWrapper());
if (goog.isDef(opt_value)) {
if (container && this.isFullScreenAvailable()) {
opt_value = !!opt_value;
if (this.fullScreen() != opt_value) {
if (opt_value)
goog.dom.fullscreen.requestFullScreenWithKeys(container);
else
goog.dom.fullscreen.exitFullScreen();
}
}
return this;
}
return !!(container && (goog.dom.fullscreen.getFullScreenElement() == container));
};
/**
* Tester for the full screen support.
* @return {boolean}
*/
acgraph.vector.Stage.prototype.isFullScreenAvailable = function() {
return goog.dom.fullscreen.isSupported();
};
//endregion
//region --- Internal methods
//------------------------------------------------------------------------------
//
// Internal methods
//
//------------------------------------------------------------------------------
/**
* Returns type prefix.
* @return {acgraph.utils.IdGenerator.ElementTypePrefix} Type prefix.
*/
acgraph.vector.Stage.prototype.getElementTypePrefix = function() {
return acgraph.utils.IdGenerator.ElementTypePrefix.STAGE;
};
/**
* Returns root layer element.
* @return {!acgraph.vector.Layer} Root layer element.
*/
acgraph.vector.Stage.prototype.getRootLayer = function() {
return this.rootLayer_;
};
/**
* Tell root layer that child was removed from DOM (moved to another layer).
* @param {acgraph.vector.Element} child Removed child.
*/
acgraph.vector.Stage.prototype.notifyRemoved = function(child) {
this.rootLayer_.notifyRemoved(child);
};
/**
* Tell layer that child clipping rectangle has changed.
*/
acgraph.vector.Stage.prototype.childClipChanged = goog.nullFunction;
/**
* Method that handles events cached by eventHandler_.
* @param {boolean=} opt_directCall
* @param {boolean=} opt_silent
*/
acgraph.vector.Stage.prototype.checkSize = function(opt_directCall, opt_silent) {
if (opt_directCall && !isNaN(this.checkSizeTimer_))
clearTimeout(this.checkSizeTimer_);
this.checkSizeTimer_ = NaN;
var width, height;
var isDynamicWidth = isNaN(this.fixedWidth_);
var isDynamicHeight = isNaN(this.fixedHeight_);
var isDynamicSize = isDynamicWidth || isDynamicHeight;
var detachedOrHidden;
if (isDynamicSize) {
var size;
if (this.fullScreen())
size = goog.style.getContentBoxSize(this.internalContainer_);
else
size = this.container_ ? goog.style.getContentBoxSize(this.container_) : new goog.math.Size(NaN, NaN);
size.width = Math.max(size.width || 0, 0);
size.height = Math.max(size.height || 0, 0);
detachedOrHidden = !size.width && !size.height;
width = isDynamicWidth ? size.width : this.fixedWidth_;
height = isDynamicHeight ? size.height : this.fixedHeight_;
} else {
width = this.fixedWidth_;
height = this.fixedHeight_;
detachedOrHidden = false;
}
if ((width != this.width_ || height != this.height_) && !detachedOrHidden) {
this.width_ = width;
this.height_ = height;
if (!opt_silent)
this.dispatchEvent(acgraph.vector.Stage.EventType.STAGE_RESIZE);
}
if (this.container_ && isDynamicSize && !acgraph.module['isNodeJS']) {
this.checkSizeTimer_ = setTimeout(this.checkSize, this.maxResizeDelay_);
}
};
/**
* @param {*} width
* @return {boolean}
* @private
*/
acgraph.vector.Stage.prototype.setWidth_ = function(width) {
if (this.currentWidth_ != width) {
var num = parseFloat(width);
if (!isNaN(num)) {
this.currentWidth_ = goog.isNumber(width) ? width : String(width);
this.fixedWidth_ = (goog.isString(width) && goog.string.endsWith(width, '%')) ? NaN : num;
goog.style.setWidth(this.internalContainer_, this.currentWidth_);
return true;
}
}
return false;
};
/**
* @param {*} height
* @return {boolean}
* @private
*/
acgraph.vector.Stage.prototype.setHeight_ = function(height) {
if (this.currentHeight_ != height) {
var num = parseFloat(height);
if (!isNaN(num)) {
this.currentHeight_ = goog.isNumber(height) ? height : String(height);
this.fixedHeight_ = (goog.isString(height) && goog.string.endsWith(height, '%')) ? NaN : num;
goog.style.setHeight(this.internalContainer_, this.currentHeight_);
return true;
}
}
return false;
};
/**
* Create container for reusable elements.
* @return {!acgraph.vector.Defs} Defs Element.
* @protected
*/
acgraph.vector.Stage.prototype.createDefs = goog.abstractMethod;
/**
* Returns Defs object.
* @return {!acgraph.vector.Defs} Defs object.
*/
acgraph.vector.Stage.prototype.getDefs = function() {
return this.defs_;
};
/**
TODO: We need to create method to clear SVG because there is no sense to clear defs only.<br/>
Destroy all content (e.g. gradients, some fill and etc.) in defs node.
@deprecated used only in AnyChartHTML5 v6.
*/
acgraph.vector.Stage.prototype.clearDefs = function() {
this.defs_.clear();
};
/**
* Updates clip or add to array to update on render.
* @param {acgraph.vector.Clip} clip Clip to update or clip that should be updated on render.
*/
acgraph.vector.Stage.prototype.addClipForRender = function(clip) {
if (!this.isSuspended()) {
clip.render();
} else {
this.clipsToRender_.push(clip);
}
};
/**
* Updates clip.
* @param {acgraph.vector.Clip} clip Clip that should be updated on render.
*/
acgraph.vector.Stage.prototype.removeClipFromRender = function(clip) {
goog.array.remove(this.clipsToRender_, clip);
};
/**
* Deserialize JSON data and apply it to Stage.
* @param {Object} data Data for deserialization.
*/
acgraph.vector.Stage.prototype.deserialize = function(data) {
this.width(data['width']);
this.height(data['height']);
data['type'] = 'layer';