<script type="text/javascript" src="../tests/css.js"></script>
<script type="text/javascript" src="../tests/selection.js"></script>
<script type="text/javascript" src="../tests/update_options.js"></script>
+ <script type="text/javascript" src="../tests/utils_test.js"></script>
<script type="text/javascript">
}
});
- // unclear why this is the existing behavior:
- //assertEquals(["0","1","2","3","4","5","6","7","8"], getXLabels());
- assertEquals(["0","2","4","6","8"], getXLabels());
+ assertEquals(["x0","x2","x4","x6","x8"], getXLabels());
//assertEquals(['0','2','4','6','8','10','12','14','16','18'], getYLabels());
//assertEquals(["y0","y1","y2","y3","y4","y5","y6","y7","y8"], getXLabels());
assertEquals(['y0','y2','y4','y6','y8','y10','y12','y14','y16','y18'], getYLabels());
g.setSelection(9);
- //assertEquals("xvf9: y:yvf18", getLegend());
- assertEquals("9: y:18", getLegend());
+ assertEquals("xvf9: y:yvf18", getLegend());
+ // assertEquals("9: y:18", getLegend());
};
assertEquals([12, 18], g.xAxisRange());
assertEquals([10, 40], g.yAxisRange(0));
+ console.log(g.user_attrs_);
g.updateOptions({ dateWindow : null, valueRange : null });
+ console.log(g.user_attrs_);
assertEquals([10, 20], g.xAxisRange());
assertEquals([0, 55], g.yAxisRange(0));
};
--- /dev/null
+/**
+ * @fileoverview Tests for stand-alone functions in dygraph-utils.js
+ *
+ * @author danvdk@gmail.com (Dan Vanderkam)
+ */
+
+var UtilsTestCase = TestCase("utils-tests");
+
+UtilsTestCase.prototype.testUpdate = function() {
+ var a = {
+ a: 1,
+ b: [1, 2, 3],
+ c: { x: 1, y: 2},
+ d: { f: 10, g: 20}
+ };
+ assertEquals(1, a['a']);
+ assertEquals([1, 2, 3], a['b']);
+ assertEquals({x: 1, y: 2}, a['c']);
+ assertEquals({f: 10, g: 20}, a['d']);
+
+ Dygraph.update(a, { c: { x: 2 } });
+ assertEquals({x: 2}, a['c']);
+
+ Dygraph.update(a, { d: null });
+ assertEquals(null, a['d']);
+
+ Dygraph.update(a, { a: 10, b: [1, 2] });
+ assertEquals(10, a['a']);
+ assertEquals([1, 2], a['b']);
+ assertEquals({x: 2}, a['c']);
+ assertEquals(null, a['d']);
+};
+
+UtilsTestCase.prototype.testUpdateDeep = function() {
+ var a = {
+ a: 1,
+ b: [1, 2, 3],
+ c: { x: 1, y: 2},
+ d: { f: 10, g: 20}
+ };
+ assertEquals(1, a['a']);
+ assertEquals([1, 2, 3], a['b']);
+ assertEquals({x: 1, y: 2}, a['c']);
+ assertEquals({f: 10, g: 20}, a['d']);
+
+ Dygraph.updateDeep(a, { c: { x: 2 } });
+ assertEquals({x: 2, y: 2}, a['c']);
+
+ Dygraph.updateDeep(a, { d: null });
+ assertEquals(null, a['d']);
+
+ Dygraph.updateDeep(a, { a: 10, b: [1, 2] });
+ assertEquals(10, a['a']);
+ assertEquals([1, 2], a['b']);
+ assertEquals({x: 2, y: 2}, a['c']);
+ assertEquals(null, a['d']);
+};
};
/**
+ * Copies all the properties from o to self.
+ *
+ * @private
+ */
+Dygraph.updateDeep = function (self, o) {
+ if (typeof(o) != 'undefined' && o !== null) {
+ for (var k in o) {
+ if (o.hasOwnProperty(k)) {
+ if (o[k] == null) {
+ self[k] = null;
+ } else if (typeof(self[k]) == 'object' &&
+ typeof(o[k]) == 'object' &&
+ !Dygraph.isArrayLike(o[k])) {
+ Dygraph.updateDeep(self[k], o[k]);
+ } else {
+ self[k] = o[k];
+ }
+ }
+ }
+ }
+ return self;
+};
+
+/**
* @private
*/
Dygraph.isArrayLike = function (o) {
// Check if this set options will require new points.
var requiresNewPoints = Dygraph.isPixelChangingOptionList(this.attr_("labels"), attrs);
- Dygraph.update(this.user_attrs_, attrs);
+ Dygraph.updateDeep(this.user_attrs_, attrs);
if (attrs['file']) {
this.file_ = attrs['file'];