123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265 |
- describe('Plugin.filler', function() {
- function decodedFillValues(chart) {
- return chart.data.datasets.map(function(dataset, index) {
- var meta = chart.getDatasetMeta(index) || {};
- expect(meta.$filler).toBeDefined();
- return meta.$filler.fill;
- });
- }
- describe('auto', jasmine.specsFromFixtures('plugin.filler'));
- describe('dataset.fill', function() {
- it('should support boundaries', function() {
- var chart = window.acquireChart({
- type: 'line',
- data: {
- datasets: [
- {fill: 'origin'},
- {fill: 'start'},
- {fill: 'end'},
- ]
- }
- });
- expect(decodedFillValues(chart)).toEqual(['origin', 'start', 'end']);
- });
- it('should support absolute dataset index', function() {
- var chart = window.acquireChart({
- type: 'line',
- data: {
- datasets: [
- {fill: 1},
- {fill: 3},
- {fill: 0},
- {fill: 2},
- ]
- }
- });
- expect(decodedFillValues(chart)).toEqual([1, 3, 0, 2]);
- });
- it('should support relative dataset index', function() {
- var chart = window.acquireChart({
- type: 'line',
- data: {
- datasets: [
- {fill: '+3'},
- {fill: '-1'},
- {fill: '+1'},
- {fill: '-2'},
- ]
- }
- });
- expect(decodedFillValues(chart)).toEqual([
- 3, // 0 + 3
- 0, // 1 - 1
- 3, // 2 + 1
- 1, // 3 - 2
- ]);
- });
- it('should handle default fill when true (origin)', function() {
- var chart = window.acquireChart({
- type: 'line',
- data: {
- datasets: [
- {fill: true},
- {fill: false},
- ]
- }
- });
- expect(decodedFillValues(chart)).toEqual(['origin', false]);
- });
- it('should ignore self dataset index', function() {
- var chart = window.acquireChart({
- type: 'line',
- data: {
- datasets: [
- {fill: 0},
- {fill: '-0'},
- {fill: '+0'},
- {fill: 3},
- ]
- }
- });
- expect(decodedFillValues(chart)).toEqual([
- false, // 0 === 0
- false, // 1 === 1 - 0
- false, // 2 === 2 + 0
- false, // 3 === 3
- ]);
- });
- it('should ignore out of bounds dataset index', function() {
- var chart = window.acquireChart({
- type: 'line',
- data: {
- datasets: [
- {fill: -2},
- {fill: 4},
- {fill: '-3'},
- {fill: '+1'},
- ]
- }
- });
- expect(decodedFillValues(chart)).toEqual([
- false, // 0 - 2 < 0
- false, // 1 + 4 > 3
- false, // 2 - 3 < 0
- false, // 3 + 1 > 3
- ]);
- });
- it('should ignore invalid values', function() {
- var chart = window.acquireChart({
- type: 'line',
- data: {
- datasets: [
- {fill: 'foo'},
- {fill: '+foo'},
- {fill: '-foo'},
- {fill: '+1.1'},
- {fill: '-2.2'},
- {fill: 3.3},
- {fill: -4.4},
- {fill: NaN},
- {fill: Infinity},
- {fill: ''},
- {fill: null},
- {fill: []},
- {fill: {}},
- {fill: function() {}}
- ]
- }
- });
- expect(decodedFillValues(chart)).toEqual([
- false, // NaN (string)
- false, // NaN (string)
- false, // NaN (string)
- false, // float (string)
- false, // float (string)
- false, // float (number)
- false, // float (number)
- false, // NaN
- false, // !isFinite
- false, // empty string
- false, // null
- false, // array
- false, // object
- false, // function
- ]);
- });
- });
- describe('options.plugins.filler.propagate', function() {
- it('should compute propagated fill targets if true', function() {
- var chart = window.acquireChart({
- type: 'line',
- data: {
- datasets: [
- {fill: 'start', hidden: true},
- {fill: '-1', hidden: true},
- {fill: 1, hidden: true},
- {fill: '-2', hidden: true},
- {fill: '+1'},
- {fill: '+2'},
- {fill: '-1'},
- {fill: 'end', hidden: true},
- ]
- },
- options: {
- plugins: {
- filler: {
- propagate: true
- }
- }
- }
- });
- expect(decodedFillValues(chart)).toEqual([
- 'start', // 'start'
- 'start', // 1 - 1 -> 0 (hidden) -> 'start'
- 'start', // 1 (hidden) -> 0 (hidden) -> 'start'
- 'start', // 3 - 2 -> 1 (hidden) -> 0 (hidden) -> 'start'
- 5, // 4 + 1
- 'end', // 5 + 2 -> 7 (hidden) -> 'end'
- 5, // 6 - 1 -> 5
- 'end', // 'end'
- ]);
- });
- it('should preserve initial fill targets if false', function() {
- var chart = window.acquireChart({
- type: 'line',
- data: {
- datasets: [
- {fill: 'start', hidden: true},
- {fill: '-1', hidden: true},
- {fill: 1, hidden: true},
- {fill: '-2', hidden: true},
- {fill: '+1'},
- {fill: '+2'},
- {fill: '-1'},
- {fill: 'end', hidden: true},
- ]
- },
- options: {
- plugins: {
- filler: {
- propagate: false
- }
- }
- }
- });
- expect(decodedFillValues(chart)).toEqual([
- 'start', // 'origin'
- 0, // 1 - 1
- 1, // 1
- 1, // 3 - 2
- 5, // 4 + 1
- 7, // 5 + 2
- 5, // 6 - 1
- 'end', // 'end'
- ]);
- });
- it('should prevent recursive propagation', function() {
- var chart = window.acquireChart({
- type: 'line',
- data: {
- datasets: [
- {fill: '+2', hidden: true},
- {fill: '-1', hidden: true},
- {fill: '-1', hidden: true},
- {fill: '-2'}
- ]
- },
- options: {
- plugins: {
- filler: {
- propagate: true
- }
- }
- }
- });
- expect(decodedFillValues(chart)).toEqual([
- false, // 0 + 2 -> 2 (hidden) -> 1 (hidden) -> 0 (loop)
- false, // 1 - 1 -> 0 (hidden) -> 2 (hidden) -> 1 (loop)
- false, // 2 - 1 -> 1 (hidden) -> 0 (hidden) -> 2 (loop)
- false, // 3 - 2 -> 1 (hidden) -> 0 (hidden) -> 2 (hidden) -> 1 (loop)
- ]);
- });
- });
- });
|