@@ -8,6 +8,65 @@ var Filter = require('./Filter');
8
8
var Slider = require ( './Slider' ) ;
9
9
var StepNumber = require ( './StepNumber' ) ;
10
10
11
+ // -----------------------------------------------------------------------------
12
+ // Definitions private to module
13
+ // -----------------------------------------------------------------------------
14
+
15
+ /**
16
+ * Field names in the options hash which are of relevance to the user.
17
+ *
18
+ * Specifically, these are the fields which require no special handling,
19
+ * and can be directly copied over.
20
+ */
21
+ var OPTIONKEYS = [
22
+ 'width' ,
23
+ 'height' ,
24
+ 'filterLabel' ,
25
+ 'legendLabel' ,
26
+ 'xLabel' ,
27
+ 'yLabel' ,
28
+ 'zLabel' ,
29
+ 'xValueLabel' ,
30
+ 'yValueLabel' ,
31
+ 'zValueLabel' ,
32
+ 'showGrid' ,
33
+ 'showPerspective' ,
34
+ 'showShadow' ,
35
+ 'showAnimationControls' ,
36
+ 'keepAspectRatio' ,
37
+ 'verticalRatio' ,
38
+ 'animationInterval' ,
39
+ 'animationPreload' ,
40
+ 'animationAutoStart' ,
41
+ 'axisColor' ,
42
+ 'gridColor'
43
+ ] ;
44
+
45
+
46
+ /**
47
+ * Copy fields from src to dst in a controlled manner.
48
+ *
49
+ * Only the fields mentioned in array 'fields' will be copied over,
50
+ * and only if these are actually defined.
51
+ *
52
+ * @param fields array with names of fields to copy
53
+ */
54
+ function safeCopy ( src , dst , fields ) {
55
+ for ( var i in fields ) {
56
+ var field = fields [ i ] ;
57
+
58
+ if ( src [ field ] !== undefined ) {
59
+ dst [ field ] = src [ field ] ;
60
+ }
61
+ }
62
+ }
63
+
64
+
65
+
66
+ // -----------------------------------------------------------------------------
67
+ // Class Graph3d
68
+ // -----------------------------------------------------------------------------
69
+
11
70
/**
12
71
* @constructor Graph3d
13
72
* Graph3d displays data in 3d.
@@ -867,46 +926,25 @@ Graph3d.prototype.setOptions = function (options) {
867
926
868
927
if ( options !== undefined ) {
869
928
// retrieve parameter values
870
- if ( options . width !== undefined ) this . width = options . width ;
871
- if ( options . height !== undefined ) this . height = options . height ;
872
929
930
+ // Handle the parameters which can be simply copied over
931
+ safeCopy ( options , this , OPTIONKEYS ) ;
932
+
933
+ // Handle the rest of the parameters
873
934
if ( options . xCenter !== undefined ) this . defaultXCenter = options . xCenter ;
874
935
if ( options . yCenter !== undefined ) this . defaultYCenter = options . yCenter ;
875
-
876
- if ( options . filterLabel !== undefined ) this . filterLabel = options . filterLabel ;
877
- if ( options . legendLabel !== undefined ) this . legendLabel = options . legendLabel ;
878
936
if ( options . showLegend !== undefined ) this . defaultShowLegend = options . showLegend ;
879
- if ( options . xLabel !== undefined ) this . xLabel = options . xLabel ;
880
- if ( options . yLabel !== undefined ) this . yLabel = options . yLabel ;
881
- if ( options . zLabel !== undefined ) this . zLabel = options . zLabel ;
882
-
883
- if ( options . xValueLabel !== undefined ) this . xValueLabel = options . xValueLabel ;
884
- if ( options . yValueLabel !== undefined ) this . yValueLabel = options . yValueLabel ;
885
- if ( options . zValueLabel !== undefined ) this . zValueLabel = options . zValueLabel ;
886
-
887
- if ( options . dotSizeRatio !== undefined ) this . dotSizeRatio = options . dotSizeRatio ;
888
937
889
938
if ( options . style !== undefined ) {
890
939
var styleNumber = this . _getStyleNumber ( options . style ) ;
891
940
if ( styleNumber !== - 1 ) {
892
941
this . style = styleNumber ;
893
942
}
894
943
}
895
- if ( options . showGrid !== undefined ) this . showGrid = options . showGrid ;
896
- if ( options . showPerspective !== undefined ) this . showPerspective = options . showPerspective ;
897
- if ( options . showShadow !== undefined ) this . showShadow = options . showShadow ;
898
- if ( options . tooltip !== undefined ) this . showTooltip = options . tooltip ;
899
- if ( options . showAnimationControls !== undefined ) this . showAnimationControls = options . showAnimationControls ;
900
- if ( options . keepAspectRatio !== undefined ) this . keepAspectRatio = options . keepAspectRatio ;
901
- if ( options . verticalRatio !== undefined ) this . verticalRatio = options . verticalRatio ;
902
-
903
- if ( options . animationInterval !== undefined ) this . animationInterval = options . animationInterval ;
904
- if ( options . animationPreload !== undefined ) this . animationPreload = options . animationPreload ;
905
- if ( options . animationAutoStart !== undefined ) this . animationAutoStart = options . animationAutoStart ;
944
+ if ( options . tooltip !== undefined ) this . showTooltip = options . tooltip ;
906
945
907
946
if ( options . xBarWidth !== undefined ) this . defaultXBarWidth = options . xBarWidth ;
908
947
if ( options . yBarWidth !== undefined ) this . defaultYBarWidth = options . yBarWidth ;
909
-
910
948
if ( options . xMin !== undefined ) this . defaultXMin = options . xMin ;
911
949
if ( options . xStep !== undefined ) this . defaultXStep = options . xStep ;
912
950
if ( options . xMax !== undefined ) this . defaultXMax = options . xMax ;
@@ -928,8 +966,6 @@ Graph3d.prototype.setOptions = function (options) {
928
966
}
929
967
930
968
// colors
931
- if ( options . axisColor !== undefined ) this . axisColor = options . axisColor ;
932
- if ( options . gridColor !== undefined ) this . gridColor = options . gridColor ;
933
969
if ( options . dataColor ) {
934
970
if ( typeof options . dataColor === 'string' ) {
935
971
this . dataColor . fill = options . dataColor ;
0 commit comments