pen.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. export const updatePen = (pen: any, prop: string, render = true) => {
  2. const v: any = { id: pen.id };
  3. const rect: any = meta2d.getPenRect(pen);
  4. v[prop] = pen[prop];
  5. if (prop === 'x') {
  6. v.x = rect.x;
  7. } else if (prop === 'y') {
  8. v.y = rect.y;
  9. } else if (prop === 'width') {
  10. v.height = (rect.width / pen.width) * pen.height;
  11. } else if (prop === 'height') {
  12. v.width = (rect.height / pen.height) * pen.width;
  13. } else if (prop === 'shadow') {
  14. if (v[prop]) {
  15. !v.shadowOffsetX && (v.shadowOffsetX = 0);
  16. !v.shadowOffsetY && (v.shadowOffsetY = 0);
  17. !v.shadowBlur && (v.shadowBlur = 0);
  18. } else {
  19. v.shadowColor = '';
  20. }
  21. } else if (prop === 'lineGradientColors') {
  22. //@ts-ignore
  23. if (meta2d.store.active[0].name === 'line') {
  24. //@ts-ignore
  25. meta2d.store.active[0].calculative.gradientColorStop = null;
  26. } else {
  27. //@ts-ignore
  28. meta2d.store.active[0].calculative.lineGradient = null;
  29. }
  30. //不同模式切换不同的系统配色
  31. } else if (prop === 'titleFnJs') {
  32. v.titleFn = null;
  33. } else if (prop === 'dash') {
  34. v.lineDash = lineDashObj[v[prop]];
  35. }
  36. meta2d.setValue(v, { render });
  37. };
  38. export const lineDashObj = [
  39. undefined,
  40. [5, 5],
  41. [10, 10],
  42. [10, 10, 2, 10],
  43. [1, 16],
  44. ];