Skip to content

Commit

Permalink
Should change scale type from time to period when [tickPeriod] is spe…
Browse files Browse the repository at this point in the history
…cified
  • Loading branch information
vladminsky committed May 17, 2016
1 parent 9125d10 commit 7166c23
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/spec-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ export class SpecConverter {

if (guide.hasOwnProperty('tickPeriod')) {
item.period = guide.tickPeriod;
item.type = 'period';
}

item.fitToFrameByDims = guide.fitToFrameByDims;
Expand Down
46 changes: 46 additions & 0 deletions test/spec-converter.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
define(function (require) {
var tauCharts = require('src/tau.charts');
var expect = require('chai').expect;
var testUtils = require('testUtils');
var Converter = require('src/spec-converter').SpecConverter;
Expand Down Expand Up @@ -344,5 +345,50 @@ define(function (require) {
expect(JSON.stringify(spec.unit)).to.deep.equal(JSON.stringify(x.unit));
expect(JSON.stringify(spec.scales)).to.deep.equal(JSON.stringify(x.scales));
});

it('should change scale type from time to period when tickPeriod is specified', function () {

var c1 = new tauCharts.Chart({
type: 'bar',
x: 'x1',
y: 'y1',
data: [
{x1: new Date(), y1: 1}
]
});

var spec1 = c1.getSpec();

var x1TimeScale = Object
.keys(spec1.scales)
.map((s) => spec1.scales[s])
.filter((s) => s.dim === 'x1')
[0];

expect(x1TimeScale.type).to.equals('time');

var c2 = new tauCharts.Chart({
type: 'bar',
x: 'x1',
y: 'y1',
guide: {
x: {tickPeriod: 'month'}
},
data: [
{x1: new Date(), y1: 1}
]
});

var spec2 = c2.getSpec();

var x1PeriodScale = Object
.keys(spec2.scales)
.map((s) => spec2.scales[s])
.filter((s) => s.dim === 'x1')
[0];

expect(x1PeriodScale.type).to.equals('period');
expect(x1PeriodScale.period).to.equals('month');
});
});
});

0 comments on commit 7166c23

Please sign in to comment.