strip.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * DevExtreme (viz/axes/strip.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. Object.defineProperty(exports, "__esModule", {
  11. value: true
  12. });
  13. exports.default = createStrip;
  14. var _type = require("../../core/utils/type");
  15. var _utils = require("../core/utils");
  16. var _extend = require("../../core/utils/extend");
  17. function createStrip(axis, options) {
  18. var storedCoord;
  19. var labelOptions = options.label || {};
  20. return {
  21. options: options,
  22. label: null,
  23. rect: null,
  24. _getCoord: function() {
  25. var canvas = axis._getCanvasStartEnd();
  26. var range = axis._translator.getBusinessRange();
  27. return axis._getStripPos(options.startValue, options.endValue, canvas.start, canvas.end, range)
  28. },
  29. _drawLabel: function(coords) {
  30. return axis._renderer.text(labelOptions.text, coords.x, coords.y).css((0, _utils.patchFontOptions)((0, _extend.extend)({}, axis.getOptions().label.font, labelOptions.font))).attr({
  31. align: "center",
  32. "class": labelOptions.cssClass
  33. }).append(axis._axisStripLabelGroup)
  34. },
  35. draw: function() {
  36. if (axis._translator.getBusinessRange().isEmpty()) {
  37. return
  38. }
  39. if (((0, _type.isDefined)(options.startValue) || (0, _type.isDefined)(options.endValue)) && (0, _type.isDefined)(options.color)) {
  40. var stripPos = this._getCoord();
  41. this.labelCoords = labelOptions.text ? axis._getStripLabelCoords(stripPos.from, stripPos.to, labelOptions) : null;
  42. if (stripPos.outOfCanvas || !(0, _type.isDefined)(stripPos.to) || !(0, _type.isDefined)(stripPos.from)) {
  43. return
  44. }
  45. this.rect = axis._createStrip(axis._getStripGraphicAttributes(stripPos.from, stripPos.to)).attr({
  46. fill: options.color
  47. }).append(axis._axisStripGroup);
  48. this.label = labelOptions.text ? this._drawLabel(this.labelCoords) : null
  49. }
  50. },
  51. removeLabel: function() {},
  52. updatePosition: function(animate) {
  53. var stripPos = this._getCoord();
  54. if (animate && storedCoord) {
  55. this.label && this.label.attr(axis._getStripLabelCoords(storedCoord.from, storedCoord.to, options.label));
  56. this.rect && this.rect.attr(axis._getStripGraphicAttributes(storedCoord.from, storedCoord.to));
  57. this.label && this.label.animate(axis._getStripLabelCoords(stripPos.from, stripPos.to, options.label));
  58. this.rect && this.rect.animate(axis._getStripGraphicAttributes(stripPos.from, stripPos.to))
  59. } else {
  60. this.label && this.label.attr(axis._getStripLabelCoords(stripPos.from, stripPos.to, options.label));
  61. this.rect && this.rect.attr(axis._getStripGraphicAttributes(stripPos.from, stripPos.to))
  62. }
  63. },
  64. saveCoords: function() {
  65. storedCoord = this._getCoord()
  66. }
  67. }
  68. }