| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566 |
- import { d3, initChart } from './c3-helper'
- describe('load without data', function() {
- var chart, args
- beforeAll(function() {
- args = {
- data: {}
- }
- })
- it('throws when data is an empty object', () => {
- expect(() => initChart(chart, args, () => {})).toThrowError(
- Error,
- /url or json or rows or columns is required/
- )
- })
- })
- describe('c3 chart data', function() {
- 'use strict'
- var chart, args
- beforeEach(function(done) {
- chart = initChart(chart, args, done)
- })
- describe('load json', function() {
- beforeAll(function() {
- args = {
- data: {
- json: {
- data1: [30, 20, 50],
- data2: [200, 130, 90]
- }
- }
- }
- })
- it('should draw correctly', function() {
- var expectedCx = [6, 299, 593],
- expectedCy = [371, 391, 332]
- d3.selectAll('.c3-circles-data1 .c3-circle').each(function(d, i) {
- var circle = d3.select(this)
- expect(+circle.attr('cx')).toBeCloseTo(expectedCx[i], 0)
- expect(+circle.attr('cy')).toBeCloseTo(expectedCy[i], 0)
- })
- })
- describe('more data', function() {
- beforeAll(function() {
- args = {
- data: {
- json: [
- {
- date: '2014-06-03',
- '443': '3000',
- '995': '500'
- },
- {
- date: '2014-06-04',
- '443': '1000'
- },
- {
- date: '2014-06-05',
- '443': '5000',
- '995': '1000'
- }
- ],
- keys: {
- x: 'date',
- value: ['443', '995']
- }
- },
- axis: {
- x: {
- type: 'category'
- }
- }
- }
- })
- it('should draw correctly', function() {
- var expectedCx = { 443: [98, 294, 490], 995: [98, 294, 490] },
- expectedCy = { 443: [194, 351, 36], 995: [391, 430, 351] }
- d3.selectAll('.c3-circles-443 .c3-circle').each(function(d, i) {
- var circle = d3.select(this)
- expect(+circle.attr('cx')).toBeCloseTo(expectedCx[443][i], 0)
- expect(+circle.attr('cy')).toBeCloseTo(expectedCy[443][i], 0)
- })
- d3.selectAll('.c3-circles-995 .c3-circle').each(function(d, i) {
- var circle = d3.select(this)
- expect(+circle.attr('cx')).toBeCloseTo(expectedCx[995][i], 0)
- expect(+circle.attr('cy')).toBeCloseTo(expectedCy[995][i], 0)
- })
- })
- })
- describe('with nested JSON args', function() {
- beforeAll(function() {
- args = {
- data: {
- json: [
- {
- date: '2014-06-03',
- '443': '3000',
- '995': { '996': '500' },
- '112': ['600'],
- '223': [{ '224': '100' }],
- '334': [[], [{ '335': '300' }]],
- '556': { '557': { '558': ['1000'] } },
- '778.889': '700'
- },
- {
- date: '2014-06-04',
- '443': '1000',
- '112': ['700'],
- '223': [{ '224': '200' }],
- '556': { '557': { '558': ['2000'] } },
- '778.889': '300'
- },
- {
- date: '2014-06-05',
- '995': { '996': '1000' },
- '112': ['800'],
- '223': [{ '224': '300' }],
- '443': '5000',
- '334': [[], [{ '335': '500' }]],
- '556': { '557': { '558': ['3000'] } },
- '778.889': '800'
- }
- ],
- keys: {
- x: 'date',
- value: [
- '443',
- '995.996',
- '112[0]',
- '223[0].224',
- '334[1][0].335',
- '556.557.558[0]',
- '778.889'
- ]
- }
- },
- axis: {
- x: {
- type: 'category'
- }
- }
- }
- })
- it('should draw nested JSON correctly', function() {
- var expectedCx = [98, 294, 490],
- expectedCy = {
- 443: [181, 326, 36],
- 995: [362, 398, 326],
- 112: [354, 347, 340],
- 223: [391, 383, 376],
- 334: [376, 398, 362],
- 556: [326, 253, 181],
- '778.889': [347, 376, 340]
- }
- d3.selectAll('.c3-circles-443 .c3-circle').each(function(d, i) {
- var circle = d3.select(this)
- expect(+circle.attr('cx')).toBeCloseTo(expectedCx[i], 0)
- expect(+circle.attr('cy')).toBeCloseTo(expectedCy[443][i], 0)
- })
- d3.selectAll('.c3-circles-995-996 .c3-circle').each(function(d, i) {
- var circle = d3.select(this)
- expect(+circle.attr('cx')).toBeCloseTo(expectedCx[i], 0)
- expect(+circle.attr('cy')).toBeCloseTo(expectedCy[995][i], 0)
- })
- d3.selectAll('.c3-circles-112-0- .c3-circle').each(function(d, i) {
- var circle = d3.select(this)
- expect(+circle.attr('cx')).toBeCloseTo(expectedCx[i], 0)
- expect(+circle.attr('cy')).toBeCloseTo(expectedCy[112][i], 0)
- })
- d3.selectAll('.c3-circles-223-0--224 .c3-circle').each(function(d, i) {
- var circle = d3.select(this)
- expect(+circle.attr('cx')).toBeCloseTo(expectedCx[i], 0)
- expect(+circle.attr('cy')).toBeCloseTo(expectedCy[223][i], 0)
- })
- d3.selectAll('.c3-circles-334-1--0--335 .c3-circle').each(function(
- d,
- i
- ) {
- var circle = d3.select(this)
- expect(+circle.attr('cx')).toBeCloseTo(expectedCx[i], 0)
- expect(+circle.attr('cy')).toBeCloseTo(expectedCy[334][i], 0)
- })
- d3.selectAll('.c3-circles-556-557-558-0- .c3-circle').each(function(
- d,
- i
- ) {
- var circle = d3.select(this)
- expect(+circle.attr('cx')).toBeCloseTo(expectedCx[i], 0)
- expect(+circle.attr('cy')).toBeCloseTo(expectedCy[556][i], 0)
- })
- d3.selectAll('.c3-circles-778-889 .c3-circle').each(function(d, i) {
- var circle = d3.select(this)
- expect(+circle.attr('cx')).toBeCloseTo(expectedCx[i], 0)
- expect(+circle.attr('cy')).toBeCloseTo(expectedCy['778.889'][i], 0)
- })
- })
- })
- })
- describe('load rows', function() {
- beforeAll(function() {
- args = {
- data: {
- rows: [
- ['data1', 'data2', 'data3'],
- [90, 120, 300],
- [40, 160, 240],
- [50, 200, 290],
- [120, 160, 230],
- [80, 130, 300],
- [90, 220, 320]
- ]
- }
- }
- })
- it('should draw correctly', function() {
- var expectedCx = [6, 124, 241, 358, 475, 593],
- expectedCy = [327, 391, 378, 289, 340, 327]
- d3.selectAll('.c3-circles-data1 .c3-circle').each(function(d, i) {
- var circle = d3.select(this)
- expect(+circle.attr('cx')).toBeCloseTo(expectedCx[i], 0)
- expect(+circle.attr('cy')).toBeCloseTo(expectedCy[i], 0)
- })
- })
- })
- describe('function in data.order', function() {
- beforeAll(function() {
- args = {
- data: {
- columns: [
- ['data1', 30, 200, 100, 400, 150, 250],
- ['data2', 50, 20, 10, 40, 15, 25],
- ['data3', 150, 120, 110, 140, 115, 125]
- ],
- order: function() {
- return 0
- }
- }
- }
- })
- it('should return false in isOrderAsc and isOrderDesc functions', function() {
- expect(chart.internal.isOrderAsc() || chart.internal.isOrderDesc()).toBe(
- false
- )
- })
- })
- describe('addHiddenTargetIds if not already hidden', function() {
- it('should update args', function() {
- args = {
- data: {
- columns: [
- ['data1', 30, 200, 100, 400, 150, 250],
- ['data2', 150, 120, 110, 140, 115, 125]
- ]
- }
- }
- expect(true).toBeTruthy()
- })
- it('length of hiddenTargetIds should not change if same key added twice', function() {
- chart.internal.addHiddenTargetIds('data1')
- expect(chart.internal.hiddenTargetIds.length).toBe(1)
- chart.internal.addHiddenTargetIds('data1')
- expect(chart.internal.hiddenTargetIds.length).toBe(1)
- chart.hide('data1')
- expect(chart.internal.hiddenTargetIds.length).toBe(1)
- chart.internal.addHiddenTargetIds('data2')
- expect(chart.internal.hiddenTargetIds.length).toBe(2)
- chart.show()
- chart.hide(['data1', 'data2'])
- expect(chart.internal.hiddenTargetIds.length).toBe(2)
- chart.show()
- chart.hide()
- expect(chart.internal.hiddenTargetIds.length).toBe(2)
- })
- })
- describe('addHiddenLegendIds if not already hidden', function() {
- it('should update args', function() {
- args = {
- data: {
- columns: [
- ['data1', 30, 200, 100, 400, 150, 250],
- ['data2', 150, 120, 110, 140, 115, 125]
- ]
- }
- }
- expect(true).toBeTruthy()
- })
- it('length of hiddenLegendIds should not change if same key added twice', function() {
- chart.internal.addHiddenLegendIds('data1')
- expect(chart.internal.hiddenLegendIds.length).toBe(1)
- chart.internal.addHiddenLegendIds('data1')
- expect(chart.internal.hiddenLegendIds.length).toBe(1)
- chart.hide('data1', { withLegend: true })
- expect(chart.internal.hiddenLegendIds.length).toBe(1)
- chart.hide('data2', { withLegend: true })
- expect(chart.internal.hiddenLegendIds.length).toBe(2)
- chart.show(['data1', 'data2'], { withLegend: true })
- chart.hide(['data1', 'data2'], { withLegend: true })
- expect(chart.internal.hiddenLegendIds.length).toBe(2)
- })
- })
- describe('data.xs', function() {
- beforeAll(function() {
- args = {
- data: {
- columns: [
- ['data1', 30, 200, 100, 400, 150, 250],
- ['data2', 50, 20, 10, 40, 15, 25],
- ['data3', 150, 120, 110, 140, 115, 125]
- ]
- }
- }
- })
- describe('normal x', function() {
- it('should have correct number of xs for each', function() {
- expect(Object.keys(chart.internal.data.xs).length).toBe(3)
- expect(chart.internal.data.xs.data1.length).toBe(6)
- expect(chart.internal.data.xs.data2.length).toBe(6)
- expect(chart.internal.data.xs.data3.length).toBe(6)
- })
- it('should have integer index as x', function() {
- for (var i = 0; i < chart.internal.data.xs.data3.length; i++) {
- expect(chart.internal.data.xs.data1[i]).toBe(i)
- expect(chart.internal.data.xs.data2[i]).toBe(i)
- expect(chart.internal.data.xs.data3[i]).toBe(i)
- }
- })
- })
- describe('timeseries x', function() {
- describe('without xFormat', function() {
- beforeAll(function() {
- args = {
- data: {
- x: 'date',
- columns: [
- ['date', '2013-01-01', '2013-01-02', '2013-01-03'],
- ['data1', 30, 200, 100],
- ['data2', 130, 300, 200]
- ]
- },
- axis: {
- x: {
- type: 'timeseries'
- }
- }
- }
- })
- it('should have correct number of xs', function() {
- expect(Object.keys(chart.internal.data.xs).length).toBe(2)
- expect(chart.internal.data.xs.data1.length).toBe(3)
- expect(chart.internal.data.xs.data2.length).toBe(3)
- })
- it('should have Date object as x', function() {
- var xs = chart.internal.data.xs
- expect(+xs.data1[0]).toBe(+new Date(2013, 0, 1, 0, 0, 0))
- expect(+xs.data1[1]).toBe(+new Date(2013, 0, 2, 0, 0, 0))
- expect(+xs.data1[2]).toBe(+new Date(2013, 0, 3, 0, 0, 0))
- expect(+xs.data2[0]).toBe(+new Date(2013, 0, 1, 0, 0, 0))
- expect(+xs.data2[1]).toBe(+new Date(2013, 0, 2, 0, 0, 0))
- expect(+xs.data2[2]).toBe(+new Date(2013, 0, 3, 0, 0, 0))
- })
- })
- describe('with xFormat', function() {
- describe('timeseries x with xFormat', function() {
- beforeAll(function() {
- args = {
- data: {
- x: 'date',
- xFormat: '%Y%m%d',
- columns: [
- ['date', '20130101', '20130102', '20130103'],
- ['data1', 30, 200, 100],
- ['data2', 130, 300, 200]
- ]
- },
- axis: {
- x: {
- type: 'timeseries'
- }
- }
- }
- })
- it('should have correct number of xs', function() {
- expect(Object.keys(chart.internal.data.xs).length).toBe(2)
- expect(chart.internal.data.xs.data1.length).toBe(3)
- expect(chart.internal.data.xs.data2.length).toBe(3)
- })
- it('should have Date object as x', function() {
- var xs = chart.internal.data.xs
- expect(+xs.data1[0]).toBe(+new Date(2013, 0, 1, 0, 0, 0))
- expect(+xs.data1[1]).toBe(+new Date(2013, 0, 2, 0, 0, 0))
- expect(+xs.data1[2]).toBe(+new Date(2013, 0, 3, 0, 0, 0))
- expect(+xs.data2[0]).toBe(+new Date(2013, 0, 1, 0, 0, 0))
- expect(+xs.data2[1]).toBe(+new Date(2013, 0, 2, 0, 0, 0))
- expect(+xs.data2[2]).toBe(+new Date(2013, 0, 3, 0, 0, 0))
- })
- })
- })
- })
- describe('milliseconds timeseries x', function() {
- describe('as date string', function() {
- beforeAll(function() {
- args = {
- data: {
- x: 'date',
- xFormat: '%Y-%m-%d %H:%M:%S.%L',
- columns: [
- ['date', '2014-05-20 17:25:00.123', '2014-05-20 17:30:00.345'],
- ['data1', 30, 200],
- ['data2', 130, 300]
- ]
- },
- axis: {
- x: {
- type: 'timeseries',
- tick: {
- format: '%Y-%m-%d %H:%M:%S.%L',
- multiline: false
- }
- }
- }
- }
- })
- it('should have correct number of xs', function() {
- expect(Object.keys(chart.internal.data.xs).length).toBe(2)
- expect(chart.internal.data.xs.data1.length).toBe(2)
- expect(chart.internal.data.xs.data2.length).toBe(2)
- })
- it('should have Date object as x', function() {
- var xs = chart.internal.data.xs
- expect(+xs.data1[0]).toBe(+new Date(2014, 4, 20, 17, 25, 0, 123))
- expect(+xs.data1[1]).toBe(+new Date(2014, 4, 20, 17, 30, 0, 345))
- expect(+xs.data2[0]).toBe(+new Date(2014, 4, 20, 17, 25, 0, 123))
- expect(+xs.data2[1]).toBe(+new Date(2014, 4, 20, 17, 30, 0, 345))
- })
- it('should have milliseconds tick format', function() {
- var expected = ['2014-05-20 17:25:00.123', '2014-05-20 17:30:00.345']
- chart.internal.main
- .selectAll('.c3-axis-x g.tick text')
- .each(function(d, i) {
- expect(d3.select(this).text()).toBe(expected[i])
- })
- })
- })
- describe('as unixtime number', function() {
- beforeAll(function() {
- args = {
- data: {
- x: 'date',
- columns: [
- ['date', 1417622461123, 1417622522345],
- ['data1', 30, 200],
- ['data2', 130, 300]
- ]
- },
- axis: {
- x: {
- type: 'timeseries',
- tick: {
- format: '%Y-%m-%d %H:%M:%S.%L'
- }
- }
- }
- }
- })
- it('should have correct number of xs', function() {
- expect(Object.keys(chart.internal.data.xs).length).toBe(2)
- expect(chart.internal.data.xs.data1.length).toBe(2)
- expect(chart.internal.data.xs.data2.length).toBe(2)
- })
- it('should have Date object as x', function() {
- var xs = chart.internal.data.xs
- expect(+xs.data1[0]).toBe(1417622461123)
- expect(+xs.data1[1]).toBe(1417622522345)
- expect(+xs.data2[0]).toBe(1417622461123)
- expect(+xs.data2[1]).toBe(1417622522345)
- })
- })
- })
- })
- describe('data.label', function() {
- describe('on line chart', function() {
- beforeAll(function() {
- args = {
- data: {
- columns: [
- ['data1', 1030, 2200, 2100],
- ['data2', 1150, 2010, 1200],
- ['data3', -1150, -2010, -1200],
- ['data4', -1030, -2200, -2100]
- ],
- type: 'line',
- labels: true
- }
- }
- })
- it('should locate data labels in correct position', function() {
- var expectedTextY = {
- data1: [128, 38, 46],
- data2: [119, 53, 115],
- data3: [311, 377, 315],
- data4: [302, 392, 384]
- }
- var expectedTextX = {
- data1: [6, 294, 583],
- data2: [6, 294, 583],
- data3: [6, 294, 583],
- data4: [6, 294, 583]
- }
- Object.keys(expectedTextY).forEach(function(key) {
- d3.selectAll('.c3-texts-' + key + ' text.c3-text').each(function(
- d,
- i
- ) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedTextY[key][i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedTextX[key][i], -2)
- })
- })
- })
- describe('with stacked', function() {
- beforeAll(function() {
- args.data.groups = [
- ['data1', 'data2'],
- ['data3', 'data4']
- ]
- })
- it('should locate data labels in correct position', function() {
- var expectedTextY = {
- data1: [120, 38, 75],
- data2: [161, 127, 159],
- data3: [269, 303, 271],
- data4: [310, 392, 355]
- }
- var expectedTextX = {
- data1: [6, 294, 583],
- data2: [6, 294, 583],
- data3: [6, 294, 583],
- data4: [6, 294, 583]
- }
- Object.keys(expectedTextY).forEach(function(key) {
- d3.selectAll('.c3-texts-' + key + ' text.c3-text').each(function(
- d,
- i
- ) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedTextY[key][i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedTextX[key][i], -2)
- })
- })
- })
- })
- })
- describe('on area chart', function() {
- beforeAll(function() {
- args = {
- data: {
- columns: [
- ['data1', 1030, 2200, 2100],
- ['data2', 1150, 2010, 1200],
- ['data3', -1150, -2010, -1200],
- ['data4', -1030, -2200, -2100]
- ],
- type: 'area',
- labels: true
- }
- }
- })
- it('should locate data labels in correct position', function() {
- var expectedTextY = {
- data1: [128, 38, 46],
- data2: [119, 53, 115],
- data3: [311, 377, 315],
- data4: [302, 392, 384]
- }
- var expectedTextX = {
- data1: [6, 294, 583],
- data2: [6, 294, 583],
- data3: [6, 294, 583],
- data4: [6, 294, 583]
- }
- Object.keys(expectedTextY).forEach(function(key) {
- d3.selectAll('.c3-texts-' + key + ' text.c3-text').each(function(
- d,
- i
- ) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedTextY[key][i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedTextX[key][i], -2)
- })
- })
- })
- describe('with stacked', function() {
- beforeAll(function() {
- args.data.groups = [
- ['data1', 'data2'],
- ['data3', 'data4']
- ]
- })
- it('should locate data labels in correct position', function() {
- var expectedTextY = {
- data1: [120, 38, 75],
- data2: [161, 127, 159],
- data3: [269, 303, 271],
- data4: [310, 392, 355]
- }
- var expectedTextX = {
- data1: [6, 294, 583],
- data2: [6, 294, 583],
- data3: [6, 294, 583],
- data4: [6, 294, 583]
- }
- Object.keys(expectedTextY).forEach(function(key) {
- d3.selectAll('.c3-texts-' + key + ' text.c3-text').each(function(
- d,
- i
- ) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedTextY[key][i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedTextX[key][i], -2)
- })
- })
- })
- })
- })
- describe('on bar chart', function() {
- beforeAll(function() {
- args = {
- data: {
- columns: [
- ['data1', 1030, 2200, 2100],
- ['data2', 1150, 2010, 1200],
- ['data3', -1150, -2010, -1200],
- ['data4', -1030, -2200, -2100]
- ],
- type: 'bar',
- labels: true
- }
- }
- })
- it('should locate data labels in correct position', function() {
- var expectedTextY = {
- data1: [128, 38, 46],
- data2: [119, 53, 115],
- data3: [311, 377, 315],
- data4: [302, 392, 384]
- }
- var expectedTextX = {
- data1: [53, 249, 445],
- data2: [83, 279, 475],
- data3: [112, 308, 504],
- data4: [142, 338, 534]
- }
- Object.keys(expectedTextY).forEach(function(key) {
- d3.selectAll('.c3-texts-' + key + ' text.c3-text').each(function(
- d,
- i
- ) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedTextY[key][i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedTextX[key][i], -2)
- })
- })
- })
- describe('with stacked', function() {
- beforeAll(function() {
- args.data.groups = [
- ['data1', 'data2'],
- ['data3', 'data4']
- ]
- })
- it('should locate data labels in correct position', function() {
- var expectedTextY = {
- data1: [120, 38, 75],
- data2: [161, 127, 159],
- data3: [269, 303, 271],
- data4: [310, 392, 355]
- }
- var expectedTextX = {
- data1: [68.6, 264, 460],
- data2: [68.6, 264, 460],
- data3: [127, 323, 519],
- data4: [127, 323, 519]
- }
- Object.keys(expectedTextY).forEach(function(key) {
- d3.selectAll('.c3-texts-' + key + ' text.c3-text').each(function(
- d,
- i
- ) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedTextY[key][i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedTextX[key][i], -2)
- })
- })
- })
- })
- })
- describe('for all targets', function() {
- describe('with data label for all data', function() {
- beforeAll(function() {
- args = {
- data: {
- columns: [
- ['data1', 100, 200, 100, 400, 150, 250],
- ['data2', 10, 20, 10, 40, 15, 25],
- ['data3', 1000, 2000, 1000, 4000, 1500, 2500]
- ],
- labels: true
- }
- }
- })
- it('should have data labels on all data', function() {
- d3.selectAll('.c3-texts-data1 text').each(function(d, i) {
- expect(d3.select(this).text()).toBe(
- args.data.columns[0][i + 1] + ''
- )
- })
- d3.selectAll('.c3-texts-data2 text').each(function(d, i) {
- expect(d3.select(this).text()).toBe(
- args.data.columns[1][i + 1] + ''
- )
- })
- d3.selectAll('.c3-texts-data3 text').each(function(d, i) {
- expect(d3.select(this).text()).toBe(
- args.data.columns[2][i + 1] + ''
- )
- })
- })
- })
- })
- describe('for each target', function() {
- describe('as true', function() {
- describe('with data label for only data1', function() {
- beforeAll(function() {
- args = {
- data: {
- columns: [
- ['data1', 100, 200, 100, 400, 150, 250],
- ['data2', 10, 20, 10, 40, 15, 25],
- ['data3', 1000, 2000, 1000, 4000, 1500, 2500]
- ],
- labels: {
- format: {
- data1: true
- }
- }
- }
- }
- })
- it('should have data labels on all data', function() {
- d3.selectAll('.c3-texts-data1 text').each(function(d, i) {
- expect(d3.select(this).text()).toBe(
- args.data.columns[0][i + 1] + ''
- )
- })
- d3.selectAll('.c3-texts-data2 text').each(function() {
- expect(d3.select(this).text()).toBe('')
- })
- d3.selectAll('.c3-texts-data3 text').each(function() {
- expect(d3.select(this).text()).toBe('')
- })
- })
- })
- })
- describe('as function', function() {
- describe('with data label for only data1', function() {
- beforeAll(function() {
- args = {
- data: {
- columns: [
- ['data1', 100, 200, 100, 400, 150, 250],
- ['data2', 10, 20, 10, 40, 15, 25],
- ['data3', 1000, 2000, 1000, 4000, 1500, 2500]
- ],
- labels: {
- format: {
- data1: d3.format('$')
- }
- }
- }
- }
- })
- it('should have data labels on all data', function() {
- d3.selectAll('.c3-texts-data1 text').each(function(d, i) {
- expect(d3.select(this).text()).toBe(
- '$' + args.data.columns[0][i + 1]
- )
- })
- d3.selectAll('.c3-texts-data2 text').each(function() {
- expect(d3.select(this).text()).toBe('')
- })
- d3.selectAll('.c3-texts-data3 text').each(function() {
- expect(d3.select(this).text()).toBe('')
- })
- })
- })
- })
- })
- describe('with small values', function() {
- describe('with data label', function() {
- beforeAll(function() {
- args = {
- data: {
- columns: [['data1', 0.03, 0.2, 0.1, 0.4, 0.15, 0.25]],
- labels: true
- }
- }
- })
- it('should have proper y domain', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(-0.02)
- expect(domain[1]).toBeCloseTo(0.45)
- })
- })
- })
- describe('with positive values and null', function() {
- describe('on not rotated axis', function() {
- beforeAll(function() {
- args = {
- data: {
- columns: [['data1', 190, 200, 190, null]],
- type: 'bar',
- labels: {
- format: function(v) {
- if (v === null) {
- return 'Not Applicable'
- }
- return d3.format('$')(v)
- }
- }
- }
- }
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(0, -1)
- expect(domain[1]).toBeCloseTo(227, -1)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [67, 49, 67, 423],
- expectedXs = [74, 221, 368, 515]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- describe('data type line', function() {
- beforeAll(function() {
- args.data.type = 'line'
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(189, -1)
- expect(domain[1]).toBeCloseTo(201, -1)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [375, 40, 375, 422],
- expectedXs = [6, 198, 391, 583]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- })
- describe('on rotated axis', function() {
- describe('data type bar', function() {
- beforeAll(function() {
- args.data.type = 'bar'
- args.axis = {
- rotated: true
- }
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(0, -1)
- expect(domain[1]).toBeCloseTo(231, -1)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [57, 163, 269, 375],
- expectedXs = [490, 516, 490, 4]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- describe('data type line', function() {
- beforeAll(function() {
- args.data.type = 'line'
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(188, -1)
- expect(domain[1]).toBeCloseTo(202, -1)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [9, 147, 286, 424],
- expectedXs = [76, 526, 76, 4]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- })
- })
- describe('with negative values and null', function() {
- describe('on not rotated axis', function() {
- describe('type bar', function() {
- beforeAll(function() {
- args = {
- data: {
- columns: [['data1', -190, 0, -190, null]],
- type: 'bar',
- labels: {
- format: function(v) {
- if (v === null) {
- return 'Not Applicable'
- }
- return d3.format('$')(v)
- }
- }
- }
- }
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(-215, -1)
- expect(domain[1]).toBeCloseTo(0, -1)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [368, 12, 368, 12],
- expectedXs = [74, 221, 368, 515]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- describe('data type line', function() {
- beforeAll(function() {
- args.data.type = 'line'
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(-215, -1)
- expect(domain[1]).toBeCloseTo(25, -1)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [395, 60, 395, 12],
- expectedXs = [6, 198, 391, 583]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- })
- describe('on rotated axis', function() {
- describe('data type bar', function() {
- beforeAll(function() {
- args.data.type = 'bar'
- args.axis = {
- rotated: true
- }
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(-220, -1)
- expect(domain[1]).toBeCloseTo(0, -1)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [57, 163, 269, 375],
- expectedXs = [103, 594, 103, 526]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- describe('data type line', function() {
- beforeAll(function() {
- args.data.type = 'line'
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(-220, -1)
- expect(domain[1]).toBeCloseTo(24, -1)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [9, 147, 286, 424],
- expectedXs = [67, 537, 67, 526]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- })
- })
- describe('with positive and negative values and null', function() {
- describe('on non rotated axis', function() {
- describe('data type bar', function() {
- beforeAll(function() {
- args = {
- data: {
- columns: [['data1', -190, 200, 190, null]],
- type: 'bar',
- labels: {
- format: function(v) {
- if (v === null) {
- return 'Not Applicable'
- }
- return d3.format('$')(v)
- }
- }
- }
- }
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(-243, -1)
- expect(domain[1]).toBeCloseTo(253, -1)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [392, 43, 52, 215],
- expectedXs = [74, 221, 368, 515]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- describe('data type line', function() {
- beforeAll(function() {
- args.data.type = 'line'
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(-243, -1)
- expect(domain[1]).toBeCloseTo(253, -1)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [392, 40, 49, 212],
- expectedXs = [6, 198, 391, 583]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- })
- describe('on rotated axis', function() {
- describe('data type bar', function() {
- beforeAll(function() {
- args.data.type = 'bar'
- args.axis = {
- rotated: true
- }
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(-253, -1)
- expect(domain[1]).toBeCloseTo(260, -1)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [57, 163, 269, 375],
- expectedXs = [69, 525, 513, 295]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- describe('data type line', function() {
- beforeAll(function() {
- args.data.type = 'line'
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(-253, -1)
- expect(domain[1]).toBeCloseTo(260, -1)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [9, 147, 286, 424],
- expectedXs = [67, 527, 515, 297]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- })
- })
- describe('with positive grouped values', function() {
- describe('on non rotated axis', function() {
- describe('data type bar', function() {
- beforeAll(function() {
- args = {
- data: {
- columns: [
- ['data1', 30, 200, 100, 500],
- ['data2', 50, 20, 10, 40],
- ['data3', 250, 220, 210, 240]
- ],
- groups: [['data1', 'data2', 'data3']],
- labels: true,
- type: 'bar'
- }
- }
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(0, -1)
- expect(domain[1]).toBeCloseTo(885, -1)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [385, 317, 370, 164],
- expectedXs = [74, 221, 368, 515]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- describe('data type line', function() {
- beforeAll(function() {
- args.data.type = 'line'
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(-94, -1)
- expect(domain[1]).toBeCloseTo(884, -1)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [344, 284, 331, 144],
- expectedXs = [6, 198, 391, 583]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- })
- describe('on rotated axis', function() {
- describe('data type bar', function() {
- beforeAll(function() {
- args.data.type = 'bar'
- args.axis = {
- rotated: true
- }
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(0, -1)
- expect(domain[1]).toBeCloseTo(888, -1.2)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [57, 163, 269, 375],
- expectedXs = [57, 150, 77, 363]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- describe('data type line', function() {
- beforeAll(function() {
- args.data.type = 'line'
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(-87, -1)
- expect(domain[1]).toBeCloseTo(887, -1.2)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [9, 147, 286, 424],
- expectedXs = [107, 192, 125, 386]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- })
- })
- describe('with negative grouped values', function() {
- describe('on non rotated axis', function() {
- describe('data type bar', function() {
- beforeAll(function() {
- args = {
- data: {
- columns: [
- ['data1', -30, -200, -100, -500],
- ['data2', -50, -20, -10, -40],
- ['data3', -250, -220, -210, -240]
- ],
- groups: [['data1', 'data2', 'data3']],
- labels: true,
- type: 'bar'
- }
- }
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(-885, -1)
- expect(domain[1]).toBeCloseTo(0, -1)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [51, 118, 65, 272],
- expectedXs = [74, 221, 368, 515]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- describe('data type line', function() {
- beforeAll(function() {
- args.data.type = 'line'
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(-884, -1)
- expect(domain[1]).toBeCloseTo(94, -1)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [88, 149, 101, 288],
- expectedXs = [6, 198, 391, 583]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- })
- describe('on rotated axis', function() {
- describe('data type bar', function() {
- beforeAll(function() {
- args.data.type = 'bar'
- args.axis = {
- rotated: true
- }
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(-899, -1)
- expect(domain[1]).toBeCloseTo(0, -1)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [57, 163, 269, 375],
- expectedXs = [533, 440, 513, 230]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- describe('data type line', function() {
- beforeAll(function() {
- args.data.type = 'line'
- })
- it('should have y domain with proper padding', function() {
- var domain = chart.internal.y.domain()
- expect(domain[0]).toBeCloseTo(-893, -1)
- expect(domain[1]).toBeCloseTo(93, -1)
- })
- it('should locate labels above each data point', function() {
- var texts = chart.internal.main.selectAll('.c3-texts-data1 text'),
- expectedYs = [9, 147, 286, 424],
- expectedXs = [480, 397, 462, 205]
- texts.each(function(d, i) {
- var text = d3.select(this)
- expect(+text.attr('y')).toBeCloseTo(expectedYs[i], -2)
- expect(+text.attr('x')).toBeCloseTo(expectedXs[i], -2)
- })
- })
- })
- })
- })
- })
- describe('data.stack', function() {
- beforeAll(() => {
- args = {
- data: {
- columns: [
- ['data1', 230, 50, 300],
- ['data2', 198, 87, 580]
- ],
- type: 'bar',
- groups: [['data1', 'data2']],
- stack: {
- normalize: true
- }
- }
- }
- })
- const getChartHeight = () =>
- +chart.internal.main.select(`.c3-event-rect`).attr('height') - 1
- it('check for the normalized y axis tick in percentage', () => {
- const tick = chart.internal.main.selectAll(`.c3-axis-y .tick tspan`)
- // check for the y axis to be in percentage
- tick.each(function(v, i) {
- expect(this.textContent).toEqual(`${i * 10}%`)
- })
- })
- it("check for the normalized bar's height", () => {
- const chartHeight = getChartHeight()
- const bars = chart.internal.main.selectAll('.c3-bar').nodes()
- bars.splice(0, 3).forEach((v, i) => {
- expect(v.getBBox().height + bars[i].getBBox().height).toEqual(
- chartHeight
- )
- })
- })
- it('check when hiding data', done => {
- const chartHeight = getChartHeight()
- // when
- chart.hide('data1')
- setTimeout(() => {
- chart.internal.main.selectAll(`.c3-target-data2 path`).each(function() {
- expect(this.getBBox().height).toBe(chartHeight)
- })
- done()
- }, 500)
- })
- describe('timeseries chart', () => {
- beforeAll(function() {
- args = {
- data: {
- x: 'date',
- columns: [
- ['date', '2012-12-24', '2012-12-25', '2012-12-26'],
- ['data1', 30, 200, 400],
- ['data2', 50, 60, 50]
- ],
- groups: [['data1', 'data2']],
- type: 'bar',
- stack: {
- normalize: true
- }
- },
- axis: {
- x: {
- type: 'timeseries'
- }
- }
- }
- })
- it("check for the normalized bar's height", () => {
- const chartHeight = getChartHeight()
- const bars = chart.internal.main.selectAll('.c3-bar').nodes()
- expect(document.hidden).toBeFalsy()
- bars.splice(0, 3).forEach((v, i) => {
- expect(v.getBBox().height + bars[i].getBBox().height).toEqual(
- chartHeight
- )
- })
- })
- })
- describe('area chart', () => {
- beforeAll(() => {
- args = {
- data: {
- columns: [
- ['data1', 200, 387, 123],
- ['data2', 200, 387, 123]
- ],
- type: 'area',
- groups: [['data1', 'data2']],
- stack: {
- normalize: true
- }
- }
- }
- })
- it("check for the normalized area's height", () => {
- const chartHeight = getChartHeight()
- let areaHeight = 0
- chart.internal.main.selectAll('.c3-area').each(function() {
- areaHeight += this.getBBox().height
- })
- expect(document.hidden).toBeFalsy()
- expect(areaHeight).toEqual(chartHeight)
- })
- })
- })
- })
|