OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 Google Inc. All rights reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style |
| 5 * license that can be found in the LICENSE file or at |
| 6 * https://developers.google.com/open-source/licenses/bsd |
| 7 */ |
| 8 |
| 9 part of charted.test.layout; |
| 10 |
| 11 testPieLayout() { |
| 12 List mockPieData = [ |
| 13 [5, 5, 10], |
| 14 [0, 0], |
| 15 [4], |
| 16 [10, 5, 5], // Case for sorting, results the same as the first case. |
| 17 ]; |
| 18 List mockPieAngle = [ |
| 19 [[0, PI / 2], [PI / 2, PI], [PI, PI * 2]], |
| 20 [[0, 0], [0, 0]], |
| 21 [[0, 2 * PI]], |
| 22 [[0, PI / 2], [PI / 2, PI], [PI, PI * 2]], |
| 23 ]; |
| 24 |
| 25 group('PieLayout.startAngleCallback', () { |
| 26 PieLayout pieLayout = new PieLayout(); |
| 27 test('= 0 by default', () { |
| 28 expect(pieLayout.startAngleCallback(null, 0, null), equals(0)); |
| 29 }); |
| 30 PieLayout pieLayout2 = new PieLayout(); |
| 31 pieLayout2.startAngle = 0.4; |
| 32 test('equals the manually set value after set by startAngle setter', () { |
| 33 expect(pieLayout2.startAngleCallback(null, 0, null), equals(0.4)); |
| 34 }); |
| 35 }); |
| 36 |
| 37 group('PieLayout.endAngleCallback', () { |
| 38 PieLayout pieLayout = new PieLayout(); |
| 39 test('= 2 * PI by default', () { |
| 40 expect(pieLayout.endAngleCallback(null, 0, null), equals(2 * PI)); |
| 41 }); |
| 42 PieLayout pieLayout2 = new PieLayout(); |
| 43 pieLayout2.endAngle = 0.4; |
| 44 test('equals the manually set value after set by endAngle setter', () { |
| 45 expect(pieLayout2.endAngleCallback(null, 0, null), equals(0.4)); |
| 46 }); |
| 47 }); |
| 48 |
| 49 group('PieLayout.layout', () { |
| 50 test('generates a list of SvgArcData object for pie-chart', () { |
| 51 PieLayout pieLayout = new PieLayout(); |
| 52 List slice = pieLayout.layout(mockPieData[0]); |
| 53 for (var i = 0; i < 3; ++i) { |
| 54 expect(slice[i].startAngle, closeTo(mockPieAngle[0][i][0], EPSILON)); |
| 55 expect(slice[i].endAngle, closeTo(mockPieAngle[0][i][1], EPSILON)); |
| 56 } |
| 57 }); |
| 58 test('generates zero-angled slice for total 0 data', () { |
| 59 PieLayout pieLayout = new PieLayout(); |
| 60 List slice = pieLayout.layout(mockPieData[1]); |
| 61 for (var i = 0; i < 2; ++i) { |
| 62 expect(slice[i].startAngle, closeTo(mockPieAngle[1][i][0], EPSILON)); |
| 63 expect(slice[i].endAngle, closeTo(mockPieAngle[1][i][1], EPSILON)); |
| 64 } |
| 65 }); |
| 66 test('generates concentric pie sector for solo non-zero data', () { |
| 67 PieLayout pieLayout = new PieLayout(); |
| 68 List slice = pieLayout.layout(mockPieData[2]); |
| 69 expect(slice[0].startAngle, closeTo(mockPieAngle[2][0][0], EPSILON)); |
| 70 expect(slice[0].endAngle, closeTo(mockPieAngle[2][0][1], EPSILON)); |
| 71 }); |
| 72 test('supports sorting data', () { |
| 73 PieLayout pieLayout = new PieLayout(); |
| 74 pieLayout.compare = (num a, num b) => (a - b).ceil(); |
| 75 List slice = pieLayout.layout(mockPieData[3]); |
| 76 for (var i = 0; i < 3; ++i) { |
| 77 expect(slice[i].startAngle, closeTo(mockPieAngle[3][i][0], EPSILON)); |
| 78 expect(slice[i].endAngle, closeTo(mockPieAngle[3][i][1], EPSILON)); |
| 79 } |
| 80 }); |
| 81 }); |
| 82 } |
OLD | NEW |