shadow.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use strict";
  2. /**
  3. * @fileoverview shadow
  4. * @author dengfuping_develop@163.com
  5. */
  6. Object.defineProperty(exports, "__esModule", { value: true });
  7. var util_1 = require("@antv/util");
  8. var dom_1 = require("../util/dom");
  9. var ATTR_MAP = {
  10. shadowColor: 'color',
  11. shadowOpacity: 'opacity',
  12. shadowBlur: 'blur',
  13. shadowOffsetX: 'dx',
  14. shadowOffsetY: 'dy',
  15. };
  16. var SHADOW_DIMENSION = {
  17. x: '-40%',
  18. y: '-40%',
  19. width: '200%',
  20. height: '200%',
  21. };
  22. var Shadow = /** @class */ (function () {
  23. function Shadow(cfg) {
  24. this.type = 'filter';
  25. this.cfg = {};
  26. this.type = 'filter';
  27. var el = dom_1.createSVGElement('filter');
  28. // expand the filter region to fill in shadows
  29. util_1.each(SHADOW_DIMENSION, function (v, k) {
  30. el.setAttribute(k, v);
  31. });
  32. this.el = el;
  33. this.id = util_1.uniqueId('filter_');
  34. this.el.id = this.id;
  35. this.cfg = cfg;
  36. this._parseShadow(cfg, el);
  37. return this;
  38. }
  39. Shadow.prototype.match = function (type, cfg) {
  40. if (this.type !== type) {
  41. return false;
  42. }
  43. var flag = true;
  44. var config = this.cfg;
  45. util_1.each(Object.keys(config), function (attr) {
  46. if (config[attr] !== cfg[attr]) {
  47. flag = false;
  48. return false;
  49. }
  50. });
  51. return flag;
  52. };
  53. Shadow.prototype.update = function (name, value) {
  54. var config = this.cfg;
  55. config[ATTR_MAP[name]] = value;
  56. this._parseShadow(config, this.el);
  57. return this;
  58. };
  59. Shadow.prototype._parseShadow = function (config, el) {
  60. var child = "<feDropShadow\n dx=\"" + (config.dx || 0) + "\"\n dy=\"" + (config.dy || 0) + "\"\n stdDeviation=\"" + (config.blur ? config.blur / 10 : 0) + "\"\n flood-color=\"" + (config.color ? config.color : '#000') + "\"\n flood-opacity=\"" + (config.opacity ? config.opacity : 1) + "\"\n />";
  61. el.innerHTML = child;
  62. };
  63. return Shadow;
  64. }());
  65. exports.default = Shadow;
  66. //# sourceMappingURL=shadow.js.map