@unovis/ts 1.3.0-beta.3 → 1.3.0

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 (260) hide show
  1. package/components/area/config.d.ts +6 -10
  2. package/components/area/config.js +3 -12
  3. package/components/area/config.js.map +1 -1
  4. package/components/area/index.d.ts +5 -6
  5. package/components/area/index.js +10 -9
  6. package/components/area/index.js.map +1 -1
  7. package/components/axis/config.d.ts +3 -27
  8. package/components/axis/config.js +3 -30
  9. package/components/axis/config.js.map +1 -1
  10. package/components/axis/index.d.ts +4 -3
  11. package/components/axis/index.js +8 -5
  12. package/components/axis/index.js.map +1 -1
  13. package/components/brush/config.d.ts +2 -12
  14. package/components/brush/config.js +11 -20
  15. package/components/brush/config.js.map +1 -1
  16. package/components/brush/index.d.ts +4 -3
  17. package/components/brush/index.js +4 -3
  18. package/components/brush/index.js.map +1 -1
  19. package/components/bullet-legend/config.d.ts +1 -10
  20. package/components/bullet-legend/config.js +11 -14
  21. package/components/bullet-legend/config.js.map +1 -1
  22. package/components/bullet-legend/index.d.ts +4 -3
  23. package/components/bullet-legend/index.js +5 -2
  24. package/components/bullet-legend/index.js.map +1 -1
  25. package/components/chord-diagram/config.d.ts +7 -23
  26. package/components/chord-diagram/config.js +4 -23
  27. package/components/chord-diagram/config.js.map +1 -1
  28. package/components/chord-diagram/index.d.ts +4 -3
  29. package/components/chord-diagram/index.js +8 -7
  30. package/components/chord-diagram/index.js.map +1 -1
  31. package/components/chord-diagram/modules/label.d.ts +3 -3
  32. package/components/chord-diagram/modules/label.js +1 -1
  33. package/components/chord-diagram/modules/label.js.map +1 -1
  34. package/components/chord-diagram/modules/link.d.ts +2 -2
  35. package/components/chord-diagram/modules/link.js.map +1 -1
  36. package/components/chord-diagram/modules/node.d.ts +2 -2
  37. package/components/chord-diagram/modules/node.js.map +1 -1
  38. package/components/chord-diagram/types.d.ts +3 -2
  39. package/components/chord-diagram/types.js.map +1 -1
  40. package/components/crosshair/config.d.ts +4 -14
  41. package/components/crosshair/config.js +3 -16
  42. package/components/crosshair/config.js.map +1 -1
  43. package/components/crosshair/index.d.ts +4 -3
  44. package/components/crosshair/index.js +4 -3
  45. package/components/crosshair/index.js.map +1 -1
  46. package/components/donut/config.d.ts +3 -20
  47. package/components/donut/config.js +3 -24
  48. package/components/donut/config.js.map +1 -1
  49. package/components/donut/index.d.ts +4 -3
  50. package/components/donut/index.js +5 -4
  51. package/components/donut/index.js.map +1 -1
  52. package/components/donut/modules/arc.d.ts +3 -3
  53. package/components/donut/modules/arc.js.map +1 -1
  54. package/components/flow-legend/config.d.ts +1 -11
  55. package/components/flow-legend/config.js +11 -16
  56. package/components/flow-legend/config.js.map +1 -1
  57. package/components/flow-legend/index.d.ts +4 -3
  58. package/components/flow-legend/index.js +5 -2
  59. package/components/flow-legend/index.js.map +1 -1
  60. package/components/free-brush/config.d.ts +2 -12
  61. package/components/free-brush/config.js +11 -20
  62. package/components/free-brush/config.js.map +1 -1
  63. package/components/free-brush/index.d.ts +4 -3
  64. package/components/free-brush/index.js +13 -12
  65. package/components/free-brush/index.js.map +1 -1
  66. package/components/graph/config.d.ts +3 -75
  67. package/components/graph/config.js +13 -79
  68. package/components/graph/config.js.map +1 -1
  69. package/components/graph/index.d.ts +8 -7
  70. package/components/graph/index.js +7 -5
  71. package/components/graph/index.js.map +1 -1
  72. package/components/graph/modules/layout.d.ts +7 -7
  73. package/components/graph/modules/layout.js +7 -2
  74. package/components/graph/modules/layout.js.map +1 -1
  75. package/components/graph/modules/link/helper.d.ts +5 -5
  76. package/components/graph/modules/link/helper.js.map +1 -1
  77. package/components/graph/modules/link/index.d.ts +6 -6
  78. package/components/graph/modules/link/index.js.map +1 -1
  79. package/components/graph/modules/node/helper.d.ts +1 -1
  80. package/components/graph/modules/node/helper.js.map +1 -1
  81. package/components/graph/modules/node/index.d.ts +9 -6
  82. package/components/graph/modules/node/index.js +7 -9
  83. package/components/graph/modules/node/index.js.map +1 -1
  84. package/components/graph/modules/panel/helper.d.ts +4 -4
  85. package/components/graph/modules/panel/helper.js.map +1 -1
  86. package/components/graph/modules/panel/index.d.ts +3 -3
  87. package/components/graph/modules/panel/index.js.map +1 -1
  88. package/components/graph/modules/shape.js +2 -2
  89. package/components/graph/modules/shape.js.map +1 -1
  90. package/components/grouped-bar/config.d.ts +5 -13
  91. package/components/grouped-bar/config.js +3 -16
  92. package/components/grouped-bar/config.js.map +1 -1
  93. package/components/grouped-bar/index.d.ts +5 -9
  94. package/components/grouped-bar/index.js +5 -15
  95. package/components/grouped-bar/index.js.map +1 -1
  96. package/components/leaflet-flow-map/config.d.ts +2 -16
  97. package/components/leaflet-flow-map/config.js +3 -21
  98. package/components/leaflet-flow-map/config.js.map +1 -1
  99. package/components/leaflet-flow-map/index.d.ts +4 -3
  100. package/components/leaflet-flow-map/index.js +3 -2
  101. package/components/leaflet-flow-map/index.js.map +1 -1
  102. package/components/leaflet-map/config.d.ts +4 -59
  103. package/components/leaflet-map/config.js +24 -68
  104. package/components/leaflet-map/config.js.map +1 -1
  105. package/components/leaflet-map/index.d.ts +5 -4
  106. package/components/leaflet-map/index.js +4 -3
  107. package/components/leaflet-map/index.js.map +1 -1
  108. package/components/leaflet-map/modules/clusterBackground.d.ts +4 -2
  109. package/components/leaflet-map/modules/clusterBackground.js.map +1 -1
  110. package/components/leaflet-map/modules/map.d.ts +4 -4
  111. package/components/leaflet-map/modules/map.js +6 -6
  112. package/components/leaflet-map/modules/map.js.map +1 -1
  113. package/components/leaflet-map/modules/node.d.ts +3 -0
  114. package/components/leaflet-map/modules/node.js +8 -12
  115. package/components/leaflet-map/modules/node.js.map +1 -1
  116. package/components/leaflet-map/modules/utils.d.ts +4 -4
  117. package/components/leaflet-map/modules/utils.js +6 -2
  118. package/components/leaflet-map/modules/utils.js.map +1 -1
  119. package/components/leaflet-map/renderer/mapboxgl-layer.d.ts +2 -2
  120. package/components/leaflet-map/renderer/mapboxgl-layer.js.map +1 -1
  121. package/components/leaflet-map/renderer/mapboxgl-utils.d.ts +5 -1
  122. package/components/leaflet-map/renderer/mapboxgl-utils.js +3 -3
  123. package/components/leaflet-map/renderer/mapboxgl-utils.js.map +1 -1
  124. package/components/leaflet-map/style.js.map +1 -1
  125. package/components/leaflet-map/types.d.ts +5 -1
  126. package/components/leaflet-map/types.js.map +1 -1
  127. package/components/line/config.d.ts +6 -11
  128. package/components/line/config.js +3 -13
  129. package/components/line/config.js.map +1 -1
  130. package/components/line/index.d.ts +6 -5
  131. package/components/line/index.js +7 -6
  132. package/components/line/index.js.map +1 -1
  133. package/components/nested-donut/config.d.ts +2 -21
  134. package/components/nested-donut/config.js +3 -24
  135. package/components/nested-donut/config.js.map +1 -1
  136. package/components/nested-donut/index.d.ts +4 -3
  137. package/components/nested-donut/index.js +18 -8
  138. package/components/nested-donut/index.js.map +1 -1
  139. package/components/nested-donut/modules/arc.d.ts +3 -3
  140. package/components/nested-donut/modules/arc.js.map +1 -1
  141. package/components/nested-donut/modules/label.d.ts +2 -2
  142. package/components/nested-donut/modules/label.js.map +1 -1
  143. package/components/nested-donut/style.js.map +1 -1
  144. package/components/sankey/config.d.ts +3 -48
  145. package/components/sankey/config.js +11 -58
  146. package/components/sankey/config.js.map +1 -1
  147. package/components/sankey/index.d.ts +4 -3
  148. package/components/sankey/index.js +3 -2
  149. package/components/sankey/index.js.map +1 -1
  150. package/components/sankey/modules/label.d.ts +7 -7
  151. package/components/sankey/modules/label.js.map +1 -1
  152. package/components/sankey/modules/link.d.ts +12 -2
  153. package/components/sankey/modules/link.js +4 -8
  154. package/components/sankey/modules/link.js.map +1 -1
  155. package/components/sankey/modules/node.d.ts +7 -7
  156. package/components/sankey/modules/node.js +1 -1
  157. package/components/sankey/modules/node.js.map +1 -1
  158. package/components/scatter/config.d.ts +5 -17
  159. package/components/scatter/config.js +3 -19
  160. package/components/scatter/config.js.map +1 -1
  161. package/components/scatter/index.d.ts +4 -3
  162. package/components/scatter/index.js +8 -8
  163. package/components/scatter/index.js.map +1 -1
  164. package/components/scatter/modules/point.d.ts +2 -2
  165. package/components/scatter/modules/point.js.map +1 -1
  166. package/components/scatter/modules/utils.d.ts +2 -2
  167. package/components/scatter/modules/utils.js.map +1 -1
  168. package/components/stacked-bar/config.d.ts +5 -13
  169. package/components/stacked-bar/config.js +3 -16
  170. package/components/stacked-bar/config.js.map +1 -1
  171. package/components/stacked-bar/index.d.ts +4 -3
  172. package/components/stacked-bar/index.js +4 -3
  173. package/components/stacked-bar/index.js.map +1 -1
  174. package/components/timeline/config.d.ts +5 -16
  175. package/components/timeline/config.js +3 -21
  176. package/components/timeline/config.js.map +1 -1
  177. package/components/timeline/index.d.ts +4 -3
  178. package/components/timeline/index.js +4 -3
  179. package/components/timeline/index.js.map +1 -1
  180. package/components/tooltip/config.d.ts +1 -15
  181. package/components/tooltip/config.js +12 -16
  182. package/components/tooltip/config.js.map +1 -1
  183. package/components/tooltip/index.d.ts +6 -4
  184. package/components/tooltip/index.js +15 -6
  185. package/components/tooltip/index.js.map +1 -1
  186. package/components/tooltip/style.d.ts +6 -0
  187. package/components/tooltip/style.js +13 -14
  188. package/components/tooltip/style.js.map +1 -1
  189. package/components/topojson-map/config.d.ts +4 -36
  190. package/components/topojson-map/config.js +3 -38
  191. package/components/topojson-map/config.js.map +1 -1
  192. package/components/topojson-map/index.d.ts +4 -3
  193. package/components/topojson-map/index.js +4 -5
  194. package/components/topojson-map/index.js.map +1 -1
  195. package/components/vis-controls/config.d.ts +1 -5
  196. package/components/vis-controls/config.js +6 -9
  197. package/components/vis-controls/config.js.map +1 -1
  198. package/components/vis-controls/index.d.ts +3 -2
  199. package/components/vis-controls/index.js +5 -2
  200. package/components/vis-controls/index.js.map +1 -1
  201. package/components/xy-labels/config.d.ts +4 -16
  202. package/components/xy-labels/config.js +3 -20
  203. package/components/xy-labels/config.js.map +1 -1
  204. package/components/xy-labels/index.d.ts +4 -3
  205. package/components/xy-labels/index.js +3 -2
  206. package/components/xy-labels/index.js.map +1 -1
  207. package/components/xy-labels/modules/label.d.ts +3 -3
  208. package/components/xy-labels/modules/label.js +1 -1
  209. package/components/xy-labels/modules/label.js.map +1 -1
  210. package/containers/single-container/config.d.ts +2 -4
  211. package/containers/single-container/config.js +3 -8
  212. package/containers/single-container/config.js.map +1 -1
  213. package/containers/single-container/index.d.ts +4 -3
  214. package/containers/single-container/index.js +2 -2
  215. package/containers/single-container/index.js.map +1 -1
  216. package/containers/xy-container/config.d.ts +2 -22
  217. package/containers/xy-container/config.js +3 -26
  218. package/containers/xy-container/config.js.map +1 -1
  219. package/containers/xy-container/index.d.ts +5 -2
  220. package/containers/xy-container/index.js +9 -8
  221. package/containers/xy-container/index.js.map +1 -1
  222. package/core/component/config.d.ts +1 -6
  223. package/core/component/config.js +6 -12
  224. package/core/component/config.js.map +1 -1
  225. package/core/component/index.d.ts +7 -5
  226. package/core/component/index.js +14 -9
  227. package/core/component/index.js.map +1 -1
  228. package/core/container/config.d.ts +1 -21
  229. package/core/container/config.js +21 -25
  230. package/core/container/config.js.map +1 -1
  231. package/core/container/index.d.ts +5 -4
  232. package/core/container/index.js +4 -3
  233. package/core/container/index.js.map +1 -1
  234. package/core/xy-component/config.d.ts +2 -10
  235. package/core/xy-component/config.js +3 -16
  236. package/core/xy-component/config.js.map +1 -1
  237. package/core/xy-component/index.d.ts +5 -4
  238. package/core/xy-component/index.js +2 -0
  239. package/core/xy-component/index.js.map +1 -1
  240. package/data-models/map-graph.d.ts +1 -1
  241. package/data-models/map-graph.js +4 -7
  242. package/data-models/map-graph.js.map +1 -1
  243. package/package.json +3 -1
  244. package/styles/colors.d.ts +2 -2
  245. package/styles/index.d.ts +1 -1
  246. package/styles/patterns.js +2 -1
  247. package/styles/patterns.js.map +1 -1
  248. package/types/accessor.d.ts +5 -5
  249. package/types/component.js +2 -0
  250. package/types/component.js.map +1 -1
  251. package/utils/d3.d.ts +10 -1
  252. package/utils/d3.js.map +1 -1
  253. package/utils/data.d.ts +7 -7
  254. package/utils/data.js +2 -1
  255. package/utils/data.js.map +1 -1
  256. package/utils/text.js +2 -2
  257. package/utils/text.js.map +1 -1
  258. package/core/config/index.d.ts +0 -3
  259. package/core/config/index.js +0 -16
  260. package/core/config/index.js.map +0 -1
