| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- import { d3, initChart } from './c3-helper'
- describe('c3 api.x', function() {
- 'use strict'
- var chart
- var args = {
- data: {
- x: 'x',
- columns: [
- ['x', 10, 30, 45, 50, 70, 100],
- ['data1', 30, 200, 100, 400, 150, 250],
- ['data2', 20, 180, 240, 100, 190]
- ]
- }
- }
- beforeEach(function(done) {
- chart = initChart(chart, args, done)
- })
- it('should return initial ticks for axis x', function() {
- var expectedValues = [10, 30, 45, 50, 70, 100]
- d3.select('.c3-axis-x')
- .selectAll('g.tick')
- .each(function(d, i) {
- var text = d3
- .select(this)
- .select('text')
- .text()
- expect(+text).toBe(expectedValues[i])
- })
- })
- it('should return new ticks for axis x after calling chart.x', function() {
- var expectedValues = [16, 26, 55, 60, 75, 90]
- chart.x(expectedValues)
- d3.select('.c3-axis-x')
- .selectAll('g.tick')
- .each(function(d, i) {
- var text = d3
- .select(this)
- .select('text')
- .text()
- expect(+text).toBe(expectedValues[i])
- })
- })
- })
- describe('c3 api.xs', function() {
- 'use strict'
- var chart
- var args = {
- data: {
- xs: {
- data1: 'x1',
- data2: 'x2'
- },
- columns: [
- ['x1', 10, 30, 50, 70, 90, 110],
- ['x2', 20, 40, 60, 80, 100],
- ['data1', 30, 200, 100, 400, 150, 250],
- ['data2', 20, 180, 240, 100, 190]
- ]
- }
- }
- beforeEach(function(done) {
- chart = initChart(chart, args, done)
- })
- it('should return initial ticks for axis x', function() {
- var expectedValues = [
- '10',
- '20',
- '30',
- '40',
- '50',
- '60',
- '70',
- '80',
- '90',
- '100',
- '110'
- ]
- d3.select('.c3-axis-x')
- .selectAll('g.tick')
- .each(function(d, i) {
- var text = d3
- .select(this)
- .select('text')
- .text()
- expect(text).toBe(expectedValues[i])
- })
- })
- it('should return new ticks for axis x after calling chart.xs', function() {
- var expectedValues = [
- '15',
- '25',
- '35',
- '45',
- '55',
- '65',
- '75',
- '85',
- '95',
- '105',
- '115'
- ]
- chart.xs({
- data1: [15, 35, 55, 75, 95, 115],
- data2: [25, 45, 65, 85, 105]
- })
- d3.select('.c3-axis-x')
- .selectAll('g.tick')
- .each(function(d, i) {
- var text = d3
- .select(this)
- .select('text')
- .text()
- expect(text).toBe(expectedValues[i])
- })
- })
- })
|