trend.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { __assign, __extends } from "tslib";
  2. import GroupComponent from '../abstract/group-component';
  3. import { AREA_STYLE, BACKGROUND_STYLE, LINE_STYLE } from './constant';
  4. import { dataToPath, linePathToAreaPath } from './path';
  5. var Trend = /** @class */ (function (_super) {
  6. __extends(Trend, _super);
  7. function Trend() {
  8. return _super !== null && _super.apply(this, arguments) || this;
  9. }
  10. Trend.prototype.getDefaultCfg = function () {
  11. var cfg = _super.prototype.getDefaultCfg.call(this);
  12. return __assign(__assign({}, cfg), { name: 'trend', x: 0, y: 0, width: 200, height: 16, smooth: true, isArea: false, data: [], backgroundStyle: BACKGROUND_STYLE, lineStyle: LINE_STYLE, areaStyle: AREA_STYLE });
  13. };
  14. Trend.prototype.renderInner = function (group) {
  15. var _a = this.cfg, width = _a.width, height = _a.height, data = _a.data, smooth = _a.smooth, isArea = _a.isArea, backgroundStyle = _a.backgroundStyle, lineStyle = _a.lineStyle, areaStyle = _a.areaStyle;
  16. // 背景
  17. this.addShape(group, {
  18. id: this.getElementId('background'),
  19. type: 'rect',
  20. attrs: __assign({ x: 0, y: 0, width: width,
  21. height: height }, backgroundStyle),
  22. });
  23. var path = dataToPath(data, width, height, smooth);
  24. // 线
  25. this.addShape(group, {
  26. id: this.getElementId('line'),
  27. type: 'path',
  28. attrs: __assign({ path: path }, lineStyle),
  29. });
  30. // area
  31. // 在 path 的基础上,增加两个坐标点
  32. if (isArea) {
  33. var areaPath = linePathToAreaPath(path, width, height, data);
  34. this.addShape(group, {
  35. id: this.getElementId('area'),
  36. type: 'path',
  37. attrs: __assign({ path: areaPath }, areaStyle),
  38. });
  39. }
  40. };
  41. Trend.prototype.applyOffset = function () {
  42. var _a = this.cfg, x = _a.x, y = _a.y;
  43. // 统一移动到对应的位置
  44. this.moveElementTo(this.get('group'), {
  45. x: x,
  46. y: y,
  47. });
  48. };
  49. return Trend;
  50. }(GroupComponent));
  51. export { Trend };
  52. export default Trend;
  53. //# sourceMappingURL=trend.js.map