data-region.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { __assign, __extends } from "tslib";
  2. import { get } from '@antv/util';
  3. import GroupComponent from '../abstract/group-component';
  4. import Theme from '../util/theme';
  5. import { pointsToBBox } from '../util/util';
  6. import { renderTag } from '../util/graphic';
  7. var DataRegionAnnotation = /** @class */ (function (_super) {
  8. __extends(DataRegionAnnotation, _super);
  9. function DataRegionAnnotation() {
  10. return _super !== null && _super.apply(this, arguments) || this;
  11. }
  12. /**
  13. * 默认的配置项
  14. * @returns {object} 默认的配置项
  15. */
  16. DataRegionAnnotation.prototype.getDefaultCfg = function () {
  17. var cfg = _super.prototype.getDefaultCfg.call(this);
  18. return __assign(__assign({}, cfg), { name: 'annotation', type: 'dataRegion', locationType: 'points', points: [], lineLength: 0, region: {}, text: {}, defaultCfg: {
  19. region: {
  20. style: {
  21. lineWidth: 0,
  22. fill: Theme.regionColor,
  23. opacity: 0.4,
  24. },
  25. },
  26. text: {
  27. content: '',
  28. style: {
  29. textAlign: 'center',
  30. textBaseline: 'bottom',
  31. fontSize: 12,
  32. fill: Theme.textColor,
  33. fontFamily: Theme.fontFamily,
  34. },
  35. },
  36. } });
  37. };
  38. DataRegionAnnotation.prototype.renderInner = function (group) {
  39. var regionStyle = get(this.get('region'), 'style', {});
  40. var textStyle = get(this.get('text'), 'style', {});
  41. var lineLength = this.get('lineLength') || 0;
  42. var points = this.get('points');
  43. if (!points.length) {
  44. return;
  45. }
  46. var bbox = pointsToBBox(points);
  47. // render region
  48. var path = [];
  49. path.push(['M', points[0].x, bbox.minY - lineLength]);
  50. points.forEach(function (point) {
  51. path.push(['L', point.x, point.y]);
  52. });
  53. path.push(['L', points[points.length - 1].x, points[points.length - 1].y - lineLength]);
  54. this.addShape(group, {
  55. type: 'path',
  56. id: this.getElementId('region'),
  57. name: 'annotation-region',
  58. attrs: __assign({ path: path }, regionStyle),
  59. });
  60. // render text
  61. var textCfg = __assign({ id: this.getElementId('text'), name: 'annotation-text', x: (bbox.minX + bbox.maxX) / 2, y: bbox.minY - lineLength }, this.get('text'));
  62. renderTag(group, textCfg);
  63. };
  64. return DataRegionAnnotation;
  65. }(GroupComponent));
  66. export default DataRegionAnnotation;
  67. //# sourceMappingURL=data-region.js.map