@visactor/vrender-components 0.15.0-alpha.24 → 0.15.0-alpha.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/cjs/index.d.ts +1 -1
  2. package/cjs/index.js +1 -1
  3. package/cjs/index.js.map +1 -1
  4. package/cjs/label/arc.js +1 -1
  5. package/cjs/label/arc.js.map +1 -1
  6. package/cjs/label/base.js +8 -8
  7. package/cjs/label/base.js.map +1 -1
  8. package/cjs/legend/size/size.d.ts +2 -2
  9. package/cjs/legend/size/size.js.map +1 -1
  10. package/cjs/marker/area.d.ts +20 -1
  11. package/cjs/marker/area.js +37 -37
  12. package/cjs/marker/area.js.map +1 -1
  13. package/cjs/marker/base.d.ts +0 -1
  14. package/cjs/marker/base.js +18 -28
  15. package/cjs/marker/base.js.map +1 -1
  16. package/cjs/marker/config.d.ts +1 -1
  17. package/cjs/marker/config.js.map +1 -1
  18. package/cjs/marker/line.js +14 -27
  19. package/cjs/marker/line.js.map +1 -1
  20. package/cjs/marker/point.d.ts +7 -7
  21. package/cjs/marker/point.js +4 -5
  22. package/cjs/marker/point.js.map +1 -1
  23. package/cjs/marker/type.d.ts +5 -8
  24. package/cjs/marker/type.js.map +1 -1
  25. package/cjs/segment/segment.d.ts +6 -11
  26. package/cjs/segment/segment.js +40 -82
  27. package/cjs/segment/segment.js.map +1 -1
  28. package/cjs/segment/type.d.ts +3 -5
  29. package/cjs/segment/type.js.map +1 -1
  30. package/cjs/util/index.d.ts +1 -1
  31. package/cjs/util/index.js +1 -1
  32. package/cjs/util/index.js.map +1 -1
  33. package/cjs/util/{label-smartInvert.js → labelSmartInvert.js} +1 -1
  34. package/cjs/util/labelSmartInvert.js.map +1 -0
  35. package/dist/index.js +145 -262
  36. package/dist/index.min.js +1 -1
  37. package/es/index.d.ts +1 -1
  38. package/es/index.js +1 -1
  39. package/es/index.js.map +1 -1
  40. package/es/label/arc.js +1 -1
  41. package/es/label/arc.js.map +1 -1
  42. package/es/label/base.js +1 -1
  43. package/es/label/base.js.map +1 -1
  44. package/es/legend/size/size.d.ts +2 -2
  45. package/es/legend/size/size.js.map +1 -1
  46. package/es/marker/area.d.ts +20 -1
  47. package/es/marker/area.js +36 -38
  48. package/es/marker/area.js.map +1 -1
  49. package/es/marker/base.d.ts +0 -1
  50. package/es/marker/base.js +19 -27
  51. package/es/marker/base.js.map +1 -1
  52. package/es/marker/config.d.ts +1 -1
  53. package/es/marker/config.js.map +1 -1
  54. package/es/marker/line.js +13 -28
  55. package/es/marker/line.js.map +1 -1
  56. package/es/marker/point.d.ts +7 -7
  57. package/es/marker/point.js +4 -5
  58. package/es/marker/point.js.map +1 -1
  59. package/es/marker/type.d.ts +5 -8
  60. package/es/marker/type.js.map +1 -1
  61. package/es/segment/segment.d.ts +6 -11
  62. package/es/segment/segment.js +41 -81
  63. package/es/segment/segment.js.map +1 -1
  64. package/es/segment/type.d.ts +3 -5
  65. package/es/segment/type.js.map +1 -1
  66. package/es/util/index.d.ts +1 -1
  67. package/es/util/index.js +1 -1
  68. package/es/util/index.js.map +1 -1
  69. package/es/util/{label-smartInvert.js → labelSmartInvert.js} +1 -1
  70. package/es/util/labelSmartInvert.js.map +1 -0
  71. package/package.json +4 -4
  72. package/cjs/marker/util.d.ts +0 -1
  73. package/cjs/marker/util.js +0 -3
  74. package/cjs/marker/util.js.map +0 -1
  75. package/cjs/util/label-smartInvert.js.map +0 -1
  76. package/cjs/util/limit-shape.d.ts +0 -3
  77. package/cjs/util/limit-shape.js +0 -14
  78. package/cjs/util/limit-shape.js.map +0 -1
  79. package/es/marker/util.d.ts +0 -1
  80. package/es/marker/util.js +0 -3
  81. package/es/marker/util.js.map +0 -1
  82. package/es/util/label-smartInvert.js.map +0 -1
  83. package/es/util/limit-shape.d.ts +0 -3
  84. package/es/util/limit-shape.js +0 -8
  85. package/es/util/limit-shape.js.map +0 -1
  86. /package/cjs/util/{label-smartInvert.d.ts → labelSmartInvert.d.ts} +0 -0
  87. /package/es/util/{label-smartInvert.d.ts → labelSmartInvert.d.ts} +0 -0
