graphic.js 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. describe('util/graphic', function() {
  2. var utHelper = window.utHelper;
  3. var graphic;
  4. beforeAll(function (done) { // jshint ignore:line
  5. utHelper.resetPackageLoader(function () {
  6. window.require(['echarts/util/graphic'], function (g) {
  7. graphic = g;
  8. done();
  9. });
  10. });
  11. });
  12. describe('subPixelOptimize', function () {
  13. it('subPixelOptimize_base', function (done) {
  14. expect(graphic.subPixelOptimize(5, 1)).toEqual(4.5);
  15. expect(graphic.subPixelOptimize(5, 2)).toEqual(5);
  16. expect(graphic.subPixelOptimize(5, 43)).toEqual(4.5);
  17. expect(graphic.subPixelOptimize(7.5, 1)).toEqual(7.5);
  18. expect(graphic.subPixelOptimize(7.5, 2)).toEqual(7);
  19. expect(graphic.subPixelOptimize(14, 1, true)).toEqual(14.5);
  20. expect(graphic.subPixelOptimize(14, 2, true)).toEqual(14);
  21. expect(graphic.subPixelOptimize(-11, 1)).toEqual(-11.5);
  22. expect(graphic.subPixelOptimize(-11, 2)).toEqual(-11);
  23. expect(graphic.subPixelOptimize(0, 2)).toEqual(0);
  24. expect(graphic.subPixelOptimize(0, 1)).toEqual(-0.5);
  25. expect(graphic.subPixelOptimize(5, 0)).toEqual(5);
  26. done();
  27. });
  28. it('subPixelOptimize_line', function (done) {
  29. function doSubPixelOptimizeLine(x, y, width, height, lineWidth) {
  30. return graphic.subPixelOptimizeLine(makeParam(x, y, width, height, lineWidth));
  31. }
  32. function makeParam(x1, y1, x2, y2, lineWidth) {
  33. return {
  34. shape: {x1: x1, y1: y1, x2: x2, y2: y2},
  35. style: {lineWidth: lineWidth}
  36. };
  37. }
  38. expect(doSubPixelOptimizeLine(5, 11, 3, 7, 1)).toEqual(makeParam(5, 11, 3, 7, 1));
  39. expect(doSubPixelOptimizeLine(5, 11, 5, 7, 1)).toEqual(makeParam(5.5, 11, 5.5, 7, 1));
  40. expect(doSubPixelOptimizeLine(5, 11, 5, 7, 2)).toEqual(makeParam(5, 11, 5, 7, 2));
  41. expect(doSubPixelOptimizeLine(5, 11, 15, 11, 1)).toEqual(makeParam(5, 11.5, 15, 11.5, 1));
  42. expect(doSubPixelOptimizeLine(5, 11, 15, 11, 2)).toEqual(makeParam(5, 11, 15, 11, 2));
  43. expect(doSubPixelOptimizeLine(5, 11, 15, 11, 3)).toEqual(makeParam(5, 11.5, 15, 11.5, 3));
  44. expect(doSubPixelOptimizeLine(5, 11, 15, 11.5, 3)).toEqual(makeParam(5, 11, 15, 11.5, 3));
  45. expect(doSubPixelOptimizeLine(5, 11.5, 15, 11.5, 3)).toEqual(makeParam(5, 11.5, 15, 11.5, 3));
  46. expect(doSubPixelOptimizeLine(5, 11.5, 15, 11.5, 4)).toEqual(makeParam(5, 12, 15, 12, 4));
  47. done();
  48. });
  49. it('subPixelOptimize_rect', function (done) {
  50. function doSubPixelOptimizeRect(x, y, width, height, lineWidth) {
  51. return graphic.subPixelOptimizeRect(makeParam(x, y, width, height, lineWidth));
  52. }
  53. function makeParam(x, y, width, height, lineWidth) {
  54. return {
  55. shape: {x: x, y: y, width: width, height: height},
  56. style: {lineWidth: lineWidth}
  57. };
  58. }
  59. expect(doSubPixelOptimizeRect(5, 11, 3, 7, 1)).toEqual(makeParam(5.5, 11.5, 2, 6, 1));
  60. expect(doSubPixelOptimizeRect(5, 11, 3, 7, 2)).toEqual(makeParam(5, 11, 3, 7, 2));
  61. expect(doSubPixelOptimizeRect(5, 11, 3, 7, 3)).toEqual(makeParam(5.5, 11.5, 2, 6, 3));
  62. // Boundary value tests
  63. expect(doSubPixelOptimizeRect(5, 11, 1, 7, 1)).toEqual(makeParam(5.5, 11.5, 1, 6, 1));
  64. expect(doSubPixelOptimizeRect(5, 11, 1, 0, 1)).toEqual(makeParam(5.5, 11.5, 1, 0, 1));
  65. done();
  66. });
  67. });
  68. });