mycharts.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // 1. 编写图形绘画函数
  2. // 其中,calculative.worldRect为canvas的世界坐标。更多信息,参考 “架构” - “概要” 和 Pen 相关文档
  3. // 形参 ctx 仅仅在 downloadSvg 时有值
  4. function mytriangle(pen, ctx) {
  5. const path = !ctx ? new Path2D() : ctx;
  6. const { x, y, width, height } = pen.calculative.worldRect;
  7. path.moveTo(x + width / 2, y);
  8. path.lineTo(x + width, y + height);
  9. path.lineTo(x, y + height);
  10. path.lineTo(x + width / 2, y);
  11. path.closePath();
  12. if (path instanceof Path2D) return path;
  13. }
  14. // 2. 如果需要,编写锚点函数。通常,可以使用默认锚点,然后通过快捷键动态添加锚点
  15. // 注意,锚点左边为相对宽高的百分比小数(0-1之间的小数)
  16. function mytriangleAnchors(pen) {
  17. const anchors = [];
  18. anchors.push({
  19. id: '0',
  20. penId: pen.id,
  21. x: 0.5,
  22. y: 0,
  23. });
  24. anchors.push({
  25. id: '1',
  26. penId: pen.id,
  27. x: 1,
  28. y: 1,
  29. });
  30. anchors.push({
  31. id: '2',
  32. penId: pen.id,
  33. x: 0,
  34. y: 1,
  35. });
  36. pen.anchors = anchors;
  37. }
  38. // 需要时打开
  39. if (false) {
  40. window.myCharts = [
  41. {
  42. name: '我的图形库文件夹名称',
  43. list: [
  44. {
  45. image: '/img/logo.png',
  46. name: '自定义图形',
  47. penFn: mytriangle,
  48. anchorsFn: mytriangleAnchors, // 可以不需要,使用缺省锚点
  49. data: {
  50. width: 100,
  51. height: 100,
  52. },
  53. },
  54. ],
  55. show: true,
  56. },
  57. ];
  58. }
  59. function beforeSave(data) {
  60. // 自己的保存业务逻辑
  61. const query = window.location.search.substring(1).split('&');
  62. const obj = {};
  63. for (let i = 0; i < query.length; i++) {
  64. const el = query[i];
  65. const kvPairs = el.split('=');
  66. obj[kvPairs[0]] = kvPairs[1];
  67. }
  68. if (obj.eqpickey) {
  69. if (!data.data) {
  70. data.data = {};
  71. }
  72. data.data.eqpickey = obj.eqpickey;
  73. }
  74. return true;
  75. }
  76. window.beforeSaveMeta2d = beforeSave;