DashProperty.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import {
  2. extendPrototype,
  3. } from '../functionExtensions';
  4. import DynamicPropertyContainer from '../helpers/dynamicProperties';
  5. import {
  6. createSizedArray,
  7. createTypedArray,
  8. } from '../helpers/arrays';
  9. import PropertyFactory from '../PropertyFactory';
  10. function DashProperty(elem, data, renderer, container) {
  11. this.elem = elem;
  12. this.frameId = -1;
  13. this.dataProps = createSizedArray(data.length);
  14. this.renderer = renderer;
  15. this.k = false;
  16. this.dashStr = '';
  17. this.dashArray = createTypedArray('float32', data.length ? data.length - 1 : 0);
  18. this.dashoffset = createTypedArray('float32', 1);
  19. this.initDynamicPropertyContainer(container);
  20. var i;
  21. var len = data.length || 0;
  22. var prop;
  23. for (i = 0; i < len; i += 1) {
  24. prop = PropertyFactory.getProp(elem, data[i].v, 0, 0, this);
  25. this.k = prop.k || this.k;
  26. this.dataProps[i] = { n: data[i].n, p: prop };
  27. }
  28. if (!this.k) {
  29. this.getValue(true);
  30. }
  31. this._isAnimated = this.k;
  32. }
  33. DashProperty.prototype.getValue = function (forceRender) {
  34. if (this.elem.globalData.frameId === this.frameId && !forceRender) {
  35. return;
  36. }
  37. this.frameId = this.elem.globalData.frameId;
  38. this.iterateDynamicProperties();
  39. this._mdf = this._mdf || forceRender;
  40. if (this._mdf) {
  41. var i = 0;
  42. var len = this.dataProps.length;
  43. if (this.renderer === 'svg') {
  44. this.dashStr = '';
  45. }
  46. for (i = 0; i < len; i += 1) {
  47. if (this.dataProps[i].n !== 'o') {
  48. if (this.renderer === 'svg') {
  49. this.dashStr += ' ' + this.dataProps[i].p.v;
  50. } else {
  51. this.dashArray[i] = this.dataProps[i].p.v;
  52. }
  53. } else {
  54. this.dashoffset[0] = this.dataProps[i].p.v;
  55. }
  56. }
  57. }
  58. };
  59. extendPrototype([DynamicPropertyContainer], DashProperty);
  60. export default DashProperty;