@@ -13,14 +13,12 @@ export type SymbolAttributes = {
13
13
  };
14
14
  export interface SegmentAttributes extends IGroupGraphicAttribute {
15
15
  visible?: boolean;
16
- multiSegment?: boolean;
17
- mainSegmentIndex?: number;
18
- points: Point[] | Point[][];
16
+ points: Point[];
19
17
  startSymbol?: SymbolAttributes;
20
18
  endSymbol?: SymbolAttributes;
21
- lineStyle?: Partial<ILineGraphicAttribute> | Partial<ILineGraphicAttribute>[];
19
+ lineStyle?: Partial<ILineGraphicAttribute>;
22
20
  state?: {
23
- line?: State<Partial<ILineGraphicAttribute> | Partial<ILineGraphicAttribute>[]>;
21
+ line?: State<Partial<ILineGraphicAttribute>>;
24
22
  symbol?: State<Partial<ISymbolGraphicAttribute>>;
25
23
  };
26
24
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/segment/type.ts"],"names":[],"mappings":"","file":"type.js","sourcesContent":["import type {\n IGraphicAttribute,\n IGroupGraphicAttribute,\n ILineGraphicAttribute,\n ISymbolGraphicAttribute,\n SymbolType\n} from '@visactor/vrender';\nimport type { Point, State } from '../core/type';\n\nexport type SymbolAttributes = {\n /** 是否展示 symbol */\n visible: boolean;\n /**\n * symbol 形状,默认为带左右方向的箭头\n */\n symbolType?: SymbolType;\n /**\n * symbol 大小\n */\n size?: number;\n /**\n * 自动旋转,沿着线的方向,默认 true\n */\n autoRotate?: boolean;\n /**\n * symbol 相对line平行方向上的偏移\n */\n refX?: number;\n /**\n * symbol 相对line正交方向上的偏移\n */\n refY?: number;\n /**\n * symbol 相对默认角度的偏移\n * @description (@chensiji: 默认角度为笛卡尔坐标系y正方向,即默认symbol包围盒的角度为笛卡尔坐标系y正方向, 做自动旋转时, 会在此基础上,将包围盒转换到line平行方向上。)\n */\n refAngle?: number;\n /**\n * symbol 是否clip line,即当symbol fill为false时,line在symbol内部的部分是否展示\n * @defalut false\n */\n clip?: boolean;\n /**\n * symbol 样式配置\n */\n style?: Partial<IGraphicAttribute>;\n};\n\nexport interface SegmentAttributes extends IGroupGraphicAttribute {\n /**\n * 可见性\n * @default true\n */\n visible?: boolean;\n /**\n * 是否对 points 进行多段处理,默认为 false,即直接将所有的点连接成线。\n * 如果需要进行多段处理,需要将 points 属性配置为 Point[][] 类型\n * @default false\n */\n multiSegment?: boolean;\n /**\n * 在 `multiSegment` 属性开启的前提下,用于声明那一段线段用来作为主线段,如果不声明,默认全段为主线段\n */\n mainSegmentIndex?: number;\n points: Point[] | Point[][];\n /** 轴线起始点 symbol 配置 */\n startSymbol?: SymbolAttributes;\n /** 轴线末端 symbol 配置 */\n endSymbol?: SymbolAttributes;\n /**\n * 线样式配置\n */\n lineStyle?: Partial<ILineGraphicAttribute> | Partial<ILineGraphicAttribute>[];\n\n state?: {\n line?: State<Partial<ILineGraphicAttribute> | Partial<ILineGraphicAttribute>[]>;\n symbol?: State<Partial<ISymbolGraphicAttribute>>;\n };\n}\n"]}
1
+ {"version":3,"sources":["../src/segment/type.ts"],"names":[],"mappings":"","file":"type.js","sourcesContent":["import type {\n IGraphicAttribute,\n IGroupGraphicAttribute,\n ILineGraphicAttribute,\n ISymbolGraphicAttribute,\n SymbolType\n} from '@visactor/vrender';\nimport type { Point, State } from '../core/type';\n\nexport type SymbolAttributes = {\n /** 是否展示 symbol */\n visible: boolean;\n /**\n * symbol 形状,默认为带左右方向的箭头\n */\n symbolType?: SymbolType;\n /**\n * symbol 大小\n */\n size?: number;\n /**\n * 自动旋转,沿着线的方向,默认 true\n */\n autoRotate?: boolean;\n /**\n * symbol 相对line平行方向上的偏移\n */\n refX?: number;\n /**\n * symbol 相对line正交方向上的偏移\n */\n refY?: number;\n /**\n * symbol 相对默认角度的偏移\n * @description (@chensiji: 默认角度为笛卡尔坐标系y正方向,即默认symbol包围盒的角度为笛卡尔坐标系y正方向, 做自动旋转时, 会在此基础上,将包围盒转换到line平行方向上。)\n */\n refAngle?: number;\n /**\n * symbol 是否clip line,即当symbol fill为false时,line在symbol内部的部分是否展示\n * @defalut false\n */\n clip?: boolean;\n /**\n * symbol 样式配置\n */\n style?: Partial<IGraphicAttribute>;\n};\n\nexport interface SegmentAttributes extends IGroupGraphicAttribute {\n /**\n * 可见性\n * @default true\n */\n visible?: boolean;\n points: Point[];\n /** 轴线起始点 symbol 配置 */\n startSymbol?: SymbolAttributes;\n /** 轴线末端 symbol 配置 */\n endSymbol?: SymbolAttributes;\n /**\n * 线样式配置\n */\n lineStyle?: Partial<ILineGraphicAttribute>;\n\n state?: {\n line?: State<Partial<ILineGraphicAttribute>>;\n symbol?: State<Partial<ISymbolGraphicAttribute>>;\n };\n}\n"]}
@@ -1,4 +1,4 @@
1
1
  export * from './common';
2
- export * from './label-smartInvert';
2
+ export * from './labelSmartInvert';
3
3
  export * from './matrix';
4
4
  export * from './text';
package/cjs/util/index.js CHANGED
@@ -17,6 +17,6 @@ var __createBinding = this && this.__createBinding || (Object.create ? function(
17
17
 
18
18
  Object.defineProperty(exports, "__esModule", {
19
19
  value: !0
20
- }), __exportStar(require("./common"), exports), __exportStar(require("./label-smartInvert"), exports),
20
+ }), __exportStar(require("./common"), exports), __exportStar(require("./labelSmartInvert"), exports),
21
21
  __exportStar(require("./matrix"), exports), __exportStar(require("./text"), exports);
22
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/util/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,sDAAoC;AACpC,2CAAyB;AACzB,yCAAuB","file":"index.js","sourcesContent":["export * from './common';\nexport * from './label-smartInvert';\nexport * from './matrix';\nexport * from './text';\n"]}
1
+ {"version":3,"sources":["../src/util/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,qDAAmC;AACnC,2CAAyB;AACzB,yCAAuB","file":"index.js","sourcesContent":["export * from './common';\nexport * from './labelSmartInvert';\nexport * from './matrix';\nexport * from './text';\n"]}
@@ -60,4 +60,4 @@ function smartInvertStrategy(fillStrategy, baseColor, invertColor, similarColor)
60
60
 
61
61
  exports.labelSmartInvert = labelSmartInvert, exports.contrastAccessibilityChecker = contrastAccessibilityChecker,
62
62
  exports.smartInvertStrategy = smartInvertStrategy;
63
- //# sourceMappingURL=label-smartInvert.js.map
63
+ //# sourceMappingURL=labelSmartInvert.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/util/labelSmartInvert.ts"],"names":[],"mappings":";;;AACA,6CAA6C;AAE7C,MAAM,wBAAwB,GAAa,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;AAQlE,SAAgB,gBAAgB,CAC9B,qBAAyC,EACzC,qBAAyC,EACzC,QAA6B,EAC7B,uBAAgC,EAChC,iBAAqC;IAErC,MAAM,eAAe,GAAG,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;IAChE,MAAM,eAAe,GAAG,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;IAChE,IAAI,CAAC,4BAA4B,CAAC,eAAe,EAAE,eAAe,EAAE,QAAQ,EAAE,uBAAuB,CAAC,EAAE;QACtG,OAAO,sBAAsB,CAC3B,eAAe,EACf,eAAe,EACf,QAAQ,EACR,uBAAuB,EACvB,iBAAiB,CAClB,CAAC;KACH;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAnBD,4CAmBC;AASD,SAAS,sBAAsB,CAC7B,eAAmC,EACnC,eAAmC,EACnC,QAA6B,EAC7B,uBAAgC,EAChC,iBAAqC;IAErC,MAAM,wBAAwB,GAAa,EAAE,CAAC;IAC9C,IAAI,iBAAiB,EAAE;QACrB,IAAI,iBAAiB,YAAY,KAAK,EAAE;YACtC,wBAAwB,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,CAAC;SACrD;aAAM;YACL,wBAAwB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;SAClD;KACF;IACD,wBAAwB,CAAC,IAAI,CAAC,GAAG,wBAAwB,CAAC,CAAC;IAC3D,KAAK,MA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,aAAtB,WAAW,uBAAX,WAAW,CAAa,QAAQ,CAAC,GAAG,CAAC,EAAE;QAC1C,OAAO,WAAW,CAAC;KACpB;IACD,MAAM,CAAC,GAAG,IAAI,kBAAS,CAAC,KAAK,CAAC,WAAqB,CAAC,CAAC;IACrD,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC;IAC5B,OAAO,GAAG,GAAG,kBAAS,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3C,CAAC;AAED,SAAgB,mBAAmB,CACjC,YAAoB,EACpB,SAAiB,EACjB,WAAmB,EACnB,YAAoB;IAEpB,IAAI,MAAM,CAAC;IACX,QAAQ,YAAY,EAAE;QACpB,KAAK,MAAM;YACT,MAAM,GAAG,SAAS,CAAC;YACnB,MAAM;QACR,KAAK,YAAY;YACf,MAAM,GAAG,WAAW,CAAC;YACrB,MAAM;QACR,KAAK,aAAa;YAChB,MAAM,GAAG,YAAY,CAAC;QACxB;YACE,MAAM;KACT;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AApBD,kDAoBC","file":"labelSmartInvert.js","sourcesContent":["import type { IColor } from '@visactor/vrender';\nimport { ColorUtil } from '@visactor/vutils';\n\nconst defaultAlternativeColors: string[] = ['#ffffff', '#000000'];\n\n/**\n * 标签智能反色\n * @param foregroundColorOrigin\n * @param backgroundColorOrogin\n * @returns\n */\nexport function labelSmartInvert(\n foregroundColorOrigin: IColor | undefined,\n backgroundColorOrogin: IColor | undefined,\n textType?: string | undefined,\n contrastRatiosThreshold?: number,\n alternativeColors?: string | string[]\n): IColor | undefined {\n const foregroundColor = formatColorToHex(foregroundColorOrigin);\n const backgroundColor = formatColorToHex(backgroundColorOrogin);\n if (!contrastAccessibilityChecker(foregroundColor, backgroundColor, textType, contrastRatiosThreshold)) {\n return improveContrastReverse(\n foregroundColor,\n backgroundColor,\n textType,\n contrastRatiosThreshold,\n alternativeColors\n );\n }\n return foregroundColor;\n}\n\n/**\n * 提升对比度\n * 对于对比度不足阈值的情况,推荐备选颜色色板中的颜色提升对比\n * @param foregroundColor\n * @param backgroundColor\n * @returns\n */\nfunction improveContrastReverse(\n foregroundColor: IColor | undefined,\n backgroundColor: IColor | undefined,\n textType?: IColor | undefined,\n contrastRatiosThreshold?: number,\n alternativeColors?: string | string[]\n) {\n const alternativeColorPalletes: string[] = [];\n if (alternativeColors) {\n if (alternativeColors instanceof Array) {\n alternativeColorPalletes.push(...alternativeColors);\n } else {\n alternativeColorPalletes.push(alternativeColors);\n }\n }\n alternativeColorPalletes.push(...defaultAlternativeColors);\n for (const alternativeColor of alternativeColorPalletes) {\n if (foregroundColor === alternativeColor) {\n continue;\n }\n if (contrastAccessibilityChecker(alternativeColor, backgroundColor, textType, contrastRatiosThreshold)) {\n return alternativeColor;\n }\n }\n return undefined;\n}\n\n/**\n * 颜色对比度可行性检查 https://webaim.org/articles/contrast/\n * - WCAG 2.0 AA 级要求普通文本的对比度至少为 4.5:1,大文本的对比度至少为 3:1。(目前按照此标准)\n * - WCAG 2.1 要求图形和用户界面组件(例如表单输入边框)的对比度至少为 3:1。\n * - WCAG AAA 级要求普通文本的对比度至少为 7:1,大文本的对比度至少为 4.5:1。\n * @param foregroundColor\n * @param backgroundColor\n * @returns\n */\nexport function contrastAccessibilityChecker(\n foregroundColor: IColor | undefined,\n backgroundColor: IColor | undefined,\n textType?: IColor | undefined,\n contrastRatiosThreshold?: number\n): boolean {\n //Contrast ratios can range from 1 to 21\n if (contrastRatiosThreshold) {\n if (contrastRatios(foregroundColor, backgroundColor) > contrastRatiosThreshold) {\n return true;\n }\n return false;\n } else if (textType === 'largeText') {\n if (contrastRatios(foregroundColor, backgroundColor) > 3) {\n return true;\n }\n return false;\n }\n if (contrastRatios(foregroundColor, backgroundColor) > 4.5) {\n return true;\n }\n return false;\n}\n\n/**\n * 计算颜色对比度 https://webaim.org/articles/contrast/\n * Contrast ratios can range from 1 to 21 (commonly written 1:1 to 21:1).\n * (L1 + 0.05) / (L2 + 0.05), whereby:\n * L1 is the relative luminance of the lighter of the colors, and\n * L2 is the relative luminance of the darker of the colors.\n * @param foregroundColor\n * @param backgroundColor\n * @returns\n */\nfunction contrastRatios(foregroundColor: IColor | undefined, backgroundColor: IColor | undefined): number {\n const foregroundColorLuminance = getColorLuminance(foregroundColor as string);\n const backgroundColorLuminance = getColorLuminance(backgroundColor as string);\n const L1 = foregroundColorLuminance > backgroundColorLuminance ? foregroundColorLuminance : backgroundColorLuminance;\n const L2 = foregroundColorLuminance > backgroundColorLuminance ? backgroundColorLuminance : foregroundColorLuminance;\n const contrastRatios = (L1 + 0.05) / (L2 + 0.05);\n return contrastRatios;\n}\n\n/**\n * 计算相对亮度 https://webaim.org/articles/contrast/\n * the relative brightness of any point in a colorspace, normalized to 0 for darkest black and 1 for lightest white\n * Note 1: For the sRGB colorspace, the relative luminance of a color is defined as\n * L = 0.2126 * R + 0.7152 * G + 0.0722 * B where R, G and B are defined as:\n * if RsRGB <= 0.03928 then R = RsRGB/12.92 else R = ((RsRGB+0.055)/1.055) ^ 2.4\n * if GsRGB <= 0.03928 then G = GsRGB/12.92 else G = ((GsRGB+0.055)/1.055) ^ 2.4\n * if BsRGB <= 0.03928 then B = BsRGB/12.92 else B = ((BsRGB+0.055)/1.055) ^ 2.4\n * and RsRGB, GsRGB, and BsRGB are defined as:\n * RsRGB = R8bit/255\n * GsRGB = G8bit/255\n * BsRGB = B8bit/255\n * @param color\n * @returns\n */\nfunction getColorLuminance(color: string): number {\n const rgb8bit = ColorUtil.hexToRgb(color);\n const RsRGB = rgb8bit[0] / 255;\n const GsRGB = rgb8bit[1] / 255;\n const BsRGB = rgb8bit[2] / 255;\n let R;\n let G;\n let B;\n if (RsRGB <= 0.03928) {\n R = RsRGB / 12.92;\n } else {\n R = Math.pow((RsRGB + 0.055) / 1.055, 2.4);\n }\n if (GsRGB <= 0.03928) {\n G = GsRGB / 12.92;\n } else {\n G = Math.pow((GsRGB + 0.055) / 1.055, 2.4);\n }\n if (BsRGB <= 0.03928) {\n B = BsRGB / 12.92;\n } else {\n B = Math.pow((BsRGB + 0.055) / 1.055, 2.4);\n }\n const L = 0.2126 * R + 0.7152 * G + 0.0722 * B;\n return L;\n}\n\n/**\n * 规范化color格式为hex\n * 当color为颜色名称或rgb时,对其进行规范化处理\n * @param originColor\n * @returns\n */\nfunction formatColorToHex(originColor: IColor | undefined) {\n if ((originColor as string)?.includes('#')) {\n return originColor;\n }\n const c = new ColorUtil.Color(originColor as string);\n const { r, g, b } = c.color;\n return '#' + ColorUtil.rgbToHex(r, g, b);\n}\n\nexport function smartInvertStrategy(\n fillStrategy: string,\n baseColor: IColor,\n invertColor: IColor,\n similarColor: IColor\n) {\n let result;\n switch (fillStrategy) {\n case 'base':\n result = baseColor;\n break;\n case 'invertBase':\n result = invertColor;\n break;\n case 'similarBase':\n result = similarColor;\n default:\n break;\n }\n return result;\n}\n"]}