1 | var util = require('vis-util');
|
2 | var Bars = require('./graph2d_types/bar');
|
3 | var Lines = require('./graph2d_types/line');
|
4 | var Points = require('./graph2d_types/points');
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function GraphGroup(group, groupId, options, groupsUsingDefaultStyles) {
|
17 | this.id = groupId;
|
18 | var fields = ['sampling', 'style', 'sort', 'yAxisOrientation', 'barChart', 'drawPoints', 'shaded', 'interpolation', 'zIndex','excludeFromStacking', 'excludeFromLegend'];
|
19 | this.options = util.selectiveBridgeObject(fields, options);
|
20 | this.usingDefaultStyle = group.className === undefined;
|
21 | this.groupsUsingDefaultStyles = groupsUsingDefaultStyles;
|
22 | this.zeroPosition = 0;
|
23 | this.update(group);
|
24 | if (this.usingDefaultStyle == true) {
|
25 | this.groupsUsingDefaultStyles[0] += 1;
|
26 | }
|
27 | this.itemsData = [];
|
28 | this.visible = group.visible === undefined ? true : group.visible;
|
29 | }
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | GraphGroup.prototype.setItems = function (items) {
|
36 | if (items != null) {
|
37 | this.itemsData = items;
|
38 | if (this.options.sort == true) {
|
39 | util.insertSort(this.itemsData,function (a, b) {
|
40 | return a.x > b.x ? 1 : -1;
|
41 | });
|
42 | }
|
43 | }
|
44 | else {
|
45 | this.itemsData = [];
|
46 | }
|
47 | };
|
48 |
|
49 | GraphGroup.prototype.getItems = function () {
|
50 | return this.itemsData;
|
51 | };
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | GraphGroup.prototype.setZeroPosition = function (pos) {
|
58 | this.zeroPosition = pos;
|
59 | };
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | GraphGroup.prototype.setOptions = function (options) {
|
66 | if (options !== undefined) {
|
67 | var fields = ['sampling', 'style', 'sort', 'yAxisOrientation', 'barChart', 'zIndex','excludeFromStacking', 'excludeFromLegend'];
|
68 | util.selectiveDeepExtend(fields, this.options, options);
|
69 |
|
70 |
|
71 | if (typeof options.drawPoints == 'function') {
|
72 | options.drawPoints = {
|
73 | onRender: options.drawPoints
|
74 | }
|
75 | }
|
76 |
|
77 | util.mergeOptions(this.options, options, 'interpolation');
|
78 | util.mergeOptions(this.options, options, 'drawPoints');
|
79 | util.mergeOptions(this.options, options, 'shaded');
|
80 |
|
81 | if (options.interpolation) {
|
82 | if (typeof options.interpolation == 'object') {
|
83 | if (options.interpolation.parametrization) {
|
84 | if (options.interpolation.parametrization == 'uniform') {
|
85 | this.options.interpolation.alpha = 0;
|
86 | }
|
87 | else if (options.interpolation.parametrization == 'chordal') {
|
88 | this.options.interpolation.alpha = 1.0;
|
89 | }
|
90 | else {
|
91 | this.options.interpolation.parametrization = 'centripetal';
|
92 | this.options.interpolation.alpha = 0.5;
|
93 | }
|
94 | }
|
95 | }
|
96 | }
|
97 | }
|
98 | };
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | GraphGroup.prototype.update = function (group) {
|
106 | this.group = group;
|
107 | this.content = group.content || 'graph';
|
108 | this.className = group.className || this.className || 'vis-graph-group' + this.groupsUsingDefaultStyles[0] % 10;
|
109 | this.visible = group.visible === undefined ? true : group.visible;
|
110 | this.style = group.style;
|
111 | this.setOptions(group.options);
|
112 | };
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | GraphGroup.prototype.getLegend = function (iconWidth, iconHeight, framework, x, y) {
|
125 | if (framework == undefined || framework == null) {
|
126 | var svg = document.createElementNS('http://www.w3.org/2000/svg', "svg");
|
127 | framework = {svg: svg, svgElements:{}, options: this.options, groups: [this]}
|
128 | }
|
129 | if (x == undefined || x == null){
|
130 | x = 0;
|
131 | }
|
132 | if (y == undefined || y == null){
|
133 | y = 0.5 * iconHeight;
|
134 | }
|
135 | switch (this.options.style){
|
136 | case "line":
|
137 | Lines.drawIcon(this, x, y, iconWidth, iconHeight, framework);
|
138 | break;
|
139 | case "points":
|
140 | case "point":
|
141 | Points.drawIcon(this, x, y, iconWidth, iconHeight, framework);
|
142 | break;
|
143 | case "bar":
|
144 | Bars.drawIcon(this, x, y, iconWidth, iconHeight, framework);
|
145 | break;
|
146 | }
|
147 | return {icon: framework.svg, label: this.content, orientation: this.options.yAxisOrientation};
|
148 | };
|
149 |
|
150 | GraphGroup.prototype.getYRange = function (groupData) {
|
151 | var yMin = groupData[0].y;
|
152 | var yMax = groupData[0].y;
|
153 | for (var j = 0; j < groupData.length; j++) {
|
154 | yMin = yMin > groupData[j].y ? groupData[j].y : yMin;
|
155 | yMax = yMax < groupData[j].y ? groupData[j].y : yMax;
|
156 | }
|
157 | return {min: yMin, max: yMax, yAxisOrientation: this.options.yAxisOrientation};
|
158 | };
|
159 |
|
160 | module.exports = GraphGroup;
|