pen.ts 1.6 KB

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