mirror of https://github.com/masayuki0812/c3.git
michalkop93
10 years ago
11 changed files with 313 additions and 57 deletions
File diff suppressed because one or more lines are too long
@ -0,0 +1,90 @@
|
||||
var describe = window.describe, |
||||
expect = window.expect, |
||||
it = window.it, |
||||
beforeEach = window.beforeEach; |
||||
|
||||
describe('c3 chart axis', function () { |
||||
'use strict'; |
||||
|
||||
var chart, d3; |
||||
|
||||
var args = { |
||||
data: { |
||||
columns: [ |
||||
['data1', 30, 200, 100, 400, 150, 250], |
||||
['data2', 50, 20, 10, 40, 15, 25], |
||||
['data3', 150, 120, 110, 140, 115, 125] |
||||
] |
||||
}, |
||||
axis: { |
||||
y: { |
||||
tick: { |
||||
values: null, |
||||
count: undefined |
||||
} |
||||
}, |
||||
y2: { |
||||
tick: { |
||||
values: null, |
||||
count: undefined |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
|
||||
beforeEach(function () { |
||||
window.initDom(); |
||||
chart = window.c3.generate(args); |
||||
d3 = chart.internal.d3; |
||||
}); |
||||
|
||||
describe('axis.y.tick.count', function () { |
||||
|
||||
var i = 1; |
||||
|
||||
beforeEach(function () { |
||||
args.axis.y.tick.count = i++; |
||||
chart = window.c3.generate(args); |
||||
}); |
||||
|
||||
it('should have only 1 tick on y axis', function () { |
||||
var ticksSize = d3.select('.c3-axis-y').selectAll('g.tick').size(); |
||||
expect(ticksSize).toBe(1); |
||||
}); |
||||
|
||||
it('should have 2 ticks on y axis', function () { |
||||
var ticksSize = d3.select('.c3-axis-y').selectAll('g.tick').size(); |
||||
expect(ticksSize).toBe(2); |
||||
}); |
||||
|
||||
it('should have 3 ticks on y axis', function () { |
||||
var ticksSize = d3.select('.c3-axis-y').selectAll('g.tick').size(); |
||||
expect(ticksSize).toBe(3); |
||||
}); |
||||
|
||||
}); |
||||
|
||||
describe('axis.y.tick.values', function () { |
||||
|
||||
var values = [100, 500]; |
||||
|
||||
beforeEach(function () { |
||||
args.axis.y.tick.values = values; |
||||
chart = window.c3.generate(args); |
||||
}); |
||||
|
||||
it('should have only 2 tick on y axis', function () { |
||||
var ticksSize = d3.select('.c3-axis-y').selectAll('g.tick').size(); |
||||
expect(ticksSize).toBe(2); |
||||
}); |
||||
|
||||
it('should have specified tick texts', function () { |
||||
d3.select('.c3-axis-y').selectAll('g.tick').each(function (d, i) { |
||||
var text = d3.select(this).select('text').text(); |
||||
expect(+text).toBe(values[i]); |
||||
}); |
||||
}); |
||||
|
||||
}); |
||||
|
||||
}); |
@ -0,0 +1,100 @@
|
||||
var describe = window.describe, |
||||
expect = window.expect, |
||||
it = window.it, |
||||
beforeEach = window.beforeEach; |
||||
|
||||
var initDom = window.initDom, |
||||
setEvent = window.setEvent; |
||||
|
||||
describe('c3 chart shape bar', function () { |
||||
'use strict'; |
||||
|
||||
var chart, d3; |
||||
|
||||
var args = { |
||||
data: { |
||||
columns: [ |
||||
['data1', 30, 200, 100, 400, -150, 250], |
||||
['data2', 50, 20, 10, 40, 15, 25], |
||||
['data3', -150, 120, 110, 140, 115, 125] |
||||
], |
||||
type: 'bar' |
||||
}, |
||||
axis: { |
||||
rotated: false |
||||
} |
||||
}; |
||||
|
||||
beforeEach(function (done) { |
||||
if (typeof chart === 'undefined') { |
||||
initDom(); |
||||
} |
||||
chart = window.c3.generate(args); |
||||
d3 = chart.internal.d3; |
||||
chart.internal.d3.select('.jasmine_html-reporter').style('display', 'none'); |
||||
|
||||
window.setTimeout(function () { |
||||
done(); |
||||
}, 10); |
||||
}); |
||||
|
||||
describe('internal.isWithinBar', function () { |
||||
|
||||
describe('with normal axis', function () { |
||||
|
||||
it('should not be within bar', function () { |
||||
var bar = d3.select('.c3-target-data1 .c3-bar-0').node(); |
||||
setEvent(chart, 0, 0); |
||||
expect(chart.internal.isWithinBar(bar)).toBeFalsy(); |
||||
}); |
||||
|
||||
it('should be within bar', function () { |
||||
var bar = d3.select('.c3-target-data1 .c3-bar-0').node(); |
||||
setEvent(chart, 31, 280); |
||||
expect(chart.internal.isWithinBar(bar)).toBeTruthy(); |
||||
}); |
||||
|
||||
it('should not be within bar of negative value', function () { |
||||
var bar = d3.select('.c3-target-data3 .c3-bar-0').node(); |
||||
setEvent(chart, 68, 280); |
||||
expect(chart.internal.isWithinBar(bar)).toBeFalsy(); |
||||
}); |
||||
|
||||
it('should be within bar of negative value', function () { |
||||
var bar = d3.select('.c3-target-data3 .c3-bar-0').node(); |
||||
setEvent(chart, 68, 350); |
||||
expect(chart.internal.isWithinBar(bar)).toBeTruthy(); |
||||
}); |
||||
|
||||
}); |
||||
|
||||
describe('with rotated axis', function () { |
||||
|
||||
it('should change the chart as axis rotated', function () { |
||||
args.axis.rotated = true; |
||||
expect(true).toBeTruthy(); |
||||
}); |
||||
|
||||
it('should not be within bar', function () { |
||||
var bar = d3.select('.c3-target-data1 .c3-bar-0').node(); |
||||
setEvent(chart, 0, 0); |
||||
expect(chart.internal.isWithinBar(bar)).toBeFalsy(); |
||||
}); |
||||
|
||||
it('should be within bar', function () { |
||||
var bar = d3.select('.c3-target-data1 .c3-bar-0').node(); |
||||
setEvent(chart, 190, 20); |
||||
expect(chart.internal.isWithinBar(bar)).toBeTruthy(); |
||||
}); |
||||
|
||||
it('should be within bar of negative value', function () { |
||||
var bar = d3.select('.c3-target-data3 .c3-bar-0').node(); |
||||
setEvent(chart, 68, 50); |
||||
expect(chart.internal.isWithinBar(bar)).toBeTruthy(); |
||||
}); |
||||
|
||||
}); |
||||
|
||||
}); |
||||
|
||||
}); |
Loading…
Reference in new issue