From b963face863a48bc8d18deb3025a65ad356cc334 Mon Sep 17 00:00:00 2001 From: hamilton Date: Tue, 27 Oct 2015 16:19:05 -0700 Subject: [PATCH] more toward #533 - began adding more tests. Much more to do. --- dist/metricsgraphics.js | 4 ++-- src/js/common/init.js | 4 ++-- tests/common/init_test.js | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/dist/metricsgraphics.js b/dist/metricsgraphics.js index 26084428..3b544f4b 100644 --- a/dist/metricsgraphics.js +++ b/dist/metricsgraphics.js @@ -1920,7 +1920,7 @@ function mg_init_compute_width(args){ // get parent element svg_width = get_width(args.target); } - args.width=svg_width; + args.width = svg_width; } function mg_init_compute_height(args){ @@ -2059,7 +2059,7 @@ function init(args) { mg_is_time_series(args); mg_init_compute_width(args); mg_init_compute_height(args); - + mg_remove_svg_if_chart_type_has_changed(svg, args); svg = mg_add_svg_if_it_doesnt_exist(svg, args); diff --git a/src/js/common/init.js b/src/js/common/init.js index 2bb5752a..b3105a9b 100644 --- a/src/js/common/init.js +++ b/src/js/common/init.js @@ -27,7 +27,7 @@ function mg_init_compute_width(args){ // get parent element svg_width = get_width(args.target); } - args.width=svg_width; + args.width = svg_width; } function mg_init_compute_height(args){ @@ -166,7 +166,7 @@ function init(args) { mg_is_time_series(args); mg_init_compute_width(args); mg_init_compute_height(args); - + mg_remove_svg_if_chart_type_has_changed(svg, args); svg = mg_add_svg_if_it_doesnt_exist(svg, args); diff --git a/tests/common/init_test.js b/tests/common/init_test.js index 2d9f2abc..286a85ba 100644 --- a/tests/common/init_test.js +++ b/tests/common/init_test.js @@ -1,5 +1,40 @@ module('init'); +test('MG properly detects time series vs. not.', function() { + var params1 = { + target: '#qunit-fixture', + data: [{'date': new Date('2014-11-01'), 'value': 12}, + {'date': new Date('2014-11-02'), 'value': 18}], + x_accessor:'date' + }; + + var params2 = { + target: '#qunit-fixture', + data: [{'date': 5434, 'value': 12}, + {'date': 5435, 'value': 18}], + x_accessor:'date' + }; + + var params3 = { + target: '#qunit-fixture', + data: [[{'date': new Date('2014-11-01'), 'value': 12}, + {'date': new Date('2014-11-02'), 'value': 18}], + [{'date': new Date('2014-11-01'), 'value': 32}, + {'date': new Date('2014-11-02'), 'value': 43}]], + x_accessor:'date' + }; + mg_merge_args_with_defaults(params1); + mg_merge_args_with_defaults(params2); + mg_merge_args_with_defaults(params3); + mg_is_time_series(params1); + mg_is_time_series(params2); + mg_is_time_series(params3); + + ok(params1.time_series === true, 'Date-accessed data set is a time series.'); + ok(params2.time_series === false, 'Number-accessed data set is not a time series.'); + ok(params3.time_series === true, 'Nested data set w/ dates detected as time series.'); +}); + test('Chart\'s width is set correctly on subsequent calls to existing chart', function() { var params_0 = { target: '#qunit-fixture',