|
| 1 | +var d3 = require('d3'); |
| 2 | + |
| 3 | +var Plotly = require('@lib/index'); |
| 4 | + |
| 5 | +var createGraphDiv = require('../assets/create_graph_div'); |
| 6 | +var destroyGraphDiv = require('../assets/destroy_graph_div'); |
| 7 | +var customMatchers = require('../assets/custom_matchers'); |
| 8 | +var failTest = require('../assets/fail_test'); |
| 9 | + |
| 10 | +describe('Pies', function() { |
| 11 | + 'use strict'; |
| 12 | + |
| 13 | + var gd; |
| 14 | + |
| 15 | + beforeAll(function() { |
| 16 | + jasmine.addMatchers(customMatchers); |
| 17 | + }); |
| 18 | + |
| 19 | + beforeEach(function() { gd = createGraphDiv(); }); |
| 20 | + |
| 21 | + afterEach(destroyGraphDiv); |
| 22 | + |
| 23 | + it('should separate colors and opacities', function(done) { |
| 24 | + Plotly.newPlot(gd, [{ |
| 25 | + values: [1, 2, 3, 4, 5], |
| 26 | + type: 'pie', |
| 27 | + sort: false, |
| 28 | + marker: { |
| 29 | + line: {width: 3, color: 'rgba(100,100,100,0.7)'}, |
| 30 | + colors: [ |
| 31 | + 'rgba(0,0,0,0.2)', |
| 32 | + 'rgba(255,0,0,0.3)', |
| 33 | + 'rgba(0,255,0,0.4)', |
| 34 | + 'rgba(0,0,255,0.5)', |
| 35 | + 'rgba(255,255,0,0.6)' |
| 36 | + ] |
| 37 | + } |
| 38 | + }], {height: 300, width: 400}).then(function() { |
| 39 | + var colors = [ |
| 40 | + 'rgb(0, 0, 0)', |
| 41 | + 'rgb(255, 0, 0)', |
| 42 | + 'rgb(0, 255, 0)', |
| 43 | + 'rgb(0, 0, 255)', |
| 44 | + 'rgb(255, 255, 0)' |
| 45 | + ]; |
| 46 | + var opacities = [0.2, 0.3, 0.4, 0.5, 0.6]; |
| 47 | + |
| 48 | + function checkPath(d, i) { |
| 49 | + var path = d3.select(this); |
| 50 | + expect(path.style('fill')).toBe(colors[i]); |
| 51 | + expect(path.style('fill-opacity')).toBe(String(opacities[i])); |
| 52 | + expect(path.style('stroke')).toBe('rgb(100, 100, 100)'); |
| 53 | + expect(path.style('stroke-opacity')).toBe('0.7'); |
| 54 | + } |
| 55 | + var slices = d3.selectAll('.slice path'); |
| 56 | + slices.each(checkPath); |
| 57 | + expect(slices.size()).toBe(5); |
| 58 | + |
| 59 | + var legendEntries = d3.selectAll('.legendpoints path'); |
| 60 | + legendEntries.each(checkPath); |
| 61 | + expect(legendEntries.size()).toBe(5); |
| 62 | + }) |
| 63 | + .catch(failTest) |
| 64 | + .then(done); |
| 65 | + }); |
| 66 | +}); |
0 commit comments