Skip to content

Commit

Permalink
Fix issue speced#332
Browse files Browse the repository at this point in the history
  • Loading branch information
almossawi committed Jan 20, 2015
1 parent 849f854 commit 62e3c9a
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 8 deletions.
7 changes: 4 additions & 3 deletions dist/metricsgraphics.js
Original file line number Diff line number Diff line change
Expand Up @@ -1906,9 +1906,11 @@
var gm;
var gb;

if (args.markers) {
$(args.target).find('svg .mg-markers').remove();
//remove existing markers and baselines
$(args.target).find('svg .mg-markers').remove();
$(args.target).find('svg .mg-baselines').remove();

if (args.markers) {
gm = svg.append('g')
.attr('class', 'mg-markers');

Expand Down Expand Up @@ -1949,7 +1951,6 @@
}

if (args.baselines) {
svg.selectAll('.mg-baselines').remove();
gb = svg.append('g')
.attr('class', 'mg-baselines');

Expand Down
2 changes: 1 addition & 1 deletion dist/metricsgraphics.min.js

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/js/common/markers.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ function markers(args) {
var gm;
var gb;

if (args.markers) {
$(args.target).find('svg .mg-markers').remove();
//remove existing markers and baselines
$(args.target).find('svg .mg-markers').remove();
$(args.target).find('svg .mg-baselines').remove();

if (args.markers) {
gm = svg.append('g')
.attr('class', 'mg-markers');

Expand Down Expand Up @@ -47,7 +49,6 @@ function markers(args) {
}

if (args.baselines) {
svg.selectAll('.mg-baselines').remove();
gb = svg.append('g')
.attr('class', 'mg-baselines');

Expand Down
2 changes: 1 addition & 1 deletion tests/common/init_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test('Charts are plotted correctly when MG is called multiple times on the same
var params_0 = {
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-02'), 'value': 18}]
};

var params = {
Expand Down
50 changes: 50 additions & 0 deletions tests/common/markers_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,53 @@ test('Baseline text is correctly added', function() {
MG.data_graphic(params);
equal(document.querySelectorAll(target + ' .mg-baselines text')[0].textContent, baselines[0].label, 'Baseline text matches specified one');
});

test('When an existing chart is updated with no markers, existing markers are cleared', function() {
var markers = [{
'date': new Date('2014-11-02'),
'label': 'Lorem Ipsum'
}];

var params_0 = {
target: '#qunit-fixture',
data: [{'date': new Date('2014-11-01'), 'value': 12},
{'date': new Date('2014-11-03'), 'value': 18}],
markers: markers
};

var params = {
target: '#qunit-fixture',
data: [{'date': new Date('2014-11-01'), 'value': 14},
{'date': new Date('2014-11-03'), 'value': 20}],
};

MG.data_graphic(params_0);
MG.data_graphic(params);

equal(document.querySelectorAll('.mg-markers').length, 0, 'Old markers were cleared');
});

test('When an existing chart is updated with no baselines, existing baselines are cleared', function() {
var baselines = [{
'value': 10,
'label': 'Lorem Ipsum'
}];

var params_0 = {
target: '#qunit-fixture',
data: [{'date': new Date('2014-11-01'), 'value': 12},
{'date': new Date('2014-11-03'), 'value': 18}],
baselines: baselines
};

var params = {
target: '#qunit-fixture',
data: [{'date': new Date('2014-11-01'), 'value': 14},
{'date': new Date('2014-11-03'), 'value': 20}],
};

MG.data_graphic(params_0);
MG.data_graphic(params);

equal(document.querySelectorAll('.mg-baselines').length, 0, 'Old baselines were cleared');
});

0 comments on commit 62e3c9a

Please sign in to comment.