schema.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. "use strict";
  2. exports.__esModule = true;
  3. exports["default"] = void 0;
  4. var _shape = _interopRequireDefault(require("./shape"));
  5. var _common = require("../../util/common");
  6. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  7. function _sortValue(value) {
  8. var sorted = value.sort(function (a, b) {
  9. return a < b ? 1 : -1;
  10. });
  11. var length = sorted.length;
  12. if (length < 4) {
  13. var min = sorted[length - 1];
  14. for (var i = 0; i < 4 - length; i++) {
  15. sorted.push(min);
  16. }
  17. }
  18. return sorted;
  19. } // from left bottom corner, and clockwise
  20. function getCandlePoints(x, y, width) {
  21. var yValues = _sortValue(y);
  22. var points = [{
  23. x: x,
  24. y: yValues[0]
  25. }, {
  26. x: x,
  27. y: yValues[1]
  28. }, {
  29. x: x - width / 2,
  30. y: yValues[2]
  31. }, {
  32. x: x - width / 2,
  33. y: yValues[1]
  34. }, {
  35. x: x + width / 2,
  36. y: yValues[1]
  37. }, {
  38. x: x + width / 2,
  39. y: yValues[2]
  40. }, {
  41. x: x,
  42. y: yValues[2]
  43. }, {
  44. x: x,
  45. y: yValues[3]
  46. }];
  47. return points;
  48. }
  49. var Schema = _shape["default"].registerFactory('schema', {});
  50. _shape["default"].registerShape('schema', 'candle', {
  51. getPoints: function getPoints(cfg) {
  52. return getCandlePoints(cfg.x, cfg.y, cfg.size);
  53. },
  54. draw: function draw(cfg, container) {
  55. var points = this.parsePoints(cfg.points);
  56. var style = (0, _common.mix)({
  57. stroke: cfg.color,
  58. fill: cfg.color,
  59. lineWidth: 1
  60. }, cfg.style);
  61. return container.addShape('Custom', {
  62. className: 'schema',
  63. attrs: style,
  64. createPath: function createPath(ctx) {
  65. ctx.beginPath();
  66. ctx.moveTo(points[0].x, points[0].y);
  67. ctx.lineTo(points[1].x, points[1].y);
  68. ctx.moveTo(points[2].x, points[2].y);
  69. for (var i = 3; i < 6; i++) {
  70. ctx.lineTo(points[i].x, points[i].y);
  71. }
  72. ctx.closePath();
  73. ctx.moveTo(points[6].x, points[6].y);
  74. ctx.lineTo(points[7].x, points[7].y);
  75. }
  76. });
  77. }
  78. });
  79. var _default = Schema;
  80. exports["default"] = _default;