@@ -1,8 +1,8 @@
1
- import { ComponentConfigInterface, ComponentConfig } from "../../core/component/config";
1
+ import { ComponentConfigInterface } from "../../core/component/config";
2
2
  import { ColorAccessor, NumericAccessor } from "../../types/accessor";
3
3
  export interface DonutConfigInterface<Datum> extends ComponentConfigInterface {
4
4
  /** Accessor function for getting the unique data record id. Used for more persistent data updates. Default: `(d, i) => d.id ?? i` */
5
- id?: ((d: Datum, i: number, ...any: any[]) => string | number);
5
+ id?: ((d: Datum, i: number, ...any: unknown[]) => string | number);
6
6
  /** Value accessor function. Default: `undefined` */
7
7
  value: NumericAccessor<Datum>;
8
8
  /** Diagram angle range. Default: `[0, 2 * Math.PI]` */
@@ -39,21 +39,4 @@ export interface DonutConfigInterface<Datum> extends ComponentConfigInterface {
39
39
  /** Background angle range. When undefined, the value will be taken from `angleRange`. Default: `undefined` */
40
40
  backgroundAngleRange?: [number, number];
41
41
  }
42
- export declare class DonutConfig<Datum> extends ComponentConfig implements DonutConfigInterface<Datum> {
43
- id: (d: Datum, i: number) => string | number;
44
- value: any;
45
- angleRange: [number, number];
46
- padAngle: number;
47
- sortFunction: any;
48
- cornerRadius: number;
49
- color: any;
50
- radius: any;
51
- arcWidth: number;
52
- centralLabel: any;
53
- centralSubLabel: any;
54
- centralSubLabelWrap: boolean;
55
- showEmptySegments: boolean;
56
- emptySegmentAngle: number;
57
- showBackground: boolean;
58
- backgroundAngleRange: any;
59
- }
42
+ export declare const DonutDefaultConfig: DonutConfigInterface<unknown>;
@@ -1,28 +1,7 @@
1
- import { ComponentConfig } from '../../core/component/config.js';
1
+ import { ComponentDefaultConfig } from '../../core/component/config.js';
2
2
 
3
3
  // Core
4
- class DonutConfig extends ComponentConfig {
5
- constructor() {
6
- super(...arguments);
7
- // eslint-disable-next-line dot-notation
8
- this.id = (d, i) => { var _a; return (_a = d['id']) !== null && _a !== void 0 ? _a : i; };
9
- this.value = undefined;
10
- this.angleRange = [0, 2 * Math.PI];
11
- this.padAngle = 0;
12
- this.sortFunction = undefined;
13
- this.cornerRadius = 0;
14
- this.color = undefined;
15
- this.radius = undefined;
16
- this.arcWidth = 20;
17
- this.centralLabel = undefined;
18
- this.centralSubLabel = undefined;
19
- this.centralSubLabelWrap = true;
20
- this.showEmptySegments = false;
21
- this.emptySegmentAngle = 0.5 * Math.PI / 180;
22
- this.showBackground = true;
23
- this.backgroundAngleRange = undefined;
24
- }
25
- }
4
+ const DonutDefaultConfig = Object.assign(Object.assign({}, ComponentDefaultConfig), { id: (d, i) => { var _a; return (_a = d.id) !== null && _a !== void 0 ? _a : i; }, value: undefined, angleRange: [0, 2 * Math.PI], padAngle: 0, sortFunction: undefined, cornerRadius: 0, color: undefined, radius: undefined, arcWidth: 20, centralLabel: undefined, centralSubLabel: undefined, centralSubLabelWrap: true, showEmptySegments: false, emptySegmentAngle: 0.5 * Math.PI / 180, showBackground: true, backgroundAngleRange: undefined });
26
5
 
27
- export { DonutConfig };
6
+ export { DonutDefaultConfig };
28
7
  //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sources":["../../../src/components/donut/config.ts"],"sourcesContent":["// Core\nimport { ComponentConfigInterface, ComponentConfig } from 'core/component/config'\n\n// Types\nimport { ColorAccessor, NumericAccessor } from 'types/accessor'\n\nexport interface DonutConfigInterface<Datum> extends ComponentConfigInterface {\n /** Accessor function for getting the unique data record id. Used for more persistent data updates. Default: `(d, i) => d.id ?? i` */\n id?: ((d: Datum, i: number, ...any) => string | number);\n /** Value accessor function. Default: `undefined` */\n value: NumericAccessor<Datum>;\n /** Diagram angle range. Default: `[0, 2 * Math.PI]` */\n angleRange?: [number, number];\n /** Pad angle. Default: `0` */\n padAngle?: number;\n /** Custom sort function. Default: `undefined` */\n sortFunction?: (a: Datum, b: Datum) => number;\n /** Corner Radius. Default: `0` */\n cornerRadius?: number;\n /** Color accessor function. Default: `undefined` */\n color?: ColorAccessor<Datum>;\n /** Explicitly set the donut outer radius. Default: `undefined` */\n radius?: number;\n /** Arc width in pixels. Set to `0` if you want to have a pie chart. Default: `20` */\n arcWidth?: number;\n /** Central label accessor function or text. Default: `undefined` */\n centralLabel?: string;\n /** Central sub-label accessor function or text. Default: `undefined` */\n centralSubLabel?: string;\n /** Enables wrapping for the sub-label. Default: `true` */\n centralSubLabelWrap?: boolean;\n /** When true, the component will display empty segments (the ones that have `0` values) as tiny slices.\n * Default: `false`\n */\n showEmptySegments?: boolean;\n /** Angular size for empty segments in radians. Default: `0.5 * Math.PI / 180` */\n emptySegmentAngle?: number;\n /** Show donut background. The color is configurable via\n * the `--vis-donut-background-color` and `--vis-dark-donut-background-color` CSS variables.\n * Default: `true`\n */\n showBackground?: boolean;\n /** Background angle range. When undefined, the value will be taken from `angleRange`. Default: `undefined` */\n backgroundAngleRange?: [number, number];\n}\n\nexport class DonutConfig<Datum> extends ComponentConfig implements DonutConfigInterface<Datum> {\n // eslint-disable-next-line dot-notation\n id = (d: Datum, i: number): string | number => d['id'] ?? i\n value = undefined\n angleRange: [number, number] = [0, 2 * Math.PI]\n padAngle = 0\n sortFunction = undefined\n cornerRadius = 0\n color = undefined\n radius = undefined\n arcWidth = 20\n centralLabel = undefined\n centralSubLabel = undefined\n centralSubLabelWrap = true\n showEmptySegments = false\n emptySegmentAngle = 0.5 * Math.PI / 180\n showBackground = true\n backgroundAngleRange = undefined\n}\n"],"names":[],"mappings":";;AAAA;AA8CM,MAAO,WAAmB,SAAQ,eAAe,CAAA;AAAvD,IAAA,WAAA,GAAA;;;AAEE,QAAA,IAAA,CAAA,EAAE,GAAG,CAAC,CAAQ,EAAE,CAAS,KAAsB,EAAA,IAAA,EAAA,CAAA,CAAA,OAAA,CAAA,EAAA,GAAA,CAAC,CAAC,IAAI,CAAC,mCAAI,CAAC,CAAA,EAAA,CAAA;QAC3D,IAAK,CAAA,KAAA,GAAG,SAAS,CAAA;QACjB,IAAU,CAAA,UAAA,GAAqB,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,CAAA;QAC/C,IAAQ,CAAA,QAAA,GAAG,CAAC,CAAA;QACZ,IAAY,CAAA,YAAA,GAAG,SAAS,CAAA;QACxB,IAAY,CAAA,YAAA,GAAG,CAAC,CAAA;QAChB,IAAK,CAAA,KAAA,GAAG,SAAS,CAAA;QACjB,IAAM,CAAA,MAAA,GAAG,SAAS,CAAA;QAClB,IAAQ,CAAA,QAAA,GAAG,EAAE,CAAA;QACb,IAAY,CAAA,YAAA,GAAG,SAAS,CAAA;QACxB,IAAe,CAAA,eAAA,GAAG,SAAS,CAAA;QAC3B,IAAmB,CAAA,mBAAA,GAAG,IAAI,CAAA;QAC1B,IAAiB,CAAA,iBAAA,GAAG,KAAK,CAAA;QACzB,IAAiB,CAAA,iBAAA,GAAG,GAAG,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,CAAA;QACvC,IAAc,CAAA,cAAA,GAAG,IAAI,CAAA;QACrB,IAAoB,CAAA,oBAAA,GAAG,SAAS,CAAA;KACjC;AAAA;;;;"}
1
+ {"version":3,"file":"config.js","sources":["../../../src/components/donut/config.ts"],"sourcesContent":["// Core\nimport { ComponentConfigInterface, ComponentDefaultConfig } from 'core/component/config'\n\n// Types\nimport { ColorAccessor, NumericAccessor } from 'types/accessor'\n\nexport interface DonutConfigInterface<Datum> extends ComponentConfigInterface {\n /** Accessor function for getting the unique data record id. Used for more persistent data updates. Default: `(d, i) => d.id ?? i` */\n id?: ((d: Datum, i: number, ...any: unknown[]) => string | number);\n /** Value accessor function. Default: `undefined` */\n value: NumericAccessor<Datum>;\n /** Diagram angle range. Default: `[0, 2 * Math.PI]` */\n angleRange?: [number, number];\n /** Pad angle. Default: `0` */\n padAngle?: number;\n /** Custom sort function. Default: `undefined` */\n sortFunction?: (a: Datum, b: Datum) => number;\n /** Corner Radius. Default: `0` */\n cornerRadius?: number;\n /** Color accessor function. Default: `undefined` */\n color?: ColorAccessor<Datum>;\n /** Explicitly set the donut outer radius. Default: `undefined` */\n radius?: number;\n /** Arc width in pixels. Set to `0` if you want to have a pie chart. Default: `20` */\n arcWidth?: number;\n /** Central label accessor function or text. Default: `undefined` */\n centralLabel?: string;\n /** Central sub-label accessor function or text. Default: `undefined` */\n centralSubLabel?: string;\n /** Enables wrapping for the sub-label. Default: `true` */\n centralSubLabelWrap?: boolean;\n /** When true, the component will display empty segments (the ones that have `0` values) as tiny slices.\n * Default: `false`\n */\n showEmptySegments?: boolean;\n /** Angular size for empty segments in radians. Default: `0.5 * Math.PI / 180` */\n emptySegmentAngle?: number;\n /** Show donut background. The color is configurable via\n * the `--vis-donut-background-color` and `--vis-dark-donut-background-color` CSS variables.\n * Default: `true`\n */\n showBackground?: boolean;\n /** Background angle range. When undefined, the value will be taken from `angleRange`. Default: `undefined` */\n backgroundAngleRange?: [number, number];\n}\n\nexport const DonutDefaultConfig: DonutConfigInterface<unknown> = {\n ...ComponentDefaultConfig,\n id: (d: unknown, i: number): string | number => (d as { id: string }).id ?? i,\n value: undefined,\n angleRange: [0, 2 * Math.PI],\n padAngle: 0,\n sortFunction: undefined,\n cornerRadius: 0,\n color: undefined,\n radius: undefined,\n arcWidth: 20,\n centralLabel: undefined,\n centralSubLabel: undefined,\n centralSubLabelWrap: true,\n showEmptySegments: false,\n emptySegmentAngle: 0.5 * Math.PI / 180,\n showBackground: true,\n backgroundAngleRange: undefined,\n}\n"],"names":[],"mappings":";;AAAA;MA8Ca,kBAAkB,GAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAC1B,sBAAsB,CACzB,EAAA,EAAA,EAAE,EAAE,CAAC,CAAU,EAAE,CAAS,KAAsB,EAAA,IAAA,EAAA,CAAA,CAAA,OAAA,MAAC,CAAoB,CAAC,EAAE,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAI,CAAC,CAAA,EAAA,EAC7E,KAAK,EAAE,SAAS,EAChB,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC,EAC5B,QAAQ,EAAE,CAAC,EACX,YAAY,EAAE,SAAS,EACvB,YAAY,EAAE,CAAC,EACf,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,SAAS,EACjB,QAAQ,EAAE,EAAE,EACZ,YAAY,EAAE,SAAS,EACvB,eAAe,EAAE,SAAS,EAC1B,mBAAmB,EAAE,IAAI,EACzB,iBAAiB,EAAE,KAAK,EACxB,iBAAiB,EAAE,GAAG,GAAG,IAAI,CAAC,EAAE,GAAG,GAAG,EACtC,cAAc,EAAE,IAAI,EACpB,oBAAoB,EAAE,SAAS,EAAA;;;;"}
@@ -3,11 +3,12 @@ import { ComponentCore } from "../../core/component";
3
3
  import { SeriesDataModel } from "../../data-models/series";
4
4
  import { Spacing } from "../../types/spacing";
5
5
  import { DonutArcAnimState } from './types';
6
- import { DonutConfig, DonutConfigInterface } from './config';
6
+ import { DonutConfigInterface } from './config';
7
7
  import * as s from './style';
8
- export declare class Donut<Datum> extends ComponentCore<Datum[], DonutConfig<Datum>, DonutConfigInterface<Datum>> {
8
+ export declare class Donut<Datum> extends ComponentCore<Datum[], DonutConfigInterface<Datum>> {
9
9
  static selectors: typeof s;
10
- config: DonutConfig<Datum>;
10
+ protected _defaultConfig: DonutConfigInterface<Datum>;
11
+ config: DonutConfigInterface<Datum>;
11
12
  datamodel: SeriesDataModel<Datum>;
12
13
  arcBackground: Selection<SVGPathElement, unknown, SVGGElement, unknown>;
13
14
  arcGroup: Selection<SVGGElement, unknown, SVGGElement, unknown>;
@@ -4,7 +4,7 @@ import { SeriesDataModel } from '../../data-models/series.js';
4
4
  import { smartTransition } from '../../utils/d3.js';
5
5
  import { getNumber, isNumber, clamp } from '../../utils/data.js';
6
6
  import { wrapSVGText } from '../../utils/text.js';
7
- import { DonutConfig } from './config.js';
7
+ import { DonutDefaultConfig } from './config.js';
8
8
  import { createArc, updateArc, removeArc } from './modules/arc.js';
9
9
  import * as style from './style.js';
10
10
  import { centralLabel, centralSubLabel, segment, segmentExit, background } from './style.js';
@@ -12,12 +12,13 @@ import { centralLabel, centralSubLabel, segment, segmentExit, background } from
12
12
  class Donut extends ComponentCore {
13
13
  constructor(config) {
14
14
  super();
15
- this.config = new DonutConfig();
15
+ this._defaultConfig = DonutDefaultConfig;
16
+ this.config = this._defaultConfig;
16
17
  this.datamodel = new SeriesDataModel();
17
18
  this.arcGen = arc();
18
19
  this.events = {};
19
20
  if (config)
20
- this.config.init(config);
21
+ this.setConfig(config);
21
22
  this.arcBackground = this.g.append('path');
22
23
  this.arcGroup = this.g.append('g');
23
24
  this.centralLabel = this.g.append('text')
@@ -53,7 +54,7 @@ class Donut extends ComponentCore {
53
54
  .endAngle((_d = (_c = config.angleRange) === null || _c === void 0 ? void 0 : _c[1]) !== null && _d !== void 0 ? _d : 2 * Math.PI)
54
55
  .padAngle(config.padAngle)
55
56
  .value(d => getNumber(d.datum, config.value, d.index) || 0)
56
- .sort(config.sortFunction);
57
+ .sort((a, b) => config.sortFunction(a.datum, b.datum));
57
58
  this.arcGroup.attr('transform', `translate(${this._width / 2},${this._height / 2})`);
58
59
  const arcData = pieGen(data).map(d => {
59
60
  const arc = Object.assign(Object.assign({}, d), { data: d.data.datum, index: d.data.index, innerRadius,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/donut/index.ts"],"sourcesContent":["import { Selection } from 'd3-selection'\nimport { pie, arc } from 'd3-shape'\n\n// Core\nimport { ComponentCore } from 'core/component'\nimport { SeriesDataModel } from 'data-models/series'\n\n// Utils\nimport { smartTransition } from 'utils/d3'\nimport { isNumber, clamp, getNumber } from 'utils/data'\nimport { wrapSVGText } from 'utils/text'\n\n// Types\nimport { Spacing } from 'types/spacing'\n\n// Local Types\nimport { DonutArcDatum, DonutArcAnimState, DonutDatum } from './types'\n\n// Config\nimport { DonutConfig, DonutConfigInterface } from './config'\n\n// Modules\nimport { createArc, updateArc, removeArc } from './modules/arc'\n\n// Styles\nimport * as s from './style'\n\nexport class Donut<Datum> extends ComponentCore<Datum[], DonutConfig<Datum>, DonutConfigInterface<Datum>> {\n static selectors = s\n config: DonutConfig<Datum> = new DonutConfig()\n datamodel: SeriesDataModel<Datum> = new SeriesDataModel()\n\n arcBackground: Selection<SVGPathElement, unknown, SVGGElement, unknown>\n arcGroup: Selection<SVGGElement, unknown, SVGGElement, unknown>\n centralLabel: Selection<SVGTextElement, unknown, SVGGElement, unknown>\n centralSubLabel: Selection<SVGTextElement, unknown, SVGGElement, unknown>\n arcGen = arc<DonutArcAnimState>()\n\n events = {\n }\n\n constructor (config?: DonutConfigInterface<Datum>) {\n super()\n if (config) this.config.init(config)\n this.arcBackground = this.g.append('path')\n this.arcGroup = this.g.append('g')\n this.centralLabel = this.g.append('text')\n .attr('class', s.centralLabel)\n this.centralSubLabel = this.g.append('text')\n .attr('class', s.centralSubLabel)\n }\n\n get bleed (): Spacing {\n return { top: 0, bottom: 0, left: 0, right: 0 }\n }\n\n _render (customDuration?: number): void {\n const { config, datamodel, bleed } = this\n\n // Wrap data to preserve original indices\n const data: DonutDatum<Datum>[] = datamodel.data\n .map((d, i) => ({\n index: i,\n datum: d,\n }))\n .filter(d => config.showEmptySegments || getNumber(d.datum, config.value, d.index))\n\n const duration = isNumber(customDuration) ? customDuration : config.duration\n const outerRadius = config.radius || Math.min(this._width - bleed.left - bleed.right, this._height - bleed.top - bleed.bottom) / 2\n const innerRadius = config.arcWidth === 0 ? 0 : clamp(outerRadius - config.arcWidth, 0, outerRadius - 1)\n\n this.arcGen\n .startAngle(d => d.startAngle)\n .endAngle(d => d.endAngle)\n .innerRadius(d => d.innerRadius)\n .outerRadius(d => d.outerRadius)\n .padAngle(d => d.padAngle)\n .cornerRadius(config.cornerRadius)\n\n const pieGen = pie<DonutDatum<Datum>>()\n .startAngle(config.angleRange?.[0] ?? 0)\n .endAngle(config.angleRange?.[1] ?? 2 * Math.PI)\n .padAngle(config.padAngle)\n .value(d => getNumber(d.datum, config.value, d.index) || 0)\n .sort(config.sortFunction)\n\n this.arcGroup.attr('transform', `translate(${this._width / 2},${this._height / 2})`)\n\n const arcData: DonutArcDatum<Datum>[] = pieGen(data).map(d => {\n const arc = {\n ...d,\n data: d.data.datum,\n index: d.data.index,\n innerRadius,\n outerRadius,\n }\n\n if (config.showEmptySegments && d.endAngle - d.startAngle - d.padAngle <= Number.EPSILON) {\n arc.endAngle = d.startAngle + Math.max(config.emptySegmentAngle, config.padAngle)\n arc.padAngle = d.padAngle / 2\n }\n return arc\n })\n\n // Arc segments\n const arcsSelection = this.arcGroup\n .selectAll<SVGPathElement, DonutArcDatum<Datum>>(`.${s.segment}`)\n .data(arcData, (d: DonutArcDatum<Datum>) => config.id(d.data, d.index))\n\n const arcsEnter = arcsSelection.enter().append('path')\n .attr('class', s.segment)\n .call(createArc, config)\n\n const arcsMerged = arcsSelection.merge(arcsEnter)\n arcsMerged.call(updateArc, config, this.arcGen, duration)\n arcsMerged.sort((a, b) => b.value - a.value)\n\n arcsSelection.exit<DonutArcDatum<Datum>>()\n .attr('class', s.segmentExit)\n .call(removeArc, duration)\n\n // Label\n this.centralLabel\n .attr('transform', `translate(${this._width / 2},${this._height / 2})`)\n .attr('dy', config.centralSubLabel ? '-0.55em' : null)\n .text(config.centralLabel ?? null)\n\n this.centralSubLabel\n .attr('transform', `translate(${this._width / 2},${this._height / 2})`)\n .attr('dy', config.centralLabel ? '0.55em' : null)\n .text(config.centralSubLabel ?? null)\n\n if (config.centralSubLabelWrap) wrapSVGText(this.centralSubLabel, innerRadius * 1.9)\n\n // Background\n this.arcBackground.attr('class', s.background)\n .attr('visibility', config.showBackground ? null : 'hidden')\n .attr('transform', `translate(${this._width / 2},${this._height / 2})`)\n\n smartTransition(this.arcBackground, duration)\n .attr('d', this.arcGen({\n startAngle: config.backgroundAngleRange?.[0] ?? config.angleRange?.[0] ?? 0,\n endAngle: config.backgroundAngleRange?.[1] ?? config.angleRange?.[1] ?? 2 * Math.PI,\n innerRadius,\n outerRadius,\n }))\n }\n}\n"],"names":["s.centralLabel","s.centralSubLabel","s.segment","s.segmentExit","s.background","s"],"mappings":";;;;;;;;;;;AA2BM,MAAO,KAAa,SAAQ,aAAuE,CAAA;AAcvG,IAAA,WAAA,CAAa,MAAoC,EAAA;AAC/C,QAAA,KAAK,EAAE,CAAA;AAbT,QAAA,IAAA,CAAA,MAAM,GAAuB,IAAI,WAAW,EAAE,CAAA;AAC9C,QAAA,IAAA,CAAA,SAAS,GAA2B,IAAI,eAAe,EAAE,CAAA;QAMzD,IAAM,CAAA,MAAA,GAAG,GAAG,EAAqB,CAAA;QAEjC,IAAM,CAAA,MAAA,GAAG,EACR,CAAA;AAIC,QAAA,IAAI,MAAM;AAAE,YAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QACpC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAC1C,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAClC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;AACtC,aAAA,IAAI,CAAC,OAAO,EAAEA,YAAc,CAAC,CAAA;QAChC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;AACzC,aAAA,IAAI,CAAC,OAAO,EAAEC,eAAiB,CAAC,CAAA;KACpC;AAED,IAAA,IAAI,KAAK,GAAA;AACP,QAAA,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAA;KAChD;AAED,IAAA,OAAO,CAAE,cAAuB,EA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IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC;AAC1C,aAAA,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC;AACrB,YAAA,UAAU,EAAE,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,MAAA,MAAM,CAAC,oBAAoB,MAAG,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,CAAC,CAAC,MAAI,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAA,CAAA,EAAA,GAAA,MAAM,CAAC,UAAU,0CAAG,CAAC,CAAC,mCAAI,CAAC;YAC3E,QAAQ,EAAE,MAAA,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,MAAM,CAAC,oBAAoB,MAAG,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,CAAC,CAAC,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAI,MAAA,MAAM,CAAC,UAAU,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAG,CAAC,CAAC,mCAAI,CAAC,GAAG,IAAI,CAAC,EAAE;YACnF,WAAW;YACX,WAAW;AACZ,SAAA,CAAC,CAAC,CAAA;KACN;;AAtHM,KAAS,CAAA,SAAA,GAAGC,KAAC;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/components/donut/index.ts"],"sourcesContent":["import { Selection } from 'd3-selection'\nimport { pie, arc } from 'd3-shape'\n\n// Core\nimport { ComponentCore } from 'core/component'\nimport { SeriesDataModel } from 'data-models/series'\n\n// Utils\nimport { smartTransition } from 'utils/d3'\nimport { isNumber, clamp, getNumber } from 'utils/data'\nimport { wrapSVGText } from 'utils/text'\n\n// Types\nimport { Spacing } from 'types/spacing'\n\n// Local Types\nimport { DonutArcDatum, DonutArcAnimState, DonutDatum } from './types'\n\n// Config\nimport { DonutDefaultConfig, DonutConfigInterface } from './config'\n\n// Modules\nimport { createArc, updateArc, removeArc } from './modules/arc'\n\n// Styles\nimport * as s from './style'\n\nexport class Donut<Datum> extends ComponentCore<Datum[], DonutConfigInterface<Datum>> {\n static selectors = s\n protected _defaultConfig = DonutDefaultConfig as DonutConfigInterface<Datum>\n public config: DonutConfigInterface<Datum> = this._defaultConfig\n\n datamodel: SeriesDataModel<Datum> = new SeriesDataModel()\n\n arcBackground: Selection<SVGPathElement, unknown, SVGGElement, unknown>\n arcGroup: Selection<SVGGElement, unknown, SVGGElement, unknown>\n centralLabel: Selection<SVGTextElement, unknown, SVGGElement, unknown>\n centralSubLabel: Selection<SVGTextElement, unknown, SVGGElement, unknown>\n arcGen = arc<DonutArcAnimState>()\n\n events = {\n }\n\n constructor (config?: DonutConfigInterface<Datum>) {\n super()\n if (config) this.setConfig(config)\n this.arcBackground = this.g.append('path')\n this.arcGroup = this.g.append('g')\n this.centralLabel = this.g.append('text')\n .attr('class', s.centralLabel)\n this.centralSubLabel = this.g.append('text')\n .attr('class', s.centralSubLabel)\n }\n\n get bleed (): Spacing {\n return { top: 0, bottom: 0, left: 0, right: 0 }\n }\n\n _render (customDuration?: number): void {\n const { config, datamodel, bleed } = this\n\n // Wrap data to preserve original indices\n const data: DonutDatum<Datum>[] = datamodel.data\n .map((d, i) => ({\n index: i,\n datum: d,\n }))\n .filter(d => config.showEmptySegments || getNumber(d.datum, config.value, d.index))\n\n const duration = isNumber(customDuration) ? customDuration : config.duration\n const outerRadius = config.radius || Math.min(this._width - bleed.left - bleed.right, this._height - bleed.top - bleed.bottom) / 2\n const innerRadius = config.arcWidth === 0 ? 0 : clamp(outerRadius - config.arcWidth, 0, outerRadius - 1)\n\n this.arcGen\n .startAngle(d => d.startAngle)\n .endAngle(d => d.endAngle)\n .innerRadius(d => d.innerRadius)\n .outerRadius(d => d.outerRadius)\n .padAngle(d => d.padAngle)\n .cornerRadius(config.cornerRadius)\n\n const pieGen = pie<DonutDatum<Datum>>()\n .startAngle(config.angleRange?.[0] ?? 0)\n .endAngle(config.angleRange?.[1] ?? 2 * Math.PI)\n .padAngle(config.padAngle)\n .value(d => getNumber(d.datum, config.value, d.index) || 0)\n .sort((a, b) => config.sortFunction(a.datum, b.datum))\n\n this.arcGroup.attr('transform', `translate(${this._width / 2},${this._height / 2})`)\n\n const arcData: DonutArcDatum<Datum>[] = pieGen(data).map(d => {\n const arc = {\n ...d,\n data: d.data.datum,\n index: d.data.index,\n innerRadius,\n outerRadius,\n }\n\n if (config.showEmptySegments && d.endAngle - d.startAngle - d.padAngle <= Number.EPSILON) {\n arc.endAngle = d.startAngle + Math.max(config.emptySegmentAngle, config.padAngle)\n arc.padAngle = d.padAngle / 2\n }\n return arc\n })\n\n // Arc segments\n const arcsSelection = this.arcGroup\n .selectAll<SVGPathElement, DonutArcDatum<Datum>>(`.${s.segment}`)\n .data(arcData, (d: DonutArcDatum<Datum>) => config.id(d.data, d.index))\n\n const arcsEnter = arcsSelection.enter().append('path')\n .attr('class', s.segment)\n .call(createArc, config)\n\n const arcsMerged = arcsSelection.merge(arcsEnter)\n arcsMerged.call(updateArc, config, this.arcGen, duration)\n arcsMerged.sort((a, b) => b.value - a.value)\n\n arcsSelection.exit<DonutArcDatum<Datum>>()\n .attr('class', s.segmentExit)\n .call(removeArc, duration)\n\n // Label\n this.centralLabel\n .attr('transform', `translate(${this._width / 2},${this._height / 2})`)\n .attr('dy', config.centralSubLabel ? '-0.55em' : null)\n .text(config.centralLabel ?? null)\n\n this.centralSubLabel\n .attr('transform', `translate(${this._width / 2},${this._height / 2})`)\n .attr('dy', config.centralLabel ? '0.55em' : null)\n .text(config.centralSubLabel ?? null)\n\n if (config.centralSubLabelWrap) wrapSVGText(this.centralSubLabel, innerRadius * 1.9)\n\n // Background\n this.arcBackground.attr('class', s.background)\n .attr('visibility', config.showBackground ? null : 'hidden')\n .attr('transform', `translate(${this._width / 2},${this._height / 2})`)\n\n smartTransition(this.arcBackground, duration)\n .attr('d', this.arcGen({\n startAngle: config.backgroundAngleRange?.[0] ?? config.angleRange?.[0] ?? 0,\n endAngle: config.backgroundAngleRange?.[1] ?? config.angleRange?.[1] ?? 2 * Math.PI,\n innerRadius,\n outerRadius,\n }))\n }\n}\n"],"names":["s.centralLabel","s.centralSubLabel","s.segment","s.segmentExit","s.background","s"],"mappings":";;;;;;;;;;;AA2BM,MAAO,KAAa,SAAQ,aAAmD,CAAA;AAgBnF,IAAA,WAAA,CAAa,MAAoC,EAAA;AAC/C,QAAA,KAAK,EAAE,CAAA;QAfC,IAAc,CAAA,cAAA,GAAG,kBAAiD,CAAA;AACrE,QAAA,IAAA,CAAA,MAAM,GAAgC,IAAI,CAAC,cAAc,CAAA;AAEhE,QAAA,IAAA,CAAA,SAAS,GAA2B,IAAI,eAAe,EAAE,CAAA;QAMzD,IAAM,CAAA,MAAA,GAAG,GAAG,EAAqB,CAAA;QAEjC,IAAM,CAAA,MAAA,GAAG,EACR,CAAA;AAIC,QAAA,IAAI,MAAM;AAAE,YAAA,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;QAClC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;QAC1C,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAClC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;AACtC,aAAA,IAAI,CAAC,OAAO,EAAEA,YAAc,CAAC,CAAA;QAChC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC;AACzC,aAAA,IAAI,CAAC,OAAO,EAAEC,eAAiB,CAAC,CAAA;KACpC;AAED,IAAA,IAAI,KAAK,GAAA;AACP,QAAA,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EA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AI,CAAC,WAAW,EAAE,CAAa,UAAA,EAAA,IAAI,CAAC,MAAM,GAAG,CAAC,CAAA,CAAA,EAAI,IAAI,CAAC,OAAO,GAAG,CAAC,CAAA,CAAA,CAAG,CAAC,CAAA;AAEzE,QAAA,eAAe,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC;AAC1C,aAAA,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC;AACrB,YAAA,UAAU,EAAE,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,MAAA,MAAM,CAAC,oBAAoB,MAAG,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,CAAC,CAAC,MAAI,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAA,CAAA,EAAA,GAAA,MAAM,CAAC,UAAU,0CAAG,CAAC,CAAC,mCAAI,CAAC;YAC3E,QAAQ,EAAE,MAAA,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,MAAM,CAAC,oBAAoB,MAAG,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAA,CAAC,CAAC,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,EAAA,GAAI,MAAA,MAAM,CAAC,UAAU,MAAA,IAAA,IAAA,EAAA,KAAA,KAAA,CAAA,GAAA,KAAA,CAAA,GAAA,EAAA,CAAG,CAAC,CAAC,mCAAI,CAAC,GAAG,IAAI,CAAC,EAAE;YACnF,WAAW;YACX,WAAW;AACZ,SAAA,CAAC,CAAC,CAAA;KACN;;AAxHM,KAAS,CAAA,SAAA,GAAGC,KAAC;;;;"}
@@ -1,10 +1,10 @@
1
1
  import { Selection } from 'd3-selection';
2
2
  import { Arc } from 'd3-shape';
3
3
  import { DonutArcDatum, DonutArcAnimState } from '../types';
4
- import { DonutConfig } from '../config';
4
+ import { DonutConfigInterface } from '../config';
5
5
  export interface ArcNode extends SVGElement {
6
6
  _animState?: DonutArcAnimState;
7
7
  }
8
- export declare function createArc<Datum>(selection: Selection<SVGPathElement, DonutArcDatum<Datum>, SVGGElement, unknown>, config: DonutConfig<Datum>): void;
9
- export declare function updateArc<Datum>(selection: Selection<SVGPathElement, DonutArcDatum<Datum>, SVGGElement, unknown>, config: DonutConfig<Datum>, arcGen: Arc<any, DonutArcAnimState>, duration: number): void;
8
+ export declare function createArc<Datum>(selection: Selection<SVGPathElement, DonutArcDatum<Datum>, SVGGElement, unknown>, config: DonutConfigInterface<Datum>): void;
9
+ export declare function updateArc<Datum>(selection: Selection<SVGPathElement, DonutArcDatum<Datum>, SVGGElement, unknown>, config: DonutConfigInterface<Datum>, arcGen: Arc<any, DonutArcAnimState>, duration: number): void;
10
10
  export declare function removeArc<Datum>(selection: Selection<SVGPathElement, DonutArcDatum<Datum>, SVGGElement, unknown>, duration: number): void;
@@ -1 +1 @@
1
- {"version":3,"file":"arc.js","sources":["../../../../src/components/donut/modules/arc.ts"],"sourcesContent":["import { Selection } from 'd3-selection'\nimport { Transition } from 'd3-transition'\nimport { interpolate } from 'd3-interpolate'\nimport { Arc } from 'd3-shape'\n\n// Utils\nimport { getColor } from 'utils/color'\nimport { smartTransition } from 'utils/d3'\n\n// Local Types\nimport { DonutArcDatum, DonutArcAnimState } from '../types'\n\n// Config\nimport { DonutConfig } from '../config'\n\nexport interface ArcNode extends SVGElement {\n _animState?: DonutArcAnimState;\n}\n\nexport function createArc<Datum> (\n selection: Selection<SVGPathElement, DonutArcDatum<Datum>, SVGGElement, unknown>,\n config: DonutConfig<Datum>\n): void {\n selection\n .style('fill', d => getColor(d.data, config.color, d.index))\n .style('opacity', 0)\n .each((d, i, els) => {\n const arcNode: ArcNode = els[i]\n const angleCenter = (d.startAngle + d.endAngle) / 2\n const angleHalfWidth = (d.endAngle - d.startAngle) / 2\n arcNode._animState = {\n startAngle: angleCenter - angleHalfWidth,\n endAngle: angleCenter + angleHalfWidth,\n innerRadius: d.innerRadius,\n outerRadius: d.outerRadius,\n padAngle: d.padAngle,\n }\n })\n}\n\nexport function updateArc<Datum> (\n selection: Selection<SVGPathElement, DonutArcDatum<Datum>, SVGGElement, unknown>,\n config: DonutConfig<Datum>,\n arcGen: Arc<any, DonutArcAnimState>,\n duration: number\n): void {\n selection\n .style('transition', `fill ${duration}ms`) // Animate color with CSS because we're using CSS-variables\n .style('fill', d => getColor(d.data, config.color, d.index))\n\n const setOpacity = (d: DonutArcDatum<Datum>): number => (config.showEmptySegments || d.value) ? 1 : 0\n if (duration) {\n const transition = smartTransition(selection, duration)\n .style('opacity', setOpacity) as Transition<SVGPathElement, DonutArcDatum<Datum>, SVGGElement, unknown>\n\n transition.attrTween('d', (d, i, els) => {\n const arcNode: ArcNode = els[i]\n const nextAnimState: DonutArcAnimState = {\n startAngle: d.startAngle,\n endAngle: d.endAngle,\n innerRadius: d.innerRadius,\n outerRadius: d.outerRadius,\n padAngle: d.padAngle,\n }\n const datum = interpolate(arcNode._animState, nextAnimState)\n\n return (t: number): string => {\n arcNode._animState = datum(t)\n return arcGen(arcNode._animState as DonutArcDatum<Datum>)\n }\n })\n } else {\n selection\n .attr('d', arcGen)\n .style('opacity', setOpacity)\n }\n}\n\nexport function removeArc<Datum> (\n selection: Selection<SVGPathElement, DonutArcDatum<Datum>, SVGGElement, unknown>,\n duration: number\n): void {\n smartTransition(selection, duration)\n .style('opacity', 0)\n .remove()\n}\n"],"names":[],"mappings":";;;;AAmBgB,SAAA,SAAS,CACvB,SAAgF,EAChF,MAA0B,EAAA;IAE1B,SAAS;SACN,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;AAC3D,SAAA,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;SACnB,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,KAAI;AAClB,QAAA,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AC,CAAC,CAAA;AAC/B,YAAA,MAAM,aAAa,GAAsB;gBACvC,UAAU,EAAE,CAAC,CAAC,UAAU;gBACxB,QAAQ,EAAE,CAAC,CAAC,QAAQ;gBACpB,WAAW,EAAE,CAAC,CAAC,WAAW;gBAC1B,WAAW,EAAE,CAAC,CAAC,WAAW;gBAC1B,QAAQ,EAAE,CAAC,CAAC,QAAQ;aACrB,CAAA;YACD,MAAM,KAAK,GAAG,WAAW,CAAC,OAAO,CAAC,UAAU,EAAE,aAAa,CAAC,CAAA;YAE5D,OAAO,CAAC,CAAS,KAAY;AAC3B,gBAAA,OAAO,CAAC,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,CAAA;AAC7B,gBAAA,OAAO,MAAM,CAAC,OAAO,CAAC,UAAkC,CAAC,CAAA;AAC3D,aAAC,CAAA;AACH,SAAC,CAAC,CAAA;AACH,KAAA;AAAM,SAAA;QACL,SAAS;AACN,aAAA,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC;AACjB,aAAA,KAAK,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;AAChC,KAAA;AACH,CAAC;AAEe,SAAA,SAAS,CACvB,SAAgF,EAChF,QAAgB,EAAA;AAEhB,IAAA,eAAe,CAAC,SAAS,EAAE,QAAQ,CAAC;AACjC,SAAA,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;AACnB,SAAA,MAAM,EAAE,CAAA;AACb;;;;"}
1
+ {"version":3,"file":"arc.js","sources":["../../../../src/components/donut/modules/arc.ts"],"sourcesContent":["import { Selection } from 'd3-selection'\nimport { Transition } from 'd3-transition'\nimport { interpolate } from 'd3-interpolate'\nimport { Arc } from 'd3-shape'\n\n// Utils\nimport { getColor } from 'utils/color'\nimport { smartTransition } from 'utils/d3'\n\n// Local Types\nimport { DonutArcDatum, DonutArcAnimState } from '../types'\n\n// Config\nimport { DonutConfigInterface } from '../config'\n\nexport interface ArcNode extends SVGElement {\n _animState?: DonutArcAnimState;\n}\n\nexport function createArc<Datum> (\n selection: Selection<SVGPathElement, DonutArcDatum<Datum>, SVGGElement, unknown>,\n config: DonutConfigInterface<Datum>\n): void {\n selection\n .style('fill', d => getColor(d.data, config.color, d.index))\n .style('opacity', 0)\n .each((d, i, els) => {\n const arcNode: ArcNode = els[i]\n const angleCenter = (d.startAngle + d.endAngle) / 2\n const angleHalfWidth = (d.endAngle - d.startAngle) / 2\n arcNode._animState = {\n startAngle: angleCenter - angleHalfWidth,\n endAngle: angleCenter + angleHalfWidth,\n innerRadius: d.innerRadius,\n outerRadius: d.outerRadius,\n padAngle: d.padAngle,\n }\n })\n}\n\nexport function updateArc<Datum> (\n selection: Selection<SVGPathElement, DonutArcDatum<Datum>, SVGGElement, unknown>,\n config: DonutConfigInterface<Datum>,\n arcGen: Arc<any, DonutArcAnimState>,\n duration: number\n): void {\n selection\n .style('transition', `fill ${duration}ms`) // Animate color with CSS because we're using CSS-variables\n .style('fill', d => getColor(d.data, config.color, d.index))\n\n const setOpacity = (d: DonutArcDatum<Datum>): number => (config.showEmptySegments || d.value) ? 1 : 0\n if (duration) {\n const transition = smartTransition(selection, duration)\n .style('opacity', setOpacity) as Transition<SVGPathElement, DonutArcDatum<Datum>, SVGGElement, unknown>\n\n transition.attrTween('d', (d, i, els) => {\n const arcNode: ArcNode = els[i]\n const nextAnimState: DonutArcAnimState = {\n startAngle: d.startAngle,\n endAngle: d.endAngle,\n innerRadius: d.innerRadius,\n outerRadius: d.outerRadius,\n padAngle: d.padAngle,\n }\n const datum = interpolate(arcNode._animState, nextAnimState)\n\n return (t: number): string => {\n arcNode._animState = datum(t)\n return arcGen(arcNode._animState as DonutArcDatum<Datum>)\n }\n })\n } else {\n selection\n .attr('d', arcGen)\n .style('opacity', setOpacity)\n }\n}\n\nexport function removeArc<Datum> (\n selection: Selection<SVGPathElement, DonutArcDatum<Datum>, SVGGElement, unknown>,\n duration: number\n): void {\n smartTransition(selection, duration)\n .style('opacity', 0)\n .remove()\n}\n"],"names":[],"mappings":";;;;AAm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../../core/config";
2
1
  export interface FlowLegendConfigInterface {
3
2
  /** Custom width of the component. Default: `undefined` */
4
3
  customWidth?: number;
@@ -17,13 +16,4 @@ export interface FlowLegendConfigInterface {
17
16
  /** Callback function for the legend item click. Default: `undefined` */
18
17
  onLegendItemClick?: ((label?: string, i?: number) => void);
19
18
  }
20
- export declare class FlowLegendConfig extends Config implements FlowLegendConfigInterface {
21
- customWidth: any;
22
- items: any[];
23
- labelFontSize: number;
24
- lineColor: any;
25
- labelColor: any;
26
- arrowSymbol: string;
27
- arrowColor: any;
28
- onLegendItemClick: any;
29
- }
19
+ export declare const FlowLegendDefaultConfig: FlowLegendConfigInterface;
@@ -1,18 +1,13 @@
1
- import { Config } from '../../core/config/index.js';
1
+ const FlowLegendDefaultConfig = {
2
+ customWidth: undefined,
3
+ items: [],
4
+ labelFontSize: 12,
5
+ lineColor: undefined,
6
+ labelColor: undefined,
7
+ arrowSymbol: '▶',
8
+ arrowColor: undefined,
9
+ onLegendItemClick: undefined,
10
+ };
2
11
 
3
- class FlowLegendConfig extends Config {
4
- constructor() {
5
- super(...arguments);
6
- this.customWidth = undefined;
7
- this.items = [];
8
- this.labelFontSize = 12;
9
- this.lineColor = undefined;
10
- this.labelColor = undefined;
11
- this.arrowSymbol = '▶';
12
- this.arrowColor = undefined;
13
- this.onLegendItemClick = undefined;
14
- }
15
- }
16
-
17
- export { FlowLegendConfig };
12
+ export { FlowLegendDefaultConfig };
18
13
  //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sources":["../../../src/components/flow-legend/config.ts"],"sourcesContent":["import { Config } from 'core/config'\n\nexport interface FlowLegendConfigInterface {\n /** Custom width of the component. Default: `undefined` */\n customWidth?: number;\n /** Legend items array as string[]. Default: `[]` */\n items?: string[];\n /** Color of the flow line. Default: `undefined` */\n lineColor?: string;\n /** Color of the flow label. Default: `undefined` */\n labelColor?: string;\n /** Font size of flow labels in pixels. Default: `12` */\n labelFontSize?: number;\n /** Arrow symbol. Default: `'▶'` */\n arrowSymbol?: string;\n /** Color of the arrow. Default: `undefined` */\n arrowColor?: string;\n /** Callback function for the legend item click. Default: `undefined` */\n onLegendItemClick?: ((label?: string, i?: number) => void);\n}\n\nexport class FlowLegendConfig extends Config implements FlowLegendConfigInterface {\n customWidth = undefined\n items = []\n labelFontSize = 12\n lineColor = undefined\n labelColor = undefined\n arrowSymbol = '▶'\n arrowColor = undefined\n onLegendItemClick = undefined\n}\n"],"names":[],"mappings":";;AAqBM,MAAO,gBAAiB,SAAQ,MAAM,CAAA;AAA5C,IAAA,WAAA,GAAA;;QACE,IAAW,CAAA,WAAA,GAAG,SAAS,CAAA;QACvB,IAAK,CAAA,KAAA,GAAG,EAAE,CAAA;QACV,IAAa,CAAA,aAAA,GAAG,EAAE,CAAA;QAClB,IAAS,CAAA,SAAA,GAAG,SAAS,CAAA;QACrB,IAAU,CAAA,UAAA,GAAG,SAAS,CAAA;QACtB,IAAW,CAAA,WAAA,GAAG,GAAG,CAAA;QACjB,IAAU,CAAA,UAAA,GAAG,SAAS,CAAA;QACtB,IAAiB,CAAA,iBAAA,GAAG,SAAS,CAAA;KAC9B;AAAA;;;;"}
1
+ {"version":3,"file":"config.js","sources":["../../../src/components/flow-legend/config.ts"],"sourcesContent":["export interface FlowLegendConfigInterface {\n /** Custom width of the component. Default: `undefined` */\n customWidth?: number;\n /** Legend items array as string[]. Default: `[]` */\n items?: string[];\n /** Color of the flow line. Default: `undefined` */\n lineColor?: string;\n /** Color of the flow label. Default: `undefined` */\n labelColor?: string;\n /** Font size of flow labels in pixels. Default: `12` */\n labelFontSize?: number;\n /** Arrow symbol. Default: `'▶'` */\n arrowSymbol?: string;\n /** Color of the arrow. Default: `undefined` */\n arrowColor?: string;\n /** Callback function for the legend item click. Default: `undefined` */\n onLegendItemClick?: ((label?: string, i?: number) => void);\n}\n\nexport const FlowLegendDefaultConfig: FlowLegendConfigInterface = {\n customWidth: undefined,\n items: [],\n labelFontSize: 12,\n lineColor: undefined,\n labelColor: undefined,\n arrowSymbol: '▶',\n arrowColor: undefined,\n onLegendItemClick: undefined,\n}\n"],"names":[],"mappings":"AAmBa,MAAA,uBAAuB,GAA8B;AAChE,IAAA,WAAW,EAAE,SAAS;AACtB,IAAA,KAAK,EAAE,EAAE;AACT,IAAA,aAAa,EAAE,EAAE;AACjB,IAAA,SAAS,EAAE,SAAS;AACpB,IAAA,UAAU,EAAE,SAAS;AACrB,IAAA,WAAW,EAAE,GAAG;AAChB,IAAA,UAAU,EAAE,SAAS;AACrB,IAAA,iBAAiB,EAAE,SAAS;;;;;"}
@@ -1,13 +1,14 @@
1
1
  import { Selection } from 'd3-selection';
2
- import { FlowLegendConfig, FlowLegendConfigInterface } from './config';
2
+ import { FlowLegendConfigInterface } from './config';
3
3
  import { FlowLegendItem } from './types';
4
4
  export declare class FlowLegend {
5
5
  div: Selection<HTMLDivElement, unknown, null, undefined>;
6
6
  element: HTMLElement;
7
7
  line: Selection<HTMLDivElement, unknown, null, undefined>;
8
8
  labels: Selection<HTMLDivElement, unknown, null, undefined>;
9
- prevConfig: FlowLegendConfig;
10
- config: FlowLegendConfig;
9
+ protected _defaultConfig: FlowLegendConfigInterface;
10
+ config: FlowLegendConfigInterface;
11
+ prevConfig: FlowLegendConfigInterface;
11
12
  protected _container: HTMLElement;
12
13
  constructor(element: HTMLElement, config?: FlowLegendConfigInterface);
13
14
  update(config: FlowLegendConfigInterface): void;
@@ -1,11 +1,14 @@
1
1
  import { select } from 'd3-selection';
2
2
  import { smartTransition } from '../../utils/d3.js';
3
- import { FlowLegendConfig } from './config.js';
3
+ import { merge } from '../../utils/data.js';
4
+ import { FlowLegendDefaultConfig } from './config.js';
4
5
  import { FlowLegendItemType } from './types.js';
5
6
  import { root, labels, item, arrow, label, clickable, line } from './style.js';
6
7
 
7
8
  class FlowLegend {
8
9
  constructor(element, config) {
10
+ this._defaultConfig = FlowLegendDefaultConfig;
11
+ this.config = this._defaultConfig;
9
12
  this._container = element;
10
13
  this.div = select(this._container).append('div').attr('class', root);
11
14
  this.element = this.div.node();
@@ -16,7 +19,7 @@ class FlowLegend {
16
19
  }
17
20
  update(config) {
18
21
  this.prevConfig = this.config;
19
- this.config = new FlowLegendConfig().init(config);
22
+ this.config = merge(this._defaultConfig, config);
20
23
  this.render();
21
24
  }
22
25
  render() {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../../src/components/flow-legend/index.ts"],"sourcesContent":["import { select, Selection } from 'd3-selection'\n\n// Utils\nimport { smartTransition } from 'utils/d3'\n\n// Config\nimport { FlowLegendConfig, FlowLegendConfigInterface } from './config'\n\n// Local Types\nimport { FlowLegendItem, FlowLegendItemType } from './types'\n\n// Styles\nimport * as s from './style'\n\nexport class FlowLegend {\n div: Selection<HTMLDivElement, unknown, null, undefined>\n element: HTMLElement\n line: Selection<HTMLDivElement, unknown, null, undefined>\n labels: Selection<HTMLDivElement, unknown, null, undefined>\n prevConfig: FlowLegendConfig\n config: FlowLegendConfig\n protected _container: HTMLElement\n\n constructor (element: HTMLElement, config?: FlowLegendConfigInterface) {\n this._container = element\n\n this.div = select(this._container).append('div').attr('class', s.root)\n this.element = this.div.node()\n\n this.line = this.div.append('div')\n this.labels = this.div.append('div').attr('class', s.labels)\n\n if (config) this.update(config)\n }\n\n update (config: FlowLegendConfigInterface): void {\n this.prevConfig = this.config\n this.config = new FlowLegendConfig().init(config)\n this.render()\n }\n\n render (): void {\n const { config } = this\n if (!config.items.length) return\n\n if (config.customWidth) this.div.style('width', `${config.customWidth}px`)\n\n // Prepare Data\n const legendData: FlowLegendItem[] = config.items.reduce((acc, label, i) => {\n acc.push({\n text: label,\n index: i,\n type: FlowLegendItemType.Label,\n })\n\n if (config.arrowSymbol && (acc.length !== config.items.length * 2 - 1)) {\n acc.push({\n text: config.arrowSymbol,\n index: i,\n type: FlowLegendItemType.Symbol,\n })\n }\n return acc\n }, [])\n\n // Draw\n const legendItems = this.labels.selectAll<HTMLDivElement, FlowLegendItem>(`.${s.item}`)\n .data(legendData)\n\n const legendItemsEnter = legendItems.enter()\n .append('div')\n .attr('class', s.item)\n .attr('opacity', 0)\n\n legendItemsEnter.filter(d => d.type === FlowLegendItemType.Label)\n .on('click', this._onItemClick.bind(this))\n\n legendItemsEnter.append('span')\n .attr('class',\n d => d.type === FlowLegendItemType.Symbol\n ? s.arrow(config.arrowColor)\n : s.label(config.labelFontSize, config.labelColor)\n )\n .classed(s.clickable, d => d.type === FlowLegendItemType.Label && !!config.onLegendItemClick)\n\n const legendItemsMerged = legendItemsEnter.merge(legendItems)\n smartTransition(legendItemsMerged, 500)\n .attr('opacity', 1)\n legendItemsMerged.select('span').html(d => d.text)\n\n legendItems.exit().remove()\n\n this.line\n .attr('class', s.line(config.lineColor))\n .style('opacity', config.items.length > 1 ? 1 : 0)\n }\n\n _onItemClick (event: MouseEvent, d: FlowLegendItem): void {\n const { config } = this\n\n if (config.onLegendItemClick) config.onLegendItemClick(d.text, d.index)\n }\n}\n"],"names":["s.root","s.labels","s.item","s.arrow","s.label","s.clickable","s.line"],"mappings":";;;;;;MAca,UAAU,CAAA;IASrB,WAAa,CAAA,OAAoB,EAAE,MAAkC,EAAA;AACnE,QAAA,IAAI,CAAC,UAAU,GAAG,OAAO,CAAA;QAEzB,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,EAAEA,IAAM,CAAC,CAAA;QACtE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAA;QAE9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAClC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,EAAEC,MAAQ,CAAC,CAAA;AAE5D,QAAA,IAAI,MAAM;AAAE,YA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M,EAAE,CAAA;AAE3B,QAAA,IAAI,CAAC,IAAI;aACN,IAAI,CAAC,OAAO,EAAEC,IAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AACvC,aAAA,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;KACrD;IAED,YAAY,CAAE,KAAiB,EAAE,CAAiB,EAAA;AAChD,QAAA,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;QAEvB,IAAI,MAAM,CAAC,iBAAiB;YAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAA;KACxE;AACF;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../../src/components/flow-legend/index.ts"],"sourcesContent":["import { select, Selection } from 'd3-selection'\n\n// Utils\nimport { smartTransition } from 'utils/d3'\nimport { merge } from 'utils/data'\n\n// Config\nimport { FlowLegendDefaultConfig, FlowLegendConfigInterface } from './config'\n\n// Local Types\nimport { FlowLegendItem, FlowLegendItemType } from './types'\n\n// Styles\nimport * as s from './style'\n\nexport class FlowLegend {\n div: Selection<HTMLDivElement, unknown, null, undefined>\n element: HTMLElement\n line: Selection<HTMLDivElement, unknown, null, undefined>\n labels: Selection<HTMLDivElement, unknown, null, undefined>\n protected _defaultConfig = FlowLegendDefaultConfig as FlowLegendConfigInterface\n public config: FlowLegendConfigInterface = this._defaultConfig\n prevConfig: FlowLegendConfigInterface\n protected _container: HTMLElement\n\n constructor (element: HTMLElement, config?: FlowLegendConfigInterface) {\n this._container = element\n\n this.div = select(this._container).append('div').attr('class', s.root)\n this.element = this.div.node()\n\n this.line = this.div.append('div')\n this.labels = this.div.append('div').attr('class', s.labels)\n\n if (config) this.update(config)\n }\n\n update (config: FlowLegendConfigInterface): void {\n this.prevConfig = this.config\n this.config = merge(this._defaultConfig, config)\n this.render()\n }\n\n render (): void {\n const { config } = this\n if (!config.items.length) return\n\n if (config.customWidth) this.div.style('width', `${config.customWidth}px`)\n\n // Prepare Data\n const legendData: FlowLegendItem[] = config.items.reduce((acc, label, i) => {\n acc.push({\n text: label,\n index: i,\n type: FlowLegendItemType.Label,\n })\n\n if (config.arrowSymbol && (acc.length !== config.items.length * 2 - 1)) {\n acc.push({\n text: config.arrowSymbol,\n index: i,\n type: FlowLegendItemType.Symbol,\n })\n }\n return acc\n }, [])\n\n // Draw\n const legendItems = this.labels.selectAll<HTMLDivElement, FlowLegendItem>(`.${s.item}`)\n .data(legendData)\n\n const legendItemsEnter = legendItems.enter()\n .append('div')\n .attr('class', s.item)\n .attr('opacity', 0)\n\n legendItemsEnter.filter(d => d.type === FlowLegendItemType.Label)\n .on('click', this._onItemClick.bind(this))\n\n legendItemsEnter.append('span')\n .attr('class',\n d => d.type === FlowLegendItemType.Symbol\n ? s.arrow(config.arrowColor)\n : s.label(config.labelFontSize, config.labelColor)\n )\n .classed(s.clickable, d => d.type === FlowLegendItemType.Label && !!config.onLegendItemClick)\n\n const legendItemsMerged = legendItemsEnter.merge(legendItems)\n smartTransition(legendItemsMerged, 500)\n .attr('opacity', 1)\n legendItemsMerged.select('span').html(d => d.text)\n\n legendItems.exit().remove()\n\n this.line\n .attr('class', s.line(config.lineColor))\n .style('opacity', config.items.length > 1 ? 1 : 0)\n }\n\n _onItemClick (event: MouseEvent, d: FlowLegendItem): void {\n const { config } = this\n\n if (config.onLegendItemClick) config.onLegendItemClick(d.text, d.index)\n }\n}\n"],"names":["s.root","s.labels","s.item","s.arrow","s.label","s.clickable","s.line"],"mappings":";;;;;;;MAea,UAAU,CAAA;IAUrB,WAAa,CAAA,OAAoB,EAAE,MAAkC,EAAA;QAL3D,IAAc,CAAA,cAAA,GAAG,uBAAoD,CAAA;AACxE,QAAA,IAAA,CAAA,MAAM,GAA8B,IAAI,CAAC,cAAc,CAAA;AAK5D,QAAA,IAAI,CAAC,UAAU,GAAG,OAAO,CAAA;QAEzB,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ACC,SAAW,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,kBAAkB,CAAC,KAAK,IAAI,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAA;QAE/F,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;AAC7D,QAAA,eAAe,CAAC,iBAAiB,EAAE,GAAG,CAAC;AACpC,aAAA,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAA;AACrB,QAAA,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAA;AAElD,QAAA,WAAW,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,CAAA;AAE3B,QAAA,IAAI,CAAC,IAAI;aACN,IAAI,CAAC,OAAO,EAAEC,IAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AACvC,aAAA,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;KACrD;IAED,YAAY,CAAE,KAAiB,EAAE,CAAiB,EAAA;AAChD,QAAA,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,CAAA;QAEvB,IAAI,MAAM,CAAC,iBAAiB;YAAE,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAA;KACxE;AACF;;;;"}
@@ -1,5 +1,5 @@
1
1
  import { D3BrushEvent } from 'd3-brush';
2
- import { XYComponentConfigInterface, XYComponentConfig } from "../../core/xy-component/config";
2
+ import { XYComponentConfigInterface } from "../../core/xy-component/config";
3
3
  import { FreeBrushMode, FreeBrushSelection } from './types';
4
4
  export interface FreeBrushConfigInterface<Datum> extends Partial<XYComponentConfigInterface<Datum>> {
5
5
  /** Brush selection mode. X - horizontal, Y - vertical, XY - both. Default: `FreeBrushMode.X` */
@@ -32,14 +32,4 @@ export interface FreeBrushConfigInterface<Datum> extends Partial<XYComponentConf
32
32
  /** Automatically hide the brush after selection. Default: `true` */
33
33
  autoHide?: boolean;
34
34
  }
35
- export declare class FreeBrushConfig<Datum> extends XYComponentConfig<Datum> implements FreeBrushConfigInterface<Datum> {
36
- onBrush: (s: FreeBrushSelection | undefined, e: D3BrushEvent<unknown>, userDriven: boolean) => void;
37
- onBrushStart: (s: FreeBrushSelection | undefined, e: D3BrushEvent<unknown>, userDriven: boolean) => void;
38
- onBrushMove: (s: FreeBrushSelection | undefined, e: D3BrushEvent<unknown>, userDriven: boolean) => void;
39
- onBrushEnd: (s: FreeBrushSelection | undefined, e: D3BrushEvent<unknown>, userDriven: boolean) => void;
40
- handleWidth: number;
41
- selection: FreeBrushSelection | null | undefined;
42
- selectionMinLength: any;
43
- mode: FreeBrushMode;
44
- autoHide: boolean;
45
- }
35
+ export declare const FreeBrushDefaultConfig: FreeBrushConfigInterface<unknown>;
@@ -1,24 +1,15 @@
1
- import { XYComponentConfig } from '../../core/xy-component/config.js';
1
+ import { XYComponentDefaultConfig } from '../../core/xy-component/config.js';
2
2
  import { FreeBrushMode } from './types.js';
3
3
 
4
- class FreeBrushConfig extends XYComponentConfig {
5
- constructor() {
6
- super(...arguments);
7
- /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */
8
- this.onBrush = (s, e, userDriven) => { };
9
- /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */
10
- this.onBrushStart = (s, e, userDriven) => { };
11
- /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */
12
- this.onBrushMove = (s, e, userDriven) => { };
13
- /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */
14
- this.onBrushEnd = (s, e, userDriven) => { };
15
- this.handleWidth = 1;
16
- this.selection = undefined;
17
- this.selectionMinLength = undefined;
18
- this.mode = FreeBrushMode.X;
19
- this.autoHide = true;
20
- }
21
- }
4
+ const FreeBrushDefaultConfig = Object.assign(Object.assign({}, XYComponentDefaultConfig), {
5
+ /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */
6
+ onBrush: (s, e, userDriven) => { },
7
+ /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */
8
+ onBrushStart: (s, e, userDriven) => { },
9
+ /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */
10
+ onBrushMove: (s, e, userDriven) => { },
11
+ /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */
12
+ onBrushEnd: (s, e, userDriven) => { }, handleWidth: 1, selection: undefined, selectionMinLength: undefined, mode: FreeBrushMode.X, autoHide: true });
22
13
 
23
- export { FreeBrushConfig };
14
+ export { FreeBrushDefaultConfig };
24
15
  //# sourceMappingURL=config.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sources":["../../../src/components/free-brush/config.ts"],"sourcesContent":["import { D3BrushEvent } from 'd3-brush'\nimport { XYComponentConfigInterface, XYComponentConfig } from 'core/xy-component/config'\n\n// Types\nimport { FreeBrushMode, FreeBrushSelection } from './types'\n\n// We extend partial XY config interface because x and y properties are optional for FreeBrush\nexport interface FreeBrushConfigInterface<Datum> extends Partial<XYComponentConfigInterface<Datum>> {\n /** Brush selection mode. X - horizontal, Y - vertical, XY - both. Default: `FreeBrushMode.X` */\n mode?: FreeBrushMode;\n /** Callback function to be called on any Brush event.\n * Default: `(selection: FreeBrushSelection, event: D3BrushEvent<Datum>, userDriven: boolean): void => {}`\n */\n onBrush?: ((selection: FreeBrushSelection | undefined, event: D3BrushEvent<unknown>, userDriven: boolean) => void);\n /** Callback function to be called on the Brush start event.\n * Default: `(selection: FreeBrushSelection, event: D3BrushEvent<unknown>, userDriven: boolean): void => {}`\n */\n onBrushStart?: ((selection: FreeBrushSelection | undefined, event: D3BrushEvent<unknown>, userDriven: boolean) => void);\n /** Callback function to be called on the Brush move event.\n * Default: `(selection: FreeBrushSelection, event: D3BrushEvent<unknown>, userDriven: boolean): void => {}`\n */\n onBrushMove?: ((selection: FreeBrushSelection | undefined, event: D3BrushEvent<unknown>, userDriven: boolean) => void);\n /** Callback function to be called on the Brush end event.\n * Default: `(selection: FreeBrushSelection, event: D3BrushEvent<unknown>, userDriven: boolean)L void => {}`\n */\n onBrushEnd?: ((selection: FreeBrushSelection | undefined, event: D3BrushEvent<unknown>, userDriven: boolean) => void);\n /** Width of the Brush handle. Default: `1` */\n handleWidth?: number;\n /** Brush selection in data space, can be used to force set the selection from outside.\n * In case of two dimensional mode, the selection has the following format: `[[xMin, xMax], [yMin, yMax]]`.\n * This config property gets updated on internal brush events. Default: `undefined`\n */\n selection?: FreeBrushSelection | null | undefined;\n /** Constraint Brush selection to a minimal length in data units. Default: `undefined` */\n selectionMinLength?: number | [number, number];\n /** Automatically hide the brush after selection. Default: `true` */\n autoHide?: boolean;\n}\n\nexport class FreeBrushConfig<Datum> extends XYComponentConfig<Datum> implements FreeBrushConfigInterface<Datum> {\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */\n onBrush = (s: FreeBrushSelection | undefined, e: D3BrushEvent<unknown>, userDriven: boolean): void => {}\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */\n onBrushStart = (s: FreeBrushSelection | undefined, e: D3BrushEvent<unknown>, userDriven: boolean): void => {}\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */\n onBrushMove = (s: FreeBrushSelection | undefined, e: D3BrushEvent<unknown>, userDriven: boolean): void => {}\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */\n onBrushEnd = (s: FreeBrushSelection | undefined, e: D3BrushEvent<unknown>, userDriven: boolean): void => {}\n handleWidth = 1\n selection: FreeBrushSelection | null | undefined = undefined\n selectionMinLength = undefined\n mode: FreeBrushMode = FreeBrushMode.X\n autoHide = true\n}\n"],"names":[],"mappings":";;;AAuCM,MAAO,eAAuB,SAAQ,iBAAwB,CAAA;AAApE,IAAA,WAAA,GAAA;;;QAEE,IAAO,CAAA,OAAA,GAAG,CAAC,CAAiC,EAAE,CAAwB,EAAE,UAAmB,KAAY,GAAC,CAAA;;QAExG,IAAY,CAAA,YAAA,GAAG,CAAC,CAAiC,EAAE,CAAwB,EAAE,UAAmB,KAAY,GAAC,CAAA;;QAE7G,IAAW,CAAA,WAAA,GAAG,CAAC,CAAiC,EAAE,CAAwB,EAAE,UAAmB,KAAY,GAAC,CAAA;;QAE5G,IAAU,CAAA,UAAA,GAAG,CAAC,CAAiC,EAAE,CAAwB,EAAE,UAAmB,KAAY,GAAC,CAAA;QAC3G,IAAW,CAAA,WAAA,GAAG,CAAC,CAAA;QACf,IAAS,CAAA,SAAA,GAA0C,SAAS,CAAA;QAC5D,IAAkB,CAAA,kBAAA,GAAG,SAAS,CAAA;AAC9B,QAAA,IAAA,CAAA,IAAI,GAAkB,aAAa,CAAC,CAAC,CAAA;QACrC,IAAQ,CAAA,QAAA,GAAG,IAAI,CAAA;KAChB;AAAA;;;;"}
1
+ {"version":3,"file":"config.js","sources":["../../../src/components/free-brush/config.ts"],"sourcesContent":["import { D3BrushEvent } from 'd3-brush'\nimport { XYComponentConfigInterface, XYComponentDefaultConfig } from 'core/xy-component/config'\n\n// Types\nimport { FreeBrushMode, FreeBrushSelection } from './types'\n\n// We extend partial XY config interface because x and y properties are optional for FreeBrush\nexport interface FreeBrushConfigInterface<Datum> extends Partial<XYComponentConfigInterface<Datum>> {\n /** Brush selection mode. X - horizontal, Y - vertical, XY - both. Default: `FreeBrushMode.X` */\n mode?: FreeBrushMode;\n /** Callback function to be called on any Brush event.\n * Default: `(selection: FreeBrushSelection, event: D3BrushEvent<Datum>, userDriven: boolean): void => {}`\n */\n onBrush?: ((selection: FreeBrushSelection | undefined, event: D3BrushEvent<unknown>, userDriven: boolean) => void);\n /** Callback function to be called on the Brush start event.\n * Default: `(selection: FreeBrushSelection, event: D3BrushEvent<unknown>, userDriven: boolean): void => {}`\n */\n onBrushStart?: ((selection: FreeBrushSelection | undefined, event: D3BrushEvent<unknown>, userDriven: boolean) => void);\n /** Callback function to be called on the Brush move event.\n * Default: `(selection: FreeBrushSelection, event: D3BrushEvent<unknown>, userDriven: boolean): void => {}`\n */\n onBrushMove?: ((selection: FreeBrushSelection | undefined, event: D3BrushEvent<unknown>, userDriven: boolean) => void);\n /** Callback function to be called on the Brush end event.\n * Default: `(selection: FreeBrushSelection, event: D3BrushEvent<unknown>, userDriven: boolean)L void => {}`\n */\n onBrushEnd?: ((selection: FreeBrushSelection | undefined, event: D3BrushEvent<unknown>, userDriven: boolean) => void);\n /** Width of the Brush handle. Default: `1` */\n handleWidth?: number;\n /** Brush selection in data space, can be used to force set the selection from outside.\n * In case of two dimensional mode, the selection has the following format: `[[xMin, xMax], [yMin, yMax]]`.\n * This config property gets updated on internal brush events. Default: `undefined`\n */\n selection?: FreeBrushSelection | null | undefined;\n /** Constraint Brush selection to a minimal length in data units. Default: `undefined` */\n selectionMinLength?: number | [number, number];\n /** Automatically hide the brush after selection. Default: `true` */\n autoHide?: boolean;\n}\n\nexport const FreeBrushDefaultConfig: FreeBrushConfigInterface<unknown> = {\n ...XYComponentDefaultConfig,\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */\n onBrush: (s: FreeBrushSelection | undefined, e: D3BrushEvent<unknown>, userDriven: boolean): void => {},\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */\n onBrushStart: (s: FreeBrushSelection | undefined, e: D3BrushEvent<unknown>, userDriven: boolean): void => {},\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */\n onBrushMove: (s: FreeBrushSelection | undefined, e: D3BrushEvent<unknown>, userDriven: boolean): void => {},\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/no-empty-function */\n onBrushEnd: (s: FreeBrushSelection | undefined, e: D3BrushEvent<unknown>, userDriven: boolean): void => {},\n handleWidth: 1,\n selection: undefined,\n selectionMinLength: undefined,\n mode: FreeBrushMode.X,\n autoHide: true,\n}\n"],"names":[],"mappings":";;;AAuCO,MAAM,sBAAsB,GAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,EAAA,EAC9B,wBAAwB,CAAA,EAAA;;IAE3B,OAAO,EAAE,CAAC,CAAiC,EAAE,CAAwB,EAAE,UAAmB,KAAU,GAAG;;IAEvG,YAAY,EAAE,CAAC,CAAiC,EAAE,CAAwB,EAAE,UAAmB,KAAU,GAAG;;IAE5G,WAAW,EAAE,CAAC,CAAiC,EAAE,CAAwB,EAAE,UAAmB,KAAU,GAAG;;AAE3G,IAAA,UAAU,EAAE,CAAC,CAAiC,EAAE,CAAwB,EAAE,UAAmB,QAAa,EAC1G,WAAW,EAAE,CAAC,EACd,SAAS,EAAE,SAAS,EACpB,kBAAkB,EAAE,SAAS,EAC7B,IAAI,EAAE,aAAa,CAAC,CAAC,EACrB,QAAQ,EAAE,IAAI;;;;"}
@@ -1,9 +1,10 @@
1
1
  import { XYComponentCore } from "../../core/xy-component";
2
- import { FreeBrushConfig, FreeBrushConfigInterface } from './config';
2
+ import { FreeBrushConfigInterface } from './config';
3
3
  import * as s from './style';
4
- export declare class FreeBrush<Datum> extends XYComponentCore<Datum, FreeBrushConfig<Datum>, FreeBrushConfigInterface<Datum>> {
4
+ export declare class FreeBrush<Datum> extends XYComponentCore<Datum, FreeBrushConfigInterface<Datum>> {
5
5
  static selectors: typeof s;
6
- config: FreeBrushConfig<Datum>;
6
+ protected _defaultConfig: FreeBrushConfigInterface<Datum>;
7
+ config: FreeBrushConfigInterface<Datum>;
7
8
  private brush;
8
9
  private brushBehaviour;
9
10
  private _firstRender;
@@ -1,25 +1,25 @@
1
1
  import { brush as brush$1, brushY, brushX } from 'd3-brush';
2
2
  import { XYComponentCore } from '../../core/xy-component/index.js';
3
- import { isNumber, clamp } from '../../utils/data.js';
3
+ import { isNumber, isArray, clamp } from '../../utils/data.js';
4
4
  import { smartTransition } from '../../utils/d3.js';
5
5
  import { FreeBrushMode } from './types.js';
6
- import { FreeBrushConfig } from './config.js';
6
+ import { FreeBrushDefaultConfig } from './config.js';
7
7
  import * as style from './style.js';
8
8
  import { brush, hide } from './style.js';
9
9
 
10
10
  class FreeBrush extends XYComponentCore {
11
11
  constructor(config) {
12
12
  super();
13
- this.config = new FreeBrushConfig();
13
+ this._defaultConfig = FreeBrushDefaultConfig;
14
+ this.config = this._defaultConfig;
14
15
  this._firstRender = true;
15
16
  if (config)
16
- this.config.init(config);
17
+ this.setConfig(config);
17
18
  this.brush = this.g
18
19
  .append('g')
19
20
  .attr('class', brush);
20
21
  }
21
22
  _render(customDuration) {
22
- var _a, _b, _c, _d;
23
23
  const { config } = this;
24
24
  const xScale = this.xScale;
25
25
  const yScale = this.yScale;
@@ -54,8 +54,9 @@ class FreeBrush extends XYComponentCore {
54
54
  let brushRange;
55
55
  switch (config.mode) {
56
56
  case FreeBrushMode.XY: {
57
- const xSelectionRange = this._dataRangeToPixelRange([(_a = config.selection) === null || _a === void 0 ? void 0 : _a[0][0], (_b = config.selection) === null || _b === void 0 ? void 0 : _b[0][1]], xScale);
58
- const ySelectionRange = this._dataRangeToPixelRange([(_c = config.selection) === null || _c === void 0 ? void 0 : _c[1][0], (_d = config.selection) === null || _d === void 0 ? void 0 : _d[1][1]], yScale, true);
57
+ const selection = config.selection;
58
+ const xSelectionRange = this._dataRangeToPixelRange([selection === null || selection === void 0 ? void 0 : selection[0][0], selection === null || selection === void 0 ? void 0 : selection[0][1]], xScale);
59
+ const ySelectionRange = this._dataRangeToPixelRange([selection === null || selection === void 0 ? void 0 : selection[1][0], selection === null || selection === void 0 ? void 0 : selection[1][1]], yScale, true);
59
60
  brushRange = (xSelectionRange && ySelectionRange) ? [[xSelectionRange[0], ySelectionRange[0]], [xSelectionRange[1], ySelectionRange[1]]] : null;
60
61
  break;
61
62
  }
@@ -73,7 +74,6 @@ class FreeBrush extends XYComponentCore {
73
74
  this._firstRender = false;
74
75
  }
75
76
  _onBrush(event) {
76
- var _a, _b, _c, _d;
77
77
  const { config } = this;
78
78
  const userDriven = !!(event === null || event === void 0 ? void 0 : event.sourceEvent);
79
79
  // Selection from the brush events is in Screen Space (pixels)
@@ -88,8 +88,9 @@ class FreeBrush extends XYComponentCore {
88
88
  let selectedDomain;
89
89
  switch (config.mode) {
90
90
  case FreeBrushMode.XY: {
91
- const xSelection = this._pixelRangeToDataRange([s[0][0], s[1][0]], this.xScale, (_b = (_a = config.selectionMinLength) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : config.selectionMinLength);
92
- const ySelection = this._pixelRangeToDataRange([s[0][1], s[1][1]], this.yScale, (_d = (_c = config.selectionMinLength) === null || _c === void 0 ? void 0 : _c[1]) !== null && _d !== void 0 ? _d : config.selectionMinLength, true);
91
+ const selection = s;
92
+ const xSelection = this._pixelRangeToDataRange([selection[0][0], selection[1][0]], this.xScale, isArray(config.selectionMinLength) ? config.selectionMinLength[0] : config.selectionMinLength);
93
+ const ySelection = this._pixelRangeToDataRange([selection[0][1], selection[1][1]], this.yScale, isArray(config.selectionMinLength) ? config.selectionMinLength[1] : config.selectionMinLength, true);
93
94
  selectedDomain = (xSelection && ySelection) ? [
94
95
  [xSelection === null || xSelection === void 0 ? void 0 : xSelection[0], xSelection === null || xSelection === void 0 ? void 0 : xSelection[1]],
95
96
  [ySelection === null || ySelection === void 0 ? void 0 : ySelection[0], ySelection === null || ySelection === void 0 ? void 0 : ySelection[1]],
@@ -97,12 +98,12 @@ class FreeBrush extends XYComponentCore {
97
98
  break;
98
99
  }
99
100
  case FreeBrushMode.Y: {
100
- selectedDomain = this._pixelRangeToDataRange(s, this.yScale, config.selectionMinLength, true);
101
+ selectedDomain = this._pixelRangeToDataRange(s, this.yScale, isArray(config.selectionMinLength) ? config.selectionMinLength[1] : config.selectionMinLength, true);
101
102
  break;
102
103
  }
103
104
  case FreeBrushMode.X:
104
105
  default: {
105
- selectedDomain = this._pixelRangeToDataRange(s, this.xScale, config.selectionMinLength);
106
+ selectedDomain = this._pixelRangeToDataRange(s, this.xScale, isArray(config.selectionMinLength) ? config.selectionMinLength[0] : config.selectionMinLength);
106
107
  break;
107
108
  }
108
109
  }