Skip to content

Commit 40bbef3

Browse files
committed
Pulled process data method into Component class. Added range normalization to adapter.
1 parent bae1d68 commit 40bbef3

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

js/Component.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,17 @@ Component.prototype = {
108108
var
109109
api = this.api,
110110
options = this.options,
111+
preprocessor = this.preprocessor,
111112
data = data || options.data,
112113
config = config || options.config,
113114
clientData = data;
114115

115116
if (!options.skipPreprocess && data) {
116117

117118
if (data !== options.data) {
118-
this.preprocessor.setData(data);
119+
preprocessor.setData(data);
119120
} else {
120-
this.preprocessor.reset();
121+
preprocessor.reset();
121122
}
122123

123124
clientData = [];
@@ -127,7 +128,29 @@ Component.prototype = {
127128
isArray = _.isArray(d),
128129
isFunction = _.isFunction(d),
129130
unprocessed = isArray ? d : (isFunction ? d : d.data),
130-
processed = api.processData(unprocessed, config, this.node, this.preprocessor, options.processData);
131+
processData = options.processData,
132+
range = api.range(config),
133+
min = range.min,
134+
max = range.max,
135+
resolution = this.node.clientWidth,
136+
processed;
137+
138+
if (isFunction) {
139+
processed = data(min, max, resolution);
140+
} else if (processData) {
141+
processData.apply(this, [{
142+
preprocessor : preprocessor,
143+
min : min,
144+
max : max,
145+
resolution : resolution
146+
}]);
147+
processed = preprocessor.getData();
148+
} else {
149+
processed = preprocessor
150+
.bound(min, max)
151+
.subsampleMinMax(resolution)
152+
.getData();
153+
}
131154

132155
if (!isFunction && !isArray) {
133156
// Objects

js/adapters/flotr/Child.js

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,13 @@ Child.prototype = {
4040
this.flotr = Flotr.draw(node, data, flotr);
4141
},
4242

43-
processData : function (data, flotr, node, preprocessor, processData) {
44-
43+
range : function (flotr) {
4544
var
46-
options = this.options,
47-
resolution = node.clientWidth,
48-
axis = flotr.xaxis,
49-
min = axis.min,
50-
max = axis.max;
51-
52-
if (_.isFunction(data)) {
53-
return data(min, max, resolution);
54-
} else if (processData) {
55-
processData.apply(this, [{
56-
preprocessor : preprocessor,
57-
min : min,
58-
max : max,
59-
resolution : resolution
60-
}]);
61-
} else {
62-
preprocessor
63-
.bound(min, max)
64-
.subsampleMinMax(resolution);
65-
}
66-
67-
return preprocessor.getData();
45+
axis = flotr.xaxis;
46+
return {
47+
min : axis.min,
48+
max : axis.max
49+
};
6850
},
6951

7052
// Transform for Flotr
@@ -73,7 +55,7 @@ Child.prototype = {
7355
var
7456
length = data[0].length,
7557
dimension = data.length,
76-
newData = [],
58+
transformed = [],
7759
point,
7860
i, j;
7961

@@ -82,10 +64,10 @@ Child.prototype = {
8264
for (j = 0; j < dimension; j++) {
8365
point.push(data[j][i]);
8466
}
85-
newData.push(point);
67+
transformed.push(point);
8668
}
8769

88-
return newData;
70+
return transformed;
8971
},
9072

9173
getDataArray : function (data) {

0 commit comments

Comments
 (0)