Skip to content

Commit

Permalink
render 0 in ct:value attribute for line graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
psalaets authored and gionkunz committed Feb 21, 2016
1 parent ff6bdf1 commit 83d55b3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/scripts/charts/line.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@
y2: pathElement.y
}, options.classNames.point).attr({
'value': [pathElement.data.value.x, pathElement.data.value.y].filter(function(v) {
return v;
return v || v === 0;
}).join(','),
'meta': pathElement.data.meta
}, Chartist.xmlNs.uri);
Expand Down
46 changes: 46 additions & 0 deletions test/spec/spec-line-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,52 @@ describe('Line chart tests', function () {

});

describe('ct:value attribute', function () {
it('should contain x and y value for each datapoint', function (done) {
jasmine.getFixtures().set('<div class="ct-chart ct-golden-section"></div>');

var chart = new Chartist.Line('.ct-chart', {
series: [[
{x: 1, y: 2},
{x: 3, y: 4}
]]
}, {
axisX: {
type: Chartist.FixedScaleAxis
}
});

chart.on('created', function () {
expect($('.ct-point').eq(0).attr('ct:value')).toEqual('1,2');
expect($('.ct-point').eq(1).attr('ct:value')).toEqual('3,4');
done();
});
});

it('should render values that are zero', function (done) {
jasmine.getFixtures().set('<div class="ct-chart ct-golden-section"></div>');

var chart = new Chartist.Line('.ct-chart', {
series: [[
{x: 0, y: 1},
{x: 1, y: 0},
{x: 0, y: 0}
]]
}, {
axisX: {
type: Chartist.FixedScaleAxis
}
});

chart.on('created', function () {
expect($('.ct-point').eq(0).attr('ct:value')).toEqual('0,1');
expect($('.ct-point').eq(1).attr('ct:value')).toEqual('1,0');
expect($('.ct-point').eq(2).attr('ct:value')).toEqual('0,0');
done();
});
});
});

describe('Meta data tests', function () {
it('should render meta data correctly with mixed value array', function (done) {
jasmine.getFixtures().set('<div class="ct-chart ct-golden-section"></div>');
Expand Down

0 comments on commit 83d55b3

Please sign in to comment.