@bino-bi/bn-template-engine 1.0.0-alpha.0 → 1.0.0-alpha.11

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 (361) hide show
  1. package/LICENSE +203 -21
  2. package/dist/bn-template-engine/bn-template-engine.esm.js +1 -1
  3. package/dist/bn-template-engine/p-095f74d7.entry.js +1 -0
  4. package/dist/bn-template-engine/p-14318b0d.entry.js +1 -0
  5. package/dist/bn-template-engine/{p-c9f050bf.entry.js → p-2133e02b.entry.js} +1 -1
  6. package/dist/bn-template-engine/p-6b469808.entry.js +1 -0
  7. package/dist/bn-template-engine/p-7HSTE79g.js +1 -0
  8. package/dist/bn-template-engine/p-B4JfKvVT.js +1 -0
  9. package/dist/bn-template-engine/p-B_d-jp99.js +2 -0
  10. package/dist/bn-template-engine/p-Bi2wx-el.js +1 -0
  11. package/dist/bn-template-engine/p-CWiZks2h.js +1 -0
  12. package/dist/bn-template-engine/{p-BQp6ZPYW.js → p-DSXNgKLa.js} +1 -1
  13. package/dist/bn-template-engine/p-c2cbb8ea.entry.js +1 -0
  14. package/dist/bn-template-engine/p-e783733e.entry.js +1 -0
  15. package/dist/bn-template-engine/p-e94b4e31.entry.js +1 -0
  16. package/dist/bn-template-engine/p-fdb3e99a.entry.js +1 -0
  17. package/dist/cjs/bn-asset_21.cjs.entry.js +23995 -0
  18. package/dist/cjs/bn-grid.cjs.entry.js +6 -13
  19. package/dist/cjs/bn-image.cjs.entry.js +6 -13
  20. package/dist/cjs/bn-internationalization.cjs.entry.js +5 -7
  21. package/dist/cjs/bn-template-engine.cjs.js +2 -2
  22. package/dist/cjs/bn-template.cjs.entry.js +4 -6
  23. package/dist/cjs/bn-text.cjs.entry.js +10 -19
  24. package/dist/cjs/bn-tree.cjs.entry.js +11 -14
  25. package/dist/cjs/{context-protocol-BkYHFkXE.js → context-protocol-B_jipZpJ.js} +6 -2
  26. package/dist/cjs/editor-companion.cjs.entry.js +3 -3
  27. package/dist/cjs/{index-CScBFiS1.js → index-CDKG4xmO.js} +2 -2
  28. package/dist/cjs/loader.cjs.js +2 -2
  29. package/dist/cjs/scaling-eyzCrFB8.js +329 -0
  30. package/dist/cjs/{withBodyObserver-B0_W1VOf.js → withBodyObserver-D7BKWN2N.js} +2 -2
  31. package/dist/cjs/{withHasError-Dspb3lIV.js → withHasError-Cl2gTQzA.js} +106 -2
  32. package/dist/{esm/luxon-DbyXf6dF.js → cjs/withStyled-V7xz_x1c.js} +1406 -1
  33. package/dist/collection/collection-manifest.json +2 -10
  34. package/dist/collection/components/bn-body/bn-body.css +1 -0
  35. package/dist/collection/components/bn-card/bn-card.css +2 -0
  36. package/dist/collection/components/bn-chart-structure/bn-chart-structure.js +368 -130
  37. package/dist/collection/components/bn-chart-structure/ibcs-chart-structure.js +34 -10
  38. package/dist/collection/components/bn-chart-structure/utils/StructureChart.js +94 -11
  39. package/dist/collection/components/bn-chart-structure/utils/elements/Label.js +11 -0
  40. package/dist/collection/components/bn-chart-structure/utils/elements/StackedBar.js +8 -6
  41. package/dist/collection/components/bn-chart-structure/utils/model/styles/StructureChartStyle.js +4 -0
  42. package/dist/collection/components/bn-chart-time/bn-chart-time.css +1 -1
  43. package/dist/collection/components/bn-chart-time/bn-chart-time.js +172 -51
  44. package/dist/collection/components/bn-chart-time/ibcs-chart-time.js +22 -9
  45. package/dist/collection/components/bn-chart-time/utils/TimeChart.js +3 -3
  46. package/dist/collection/components/bn-chart-time/utils/elements/StackedColumn.js +3 -4
  47. package/dist/collection/components/bn-chart-time/utils/model/styles/TimeChartStyle.js +4 -0
  48. package/dist/collection/components/bn-dataset/bn-dataset.js +49 -2
  49. package/dist/collection/components/bn-datasource/bn-datasource.js +173 -8
  50. package/dist/collection/components/bn-layout-card/bn-layout-card.css +3 -2
  51. package/dist/collection/components/bn-layout-card/bn-layout-card.js +207 -32
  52. package/dist/collection/components/bn-layout-page/bn-layout-page.css +1 -3
  53. package/dist/collection/components/bn-layout-page/bn-layout-page.js +172 -43
  54. package/dist/collection/components/bn-message/bn-message.js +1 -1
  55. package/dist/collection/components/bn-page/bn-page.js +1 -1
  56. package/dist/collection/components/bn-scaling-group/bn-scaling-group.css +3 -0
  57. package/dist/collection/components/bn-scaling-group/bn-scaling-group.js +136 -0
  58. package/dist/collection/components/bn-table/bn-table.js +201 -58
  59. package/dist/collection/components/bn-table/ibcs-table.css +7 -5
  60. package/dist/collection/components/bn-table/ibcs-table.js +91 -5
  61. package/dist/collection/components/bn-table/utils/elements/CellBarChart.js +79 -31
  62. package/dist/collection/components/bn-table/utils/elements/TableRow.js +3 -1
  63. package/dist/collection/components/bn-table/utils/factories/tableDataSetFactory.js +12 -3
  64. package/dist/collection/components/bn-table/utils/helper/ColumnStatistics.js +9 -1
  65. package/dist/collection/components/bn-template/bn-template.js +1 -1
  66. package/dist/collection/components/bn-text/bn-text.js +1 -1
  67. package/dist/collection/components/bn-title/bn-title.js +1 -9
  68. package/dist/collection/components/bn-title/ibcs-title/ibcs-title.js +1 -4
  69. package/dist/collection/components/bn-tree/bn-tree.js +5 -1
  70. package/dist/collection/components/editor-companion/editor-companion.js +1 -1
  71. package/dist/collection/stores/componentStyles.js +2 -0
  72. package/dist/collection/stores/createScopedStores.js +3 -1
  73. package/dist/collection/utils/DateStringFactory.js +0 -1
  74. package/dist/collection/utils/constants.js +35 -5
  75. package/dist/collection/utils/contentDecoder.js +28 -0
  76. package/dist/collection/utils/layoutObserver.js +88 -0
  77. package/dist/collection/utils/parentDimensions.js +57 -10
  78. package/dist/collection/utils/stackColors.js +2 -2
  79. package/dist/collection/utils/validate.js +5 -2
  80. package/dist/collection/utils/withInheritedProps.js +152 -0
  81. package/dist/collection/utils/withScalingGroup.js +66 -0
  82. package/dist/components/DataFormatDigits.js +1 -1
  83. package/dist/components/DateStringFactory.js +1 -1
  84. package/dist/components/Order.js +1 -1
  85. package/dist/components/SVGVariancesStyleGroup.js +1 -1
  86. package/dist/components/bn-body2.js +1 -1
  87. package/dist/components/bn-card2.js +1 -1
  88. package/dist/components/bn-chart-structure.js +1 -1
  89. package/dist/components/bn-chart-time.js +1 -1
  90. package/dist/components/bn-dataset.js +1 -1
  91. package/dist/components/bn-datasource.js +1 -1
  92. package/dist/components/bn-layout-card.js +1 -1
  93. package/dist/components/bn-layout-page.js +1 -1
  94. package/dist/components/bn-message2.js +1 -1
  95. package/dist/components/bn-page2.js +1 -1
  96. package/dist/components/{test-runner-time.d.ts → bn-scaling-group.d.ts} +4 -4
  97. package/dist/components/bn-scaling-group.js +1 -0
  98. package/dist/components/bn-table.js +1 -1
  99. package/dist/components/bn-template.js +1 -1
  100. package/dist/components/bn-text.js +1 -1
  101. package/dist/components/bn-title2.js +1 -1
  102. package/dist/components/bn-tree.js +1 -1
  103. package/dist/components/contentDecoder.js +1 -0
  104. package/dist/components/context-protocol.js +1 -1
  105. package/dist/components/editor-companion.js +1 -1
  106. package/dist/components/emotion-hash.esm.js +1 -0
  107. package/dist/components/ibcs-chart-structure2.js +1 -1
  108. package/dist/components/ibcs-chart-time2.js +1 -1
  109. package/dist/components/ibcs-table2.js +1 -1
  110. package/dist/components/ibcs-title2.js +1 -1
  111. package/dist/components/ibcsRuleSet.js +1 -1
  112. package/dist/components/layoutObserver.js +1 -0
  113. package/dist/components/scaling.js +1 -1
  114. package/dist/components/validate.js +1 -1
  115. package/dist/components/withHasError.js +1 -1
  116. package/dist/components/withInheritedProps.js +1 -0
  117. package/dist/components/withStyled.js +1 -1
  118. package/dist/esm/bn-asset_21.entry.js +23973 -0
  119. package/dist/esm/bn-grid.entry.js +4 -11
  120. package/dist/esm/bn-image.entry.js +4 -11
  121. package/dist/esm/bn-internationalization.entry.js +4 -6
  122. package/dist/esm/bn-template-engine.js +3 -3
  123. package/dist/esm/bn-template.entry.js +3 -5
  124. package/dist/esm/bn-text.entry.js +6 -15
  125. package/dist/esm/bn-tree.entry.js +9 -12
  126. package/dist/esm/{context-protocol-DzeqZxg6.js → context-protocol-D-o_UZ33.js} +6 -2
  127. package/dist/esm/editor-companion.entry.js +3 -3
  128. package/dist/esm/{index-B27Ax6P_.js → index-B_d-jp99.js} +2 -2
  129. package/dist/esm/loader.js +3 -3
  130. package/dist/esm/scaling-BzbiBnuN.js +324 -0
  131. package/dist/esm/{withBodyObserver-gZpZiEIK.js → withBodyObserver-AFk2wwHT.js} +2 -2
  132. package/dist/esm/{withHasError-C48fTE2k.js → withHasError-DW_vMDUp.js} +106 -2
  133. package/dist/{cjs/luxon-8hyy5YD7.js → esm/withStyled-5RqF8WBL.js} +1371 -2
  134. package/dist/types/components/bn-chart-structure/bn-chart-structure.d.ts +163 -110
  135. package/dist/types/components/bn-chart-structure/ibcs-chart-structure.d.ts +4 -3
  136. package/dist/types/components/bn-chart-structure/utils/StructureChart.d.ts +7 -0
  137. package/dist/types/components/bn-chart-structure/utils/elements/Label.d.ts +2 -0
  138. package/dist/types/components/bn-chart-structure/utils/model/styles/StructureChartStyle.d.ts +1 -0
  139. package/dist/types/components/bn-chart-time/bn-chart-time.d.ts +29 -12
  140. package/dist/types/components/bn-chart-time/ibcs-chart-time.d.ts +4 -3
  141. package/dist/types/components/bn-chart-time/utils/model/styles/TimeChartStyle.d.ts +1 -0
  142. package/dist/types/components/bn-dataset/bn-dataset.d.ts +6 -0
  143. package/dist/types/components/bn-datasource/bn-datasource.d.ts +48 -5
  144. package/dist/types/components/bn-layout-card/bn-layout-card.d.ts +153 -0
  145. package/dist/types/components/bn-layout-page/bn-layout-page.d.ts +160 -1
  146. package/dist/types/components/bn-scaling-group/bn-scaling-group.d.ts +37 -0
  147. package/dist/types/components/bn-table/bn-table.d.ts +32 -17
  148. package/dist/types/components/bn-table/ibcs-table.d.ts +20 -0
  149. package/dist/types/components/bn-table/utils/elements/Cell.d.ts +1 -0
  150. package/dist/types/components/bn-table/utils/elements/CellBarChart.d.ts +1 -0
  151. package/dist/types/components/bn-title/bn-title.d.ts +0 -1
  152. package/dist/types/components.d.ts +438 -461
  153. package/dist/types/context/context-protocol.d.ts +2 -1
  154. package/dist/types/stores/componentStyles.d.ts +2 -0
  155. package/dist/types/stores/createScopedStores.d.ts +1 -0
  156. package/dist/types/utils/constants.d.ts +23 -5
  157. package/dist/types/utils/contentDecoder.d.ts +12 -0
  158. package/dist/types/utils/layoutObserver.d.ts +27 -0
  159. package/dist/types/utils/parentDimensions.d.ts +7 -2
  160. package/dist/types/utils/validate.d.ts +1 -0
  161. package/dist/types/utils/withInheritedProps.d.ts +38 -0
  162. package/dist/types/utils/withScalingGroup.d.ts +14 -0
  163. package/package.json +4 -4
  164. package/readme.md +2 -3
  165. package/dist/bn-template-engine/assets/gpx/Chasing_Legends.gpx +0 -195076
  166. package/dist/bn-template-engine/assets/gpx/Fahrt_am_Nachmittag.gpx +0 -142007
  167. package/dist/bn-template-engine/assets/icons/gpx-finish.png +0 -0
  168. package/dist/bn-template-engine/assets/icons/gpx-shadow.png +0 -0
  169. package/dist/bn-template-engine/assets/icons/gpx-start.png +0 -0
  170. package/dist/bn-template-engine/assets/icons/marker-example.png +0 -0
  171. package/dist/bn-template-engine/assets/icons/pin-icon-end.png +0 -0
  172. package/dist/bn-template-engine/assets/icons/pin-icon-start.png +0 -0
  173. package/dist/bn-template-engine/assets/icons/pin-icon-wpt.png +0 -0
  174. package/dist/bn-template-engine/assets/icons/pin-shadow.png +0 -0
  175. package/dist/bn-template-engine/assets/icons/pin.png +0 -0
  176. package/dist/bn-template-engine/p--TeDldm8.js +0 -1
  177. package/dist/bn-template-engine/p-0e7dc113.entry.js +0 -1
  178. package/dist/bn-template-engine/p-1jFf17Vj.js +0 -1
  179. package/dist/bn-template-engine/p-264c6bad.entry.js +0 -1
  180. package/dist/bn-template-engine/p-326a0902.entry.js +0 -1
  181. package/dist/bn-template-engine/p-38a8bde3.entry.js +0 -1
  182. package/dist/bn-template-engine/p-577eafcd.entry.js +0 -1
  183. package/dist/bn-template-engine/p-5905cc43.entry.js +0 -1
  184. package/dist/bn-template-engine/p-5d155a72.entry.js +0 -1
  185. package/dist/bn-template-engine/p-65f8962a.entry.js +0 -1
  186. package/dist/bn-template-engine/p-6b8d1ebf.entry.js +0 -1
  187. package/dist/bn-template-engine/p-7995acb2.entry.js +0 -1
  188. package/dist/bn-template-engine/p-7afe431e.entry.js +0 -1
  189. package/dist/bn-template-engine/p-8014b1ac.entry.js +0 -1
  190. package/dist/bn-template-engine/p-80423fc8.entry.js +0 -1
  191. package/dist/bn-template-engine/p-91e74d42.entry.js +0 -1
  192. package/dist/bn-template-engine/p-930a9e29.entry.js +0 -1
  193. package/dist/bn-template-engine/p-93C9jL8R.js +0 -1
  194. package/dist/bn-template-engine/p-93ff8584.entry.js +0 -1
  195. package/dist/bn-template-engine/p-B0m0U4wJ.js +0 -1
  196. package/dist/bn-template-engine/p-B27Ax6P_.js +0 -2
  197. package/dist/bn-template-engine/p-B79VcHiT.js +0 -1
  198. package/dist/bn-template-engine/p-BBd0ZVLL.js +0 -1
  199. package/dist/bn-template-engine/p-BFTU3MAI.js +0 -1
  200. package/dist/bn-template-engine/p-BFatTBqh.js +0 -1
  201. package/dist/bn-template-engine/p-BYmPQYxx.js +0 -1
  202. package/dist/bn-template-engine/p-BhEQy-2D.js +0 -1
  203. package/dist/bn-template-engine/p-BtVfu16B.js +0 -1
  204. package/dist/bn-template-engine/p-CY1RzLjU.js +0 -1
  205. package/dist/bn-template-engine/p-CfWnag33.js +0 -1
  206. package/dist/bn-template-engine/p-CnI71OA9.js +0 -1
  207. package/dist/bn-template-engine/p-Cp4MVxCu.js +0 -1
  208. package/dist/bn-template-engine/p-DbyXf6dF.js +0 -1
  209. package/dist/bn-template-engine/p-TdL-LRR9.js +0 -1
  210. package/dist/bn-template-engine/p-_LBTIfNN.js +0 -1
  211. package/dist/bn-template-engine/p-a342cd3c.entry.js +0 -1
  212. package/dist/bn-template-engine/p-ad94cf63.entry.js +0 -1
  213. package/dist/bn-template-engine/p-bc37d750.entry.js +0 -1
  214. package/dist/bn-template-engine/p-d07a0ca3.entry.js +0 -1
  215. package/dist/bn-template-engine/p-e5f372af.entry.js +0 -1
  216. package/dist/bn-template-engine/p-e620028c.entry.js +0 -1
  217. package/dist/bn-template-engine/p-e81e116a.entry.js +0 -1
  218. package/dist/bn-template-engine/p-eca98070.entry.js +0 -1
  219. package/dist/bn-template-engine/p-ee6de950.entry.js +0 -1
  220. package/dist/bn-template-engine/p-efe0ef1e.entry.js +0 -1
  221. package/dist/bn-template-engine/p-f034f1b8.entry.js +0 -1
  222. package/dist/bn-template-engine/p-f1c1a8a3.entry.js +0 -1
  223. package/dist/bn-template-engine/p-fe573a1a.entry.js +0 -1
  224. package/dist/bn-template-engine/p-kMyLevYy.js +0 -1
  225. package/dist/cjs/DataFormatDigits-DmTbhF8q.js +0 -142
  226. package/dist/cjs/DateStringFactory-Dn0aRj2Y.js +0 -453
  227. package/dist/cjs/Order-B4NIqQWe.js +0 -129
  228. package/dist/cjs/SVGVariancesStyleGroup-Czizhngt.js +0 -7973
  229. package/dist/cjs/StringAdapter-0EbYMkR0.js +0 -136
  230. package/dist/cjs/_commonjsHelpers-BJu3ubxk.js +0 -10
  231. package/dist/cjs/alasql.min-C_nHTuEQ.js +0 -306
  232. package/dist/cjs/bn-asset.cjs.entry.js +0 -42
  233. package/dist/cjs/bn-body_3.cjs.entry.js +0 -413
  234. package/dist/cjs/bn-card.cjs.entry.js +0 -37
  235. package/dist/cjs/bn-chart-structure.cjs.entry.js +0 -705
  236. package/dist/cjs/bn-chart-time.cjs.entry.js +0 -987
  237. package/dist/cjs/bn-component-style.cjs.entry.js +0 -44
  238. package/dist/cjs/bn-context_5.cjs.entry.js +0 -3380
  239. package/dist/cjs/bn-dataset.cjs.entry.js +0 -278
  240. package/dist/cjs/bn-layout-card.cjs.entry.js +0 -128
  241. package/dist/cjs/bn-layout-page.cjs.entry.js +0 -142
  242. package/dist/cjs/bn-map.cjs.entry.js +0 -425
  243. package/dist/cjs/bn-message.cjs.entry.js +0 -52
  244. package/dist/cjs/componentRegister-C17UFNPh.js +0 -72
  245. package/dist/cjs/constants-DHqQXSSd.js +0 -158
  246. package/dist/cjs/formatter-DIJL_crx.js +0 -215
  247. package/dist/cjs/ibcs-chart-structure.cjs.entry.js +0 -2906
  248. package/dist/cjs/ibcs-chart-time.cjs.entry.js +0 -4140
  249. package/dist/cjs/ibcs-map.cjs.entry.js +0 -1075
  250. package/dist/cjs/ibcs-title.cjs.entry.js +0 -352
  251. package/dist/cjs/scaling-B23eOtsC.js +0 -67
  252. package/dist/cjs/test-runner-card.cjs.entry.js +0 -27
  253. package/dist/cjs/test-runner-chart-time.cjs.entry.js +0 -230
  254. package/dist/cjs/test-runner-chart.cjs.entry.js +0 -326
  255. package/dist/cjs/test-runner-map.cjs.entry.js +0 -1862
  256. package/dist/cjs/test-runner-table.cjs.entry.js +0 -477
  257. package/dist/cjs/test-runner-time.cjs.entry.js +0 -381
  258. package/dist/cjs/test-runner-title.cjs.entry.js +0 -115
  259. package/dist/cjs/withComponentStatus-BrxL7usr.js +0 -39
  260. package/dist/cjs/withComponentStyle-C6KHnZHt.js +0 -128
  261. package/dist/cjs/withDataset-ZdN-RRTx.js +0 -146
  262. package/dist/cjs/withStyled-Bf-stJTR.js +0 -567
  263. package/dist/cjs/withTranslation-Cz0M5maV.js +0 -77
  264. package/dist/collection/components/bn-map/bn-map.css +0 -4
  265. package/dist/collection/components/bn-map/bn-map.js +0 -725
  266. package/dist/collection/components/bn-map/ibcs-map/assets/gpx/Chasing_Legends.gpx +0 -195076
  267. package/dist/collection/components/bn-map/ibcs-map/assets/gpx/Fahrt_am_Nachmittag.gpx +0 -142007
  268. package/dist/collection/components/bn-map/ibcs-map/assets/icons/gpx-finish.png +0 -0
  269. package/dist/collection/components/bn-map/ibcs-map/assets/icons/gpx-shadow.png +0 -0
  270. package/dist/collection/components/bn-map/ibcs-map/assets/icons/gpx-start.png +0 -0
  271. package/dist/collection/components/bn-map/ibcs-map/assets/icons/marker-example.png +0 -0
  272. package/dist/collection/components/bn-map/ibcs-map/assets/icons/pin-icon-end.png +0 -0
  273. package/dist/collection/components/bn-map/ibcs-map/assets/icons/pin-icon-start.png +0 -0
  274. package/dist/collection/components/bn-map/ibcs-map/assets/icons/pin-icon-wpt.png +0 -0
  275. package/dist/collection/components/bn-map/ibcs-map/assets/icons/pin-shadow.png +0 -0
  276. package/dist/collection/components/bn-map/ibcs-map/assets/icons/pin.png +0 -0
  277. package/dist/collection/components/bn-map/ibcs-map/ibcs-map.css +0 -674
  278. package/dist/collection/components/bn-map/ibcs-map/ibcs-map.js +0 -744
  279. package/dist/collection/components/bn-map/ibcs-map/utils/model/GeoJsonLayer.js +0 -9
  280. package/dist/collection/components/bn-map/ibcs-map/utils/model/GpxLayer.js +0 -13
  281. package/dist/collection/components/bn-map/ibcs-map/utils/model/Marker.js +0 -11
  282. package/dist/collection/components/bn-map/ibcs-map/utils/model/index.js +0 -2
  283. package/dist/collection/test-runner/test-runner-card.js +0 -36
  284. package/dist/collection/test-runner/test-runner-chart-time.js +0 -234
  285. package/dist/collection/test-runner/test-runner-chart.js +0 -364
  286. package/dist/collection/test-runner/test-runner-map.js +0 -1901
  287. package/dist/collection/test-runner/test-runner-table.js +0 -469
  288. package/dist/collection/test-runner/test-runner-time.js +0 -399
  289. package/dist/collection/test-runner/test-runner-title.js +0 -108
  290. package/dist/components/bn-map.d.ts +0 -11
  291. package/dist/components/bn-map.js +0 -1
  292. package/dist/components/componentRegister.js +0 -1
  293. package/dist/components/ibcs-map.d.ts +0 -11
  294. package/dist/components/ibcs-map.js +0 -1
  295. package/dist/components/ibcs-map2.js +0 -1
  296. package/dist/components/test-runner-card.d.ts +0 -11
  297. package/dist/components/test-runner-card.js +0 -1
  298. package/dist/components/test-runner-chart-time.d.ts +0 -11
  299. package/dist/components/test-runner-chart-time.js +0 -1
  300. package/dist/components/test-runner-chart.d.ts +0 -11
  301. package/dist/components/test-runner-chart.js +0 -1
  302. package/dist/components/test-runner-map.d.ts +0 -11
  303. package/dist/components/test-runner-map.js +0 -1
  304. package/dist/components/test-runner-table.d.ts +0 -11
  305. package/dist/components/test-runner-table.js +0 -1
  306. package/dist/components/test-runner-time.js +0 -1
  307. package/dist/components/test-runner-title.d.ts +0 -11
  308. package/dist/components/test-runner-title.js +0 -1
  309. package/dist/components/withDataset.js +0 -1
  310. package/dist/esm/DataFormatDigits-Dt6gpIiZ.js +0 -137
  311. package/dist/esm/DateStringFactory-_Qiv0IvF.js +0 -451
  312. package/dist/esm/Order-B4fpLe_f.js +0 -125
  313. package/dist/esm/SVGVariancesStyleGroup-DlWgvpzs.js +0 -7961
  314. package/dist/esm/StringAdapter-BLvo1Krl.js +0 -133
  315. package/dist/esm/_commonjsHelpers-BFTU3MAI.js +0 -7
  316. package/dist/esm/alasql.min-CWu4NkIt.js +0 -304
  317. package/dist/esm/bn-asset.entry.js +0 -40
  318. package/dist/esm/bn-body_3.entry.js +0 -409
  319. package/dist/esm/bn-card.entry.js +0 -35
  320. package/dist/esm/bn-chart-structure.entry.js +0 -703
  321. package/dist/esm/bn-chart-time.entry.js +0 -985
  322. package/dist/esm/bn-component-style.entry.js +0 -42
  323. package/dist/esm/bn-context_5.entry.js +0 -3374
  324. package/dist/esm/bn-dataset.entry.js +0 -276
  325. package/dist/esm/bn-layout-card.entry.js +0 -126
  326. package/dist/esm/bn-layout-page.entry.js +0 -140
  327. package/dist/esm/bn-map.entry.js +0 -423
  328. package/dist/esm/bn-message.entry.js +0 -50
  329. package/dist/esm/componentRegister-BtVfu16B.js +0 -72
  330. package/dist/esm/constants-kMyLevYy.js +0 -158
  331. package/dist/esm/formatter-DTMEZ6d8.js +0 -211
  332. package/dist/esm/ibcs-chart-structure.entry.js +0 -2904
  333. package/dist/esm/ibcs-chart-time.entry.js +0 -4138
  334. package/dist/esm/ibcs-map.entry.js +0 -1073
  335. package/dist/esm/ibcs-title.entry.js +0 -350
  336. package/dist/esm/scaling-BBd0ZVLL.js +0 -64
  337. package/dist/esm/test-runner-card.entry.js +0 -25
  338. package/dist/esm/test-runner-chart-time.entry.js +0 -228
  339. package/dist/esm/test-runner-chart.entry.js +0 -324
  340. package/dist/esm/test-runner-map.entry.js +0 -1860
  341. package/dist/esm/test-runner-table.entry.js +0 -475
  342. package/dist/esm/test-runner-time.entry.js +0 -379
  343. package/dist/esm/test-runner-title.entry.js +0 -113
  344. package/dist/esm/withComponentStatus-elELReKt.js +0 -37
  345. package/dist/esm/withComponentStyle-NaxfakAG.js +0 -126
  346. package/dist/esm/withDataset-BT2VQCsG.js +0 -144
  347. package/dist/esm/withStyled-CpUTv74m.js +0 -539
  348. package/dist/esm/withTranslation-Do4GhleK.js +0 -75
  349. package/dist/types/components/bn-map/bn-map.d.ts +0 -122
  350. package/dist/types/components/bn-map/ibcs-map/ibcs-map.d.ts +0 -73
  351. package/dist/types/components/bn-map/ibcs-map/utils/model/GeoJsonLayer.d.ts +0 -8
  352. package/dist/types/components/bn-map/ibcs-map/utils/model/GpxLayer.d.ts +0 -11
  353. package/dist/types/components/bn-map/ibcs-map/utils/model/Marker.d.ts +0 -9
  354. package/dist/types/components/bn-map/ibcs-map/utils/model/index.d.ts +0 -2
  355. package/dist/types/test-runner/test-runner-card.d.ts +0 -3
  356. package/dist/types/test-runner/test-runner-chart-time.d.ts +0 -3
  357. package/dist/types/test-runner/test-runner-chart.d.ts +0 -3
  358. package/dist/types/test-runner/test-runner-map.d.ts +0 -3
  359. package/dist/types/test-runner/test-runner-table.d.ts +0 -3
  360. package/dist/types/test-runner/test-runner-time.d.ts +0 -3
  361. package/dist/types/test-runner/test-runner-title.d.ts +0 -3
@@ -1,4138 +0,0 @@
1
- import { r as registerInstance, h, H as Host, g as getElement } from './index-B27Ax6P_.js';
2
- import { S as Svg, g as getContrastTextColor, a as getStackFill, b as getStackStroke, c as getScenarioPrefix, I as IBCS_LAYER_ORDER, F as FontStyleAdapter, d as SVGStyleGroupAdapter, e as SVGStyleAdapter, f as SVGVariancesStyleGroupAdapter, P as PaddingAdapter } from './SVGVariancesStyleGroup-DlWgvpzs.js';
3
- import { C as CompareUtil, A as AdapterUtils, b as OrderAdapter, O as OrderDirection } from './Order-B4fpLe_f.js';
4
- import { C as CalculateSize, F as Formatter, V as VarianceScenario } from './formatter-DTMEZ6d8.js';
5
- import { S as SiPrefix, D as DataAnalyzer, b as DataFormatDigitsAdapter } from './DataFormatDigits-Dt6gpIiZ.js';
6
- import { b as StackMode, c as AxisLabelsMode, C as ChartMode, f as StackBy, A as AggregationLevel } from './constants-kMyLevYy.js';
7
- import { a as alasql } from './alasql.min-CWu4NkIt.js';
8
- import { D as DateTime } from './luxon-DbyXf6dF.js';
9
- import { D as DateDistance, b as DateStringFactory } from './DateStringFactory-_Qiv0IvF.js';
10
- import { I as IBCSRuleSet, S as StringAdapter } from './StringAdapter-BLvo1Krl.js';
11
- import './_commonjsHelpers-BFTU3MAI.js';
12
-
13
- // import { IAdapter } from "../../../../../utils/helper/IAdapter";
14
- // import { CompareUtil } from "../../../../../utils/helper/CompareUtil";
15
- /**
16
- * Proportional scale factors for time-series chart elements.
17
- *
18
- * All values are expressed in **font-size multiples** (em-like units), so the chart
19
- * scales uniformly when the base font size changes. The chart renderer multiplies
20
- * each factor by the computed font size to get pixel dimensions.
21
- */
22
- class ScaleFactorsTimeChart {
23
- constructor() {
24
- /** Horizontal gap between adjacent scenario bars within a data point. */
25
- this.scenarioOffset = 0.3;
26
- /** Vertical gap between the scenario label and the top of its column. */
27
- this.scenarioLabelToColumn = 0.3;
28
- /** Vertical gap between the value label and the top of its column. */
29
- this.labelToColumn = 0.3;
30
- /** Gap between axis labels and the axis line. */
31
- this.labelToAxis = 0.3;
32
- /** Width of the variance needle (pin chart element). */
33
- this.needleWidth = 0.3;
34
- /** Width of the arrowhead on variance needles. */
35
- this.needleHeadWidth = 0.6;
36
- /** Width of a single data column (bar). */
37
- this.columnWidth = 2.0;
38
- /** Stroke width of the variance chart axis line. */
39
- this.varianceAxisLineWidth = 0.3;
40
- /** Stroke width of the main value axis line. */
41
- this.axisLineWidth = 0.1;
42
- /** Stroke width of auxiliary/grid lines. */
43
- this.auxiliaryLineWidth = 0.1;
44
- /** Stroke width of scenario indicator lines (e.g. forecast hatching). */
45
- this.scenarioLineWidth = 0.2;
46
- /** Width of plan/previous-period marker symbols. */
47
- this.markerWidth = 0.7;
48
- /** Horizontal offset of markers from the column center. */
49
- this.markerOffset = 0.0;
50
- /** Total horizontal space allocated per data point (bar + padding). */
51
- this.categoryWidth = 3.0;
52
- /** Length of axis tick marks. */
53
- this.axisTickLength = 0.3;
54
- }
55
- }
56
- /** Converts untyped JSON into a validated {@link ScaleFactorsTimeChart}. */
57
- class ScaleFactorsTimeChartAdapter {
58
- adapt(data) {
59
- const scaleFactors = new ScaleFactorsTimeChart();
60
- if (CompareUtil.isNumber(data.scenarioOffset)) {
61
- scaleFactors.scenarioOffset = data.scenarioOffset;
62
- }
63
- if (CompareUtil.isNumber(data.scenarioLabelToColumn)) {
64
- scaleFactors.scenarioLabelToColumn = data.scenarioLabelToColumn;
65
- }
66
- if (CompareUtil.isNumber(data.labelToColumn)) {
67
- scaleFactors.labelToColumn = data.labelToColumn;
68
- }
69
- if (CompareUtil.isNumber(data.labelToAxis)) {
70
- scaleFactors.labelToAxis = data.labelToAxis;
71
- }
72
- if (CompareUtil.isNumber(data.needleWidth)) {
73
- scaleFactors.needleWidth = data.needleWidth;
74
- }
75
- if (CompareUtil.isNumber(data.needleHeadWidth)) {
76
- scaleFactors.needleHeadWidth = data.needleHeadWidth;
77
- }
78
- if (CompareUtil.isNumber(data.columnWidth)) {
79
- scaleFactors.columnWidth = data.columnWidth;
80
- }
81
- if (CompareUtil.isNumber(data.varianceAxisLineWidth)) {
82
- scaleFactors.varianceAxisLineWidth = data.varianceAxisLineWidth;
83
- }
84
- if (CompareUtil.isNumber(data.axisLineWidth)) {
85
- scaleFactors.axisLineWidth = data.axisLineWidth;
86
- }
87
- if (CompareUtil.isNumber(data.auxiliaryLineWidth)) {
88
- scaleFactors.auxiliaryLineWidth = data.auxiliaryLineWidth;
89
- }
90
- if (CompareUtil.isNumber(data.scenarioLineWidth)) {
91
- scaleFactors.scenarioLineWidth = data.scenarioLineWidth;
92
- }
93
- if (CompareUtil.isNumber(data.markerWidth)) {
94
- scaleFactors.markerWidth = data.markerWidth;
95
- }
96
- if (CompareUtil.isNumber(data.markerOffset)) {
97
- scaleFactors.markerOffset = data.markerOffset;
98
- }
99
- if (CompareUtil.isNumber(data.categoryWidth)) {
100
- scaleFactors.categoryWidth = data.categoryWidth;
101
- }
102
- if (CompareUtil.isNumber(data.axisTickLength)) {
103
- scaleFactors.axisTickLength = data.axisTickLength;
104
- }
105
- return scaleFactors;
106
- }
107
- default() {
108
- return new ScaleFactorsTimeChart();
109
- }
110
- }
111
-
112
- // import {FontStyle} from "../../../../utils/model/styles/FontStyle";
113
- /**
114
- * Spatial layout engine for the time chart.
115
- *
116
- * Converts logical data model coordinates (column index, data values) into pixel positions
117
- * for all chart elements. All spacings are derived from the font size multiplied by
118
- * ScaleFactorsTimeChart factors, making the layout scale consistently with typography.
119
- *
120
- * Key coordinate reference points:
121
- * - getColumnPositionY(): the Y coordinate of the horizontal axis baseline
122
- * - getColumnCenterPositionX(index): center X for the column at the given time index
123
- * - getAxisPositionY(isRelative): axis Y adjusted for relative variance offset
124
- *
125
- * The layout accounts for: padding, left-side label space, scenario label offsets,
126
- * data label height, and the min/max data values to position the axis correctly
127
- * so that bars grow upward (positive) or downward (negative) from the baseline.
128
- */
129
- class ElementPositions {
130
- constructor(padding, scaleFactors, fontstyle, smallestDataPoint, highestDataPoint, numberOfColumns, leftSideLabelLength) {
131
- this.categoryPosition = { x: 0, y: 0 };
132
- this.spacings = new ScaleFactorsTimeChart();
133
- this.categoriesBoxOffset = {
134
- width: 0,
135
- height: 0,
136
- };
137
- this.padding = padding;
138
- this.scaleFactors = scaleFactors;
139
- this.fontStlye = fontstyle;
140
- this.dataLabelHeight = this.caluculateDataLabelHeight();
141
- this.axisPosition = { x: 0, y: 0 };
142
- this.columnValue = {
143
- min: smallestDataPoint,
144
- max: highestDataPoint,
145
- };
146
- this.numberOfColumns = numberOfColumns;
147
- this.leftSideLabelLength = leftSideLabelLength;
148
- this.calculateSpacings();
149
- this.calculateCategoryPosition();
150
- this.calculateAxisPosition();
151
- }
152
- caluculateDataLabelHeight() {
153
- const testlable = "123456789";
154
- const height = CalculateSize(testlable, {
155
- font: this.fontStlye.font,
156
- fontSize: this.fontStlye.size + "px",
157
- }).height;
158
- return height * 1.1;
159
- }
160
- getColumnCenterPositionX(index) {
161
- return (this.categoryPosition.y +
162
- this.spacings.scenarioOffset +
163
- index * this.spacings.categoryWidth +
164
- this.leftSideLabelLength +
165
- this.spacings.columnWidth * 0.5);
166
- }
167
- getAxisPositionY(isRelative) {
168
- let value = this.columnValue.max.getScaledUnit();
169
- if (isRelative) {
170
- value = this.columnValue.max.getScaledPercentUnit() + this.getNeedleWidth();
171
- }
172
- return value + this.dataLabelHeight + this.spacings.labelToAxis + this.padding.top;
173
- }
174
- getAxisPositionX() {
175
- return this.padding.left + this.leftSideLabelLength;
176
- }
177
- getColumnPositionX(index, isPrimaryColumn) {
178
- if (isPrimaryColumn) {
179
- return this.getColumnCenterPositionX(index);
180
- }
181
- return this.getColumnCenterPositionX(index) - this.spacings.scenarioOffset;
182
- }
183
- getColumnPositionY() {
184
- return this.columnValue.max.getScaledUnit() + this.dataLabelHeight + this.spacings.labelToColumn + this.padding.top;
185
- }
186
- getNeedlePositionY() {
187
- return (this.columnValue.max.getScaledPercentUnit() +
188
- this.dataLabelHeight +
189
- this.spacings.labelToColumn +
190
- this.getNeedleWidth() +
191
- this.padding.top);
192
- }
193
- getMarkerPositionX(index, isPrimaryMarker) {
194
- if (isPrimaryMarker) {
195
- return this.getColumnCenterPositionX(index) - this.spacings.markerOffset - this.getColumnWidth() * 0.5;
196
- }
197
- return this.getColumnCenterPositionX(index) + this.spacings.markerOffset + this.getColumnWidth() * 0.5;
198
- }
199
- getMarkerPositionY() {
200
- return this.getColumnPositionY();
201
- }
202
- getAxisTitlePositionX(group) {
203
- const offsetToCenterText = group.width();
204
- return this.axisPosition.x - offsetToCenterText;
205
- }
206
- getAxisTitlePositionY(isPositive, isRelative) {
207
- let value = this.columnValue.max.getScaledUnit();
208
- if (isRelative) {
209
- value = this.columnValue.max.getScaledPercentUnit();
210
- }
211
- if (isPositive) {
212
- return value + this.dataLabelHeight + this.spacings.labelToAxis;
213
- }
214
- else {
215
- return value;
216
- }
217
- }
218
- getColumnDataLabelPositionY(scaledUnit) {
219
- const offset = this.spacings.labelToColumn;
220
- if (scaledUnit < 0) {
221
- return this.getColumnPositionY() + Math.abs(scaledUnit) + offset;
222
- }
223
- return this.getColumnPositionY() - scaledUnit - offset;
224
- }
225
- getNeedleDataLabelPositionY(scaledUnit) {
226
- const offset = this.spacings.labelToColumn;
227
- if (scaledUnit < 0) {
228
- return this.getNeedlePositionY() + Math.abs(scaledUnit) + offset + 2 * this.getNeedleWidth();
229
- }
230
- return this.getNeedlePositionY() - scaledUnit - offset - 2 * this.getNeedleWidth();
231
- }
232
- getAxisEndPositionX() {
233
- return this.getAxisPositionX() + (this.numberOfColumns + 1 / 2) * this.spacings.categoryWidth;
234
- }
235
- getColumnWidth() {
236
- return this.spacings.columnWidth;
237
- }
238
- getNeedleWidth() {
239
- return this.spacings.needleWidth;
240
- }
241
- getNeedleHeadWidth() {
242
- return this.spacings.needleHeadWidth;
243
- }
244
- getScenarioLabelPositionOffsetX(isPrimaryColumn) {
245
- if (isPrimaryColumn) {
246
- return this.getColumnWidth() * 0.5 + this.spacings.scenarioLabelToColumn;
247
- }
248
- return -(this.getColumnWidth() * 0.5 + this.spacings.scenarioLabelToColumn);
249
- }
250
- calculateSpacings() {
251
- this.spacings = {
252
- scenarioOffset: this.fontStlye.size * this.scaleFactors.scenarioOffset,
253
- scenarioLabelToColumn: this.fontStlye.size * this.scaleFactors.scenarioLabelToColumn,
254
- markerOffset: this.fontStlye.size * this.scaleFactors.markerOffset,
255
- labelToColumn: this.fontStlye.size * this.scaleFactors.labelToColumn,
256
- labelToAxis: this.fontStlye.size * this.scaleFactors.labelToAxis,
257
- needleWidth: this.fontStlye.size * this.scaleFactors.needleWidth,
258
- needleHeadWidth: this.fontStlye.size * this.scaleFactors.needleHeadWidth,
259
- columnWidth: this.fontStlye.size * this.scaleFactors.columnWidth,
260
- varianceAxisLineWidth: this.fontStlye.size * this.scaleFactors.varianceAxisLineWidth,
261
- axisLineWidth: this.fontStlye.size * this.scaleFactors.axisLineWidth,
262
- auxiliaryLineWidth: this.fontStlye.size * this.scaleFactors.auxiliaryLineWidth,
263
- scenarioLineWidth: this.fontStlye.size * this.scaleFactors.scenarioLineWidth,
264
- markerWidth: this.fontStlye.size * this.scaleFactors.markerWidth,
265
- categoryWidth: this.fontStlye.size * this.scaleFactors.categoryWidth,
266
- axisTickLength: this.fontStlye.size * this.scaleFactors.axisTickLength,
267
- };
268
- }
269
- calculateCategoryPosition() {
270
- this.categoryPosition = {
271
- x: this.padding.left + this.spacings.columnWidth * 0.5,
272
- y: this.padding.top,
273
- };
274
- }
275
- calculateAxisPosition() {
276
- this.axisPosition = {
277
- x: this.getAxisPositionX(),
278
- y: this.getAxisPositionY(false),
279
- };
280
- }
281
- getMarkerScenarioLabelPositionOffsetX(isPrimaryColumn) {
282
- if (isPrimaryColumn) {
283
- return this.spacings.labelToColumn - this.fontStlye.size;
284
- }
285
- return this.spacings.labelToColumn + this.spacings.markerWidth * 0.5;
286
- }
287
- }
288
-
289
- class Padding {
290
- constructor(padding) {
291
- this.top = padding.top;
292
- this.bottom = padding.bottom;
293
- this.left = padding.left;
294
- this.right = padding.right;
295
- }
296
- addBoxTopLeft(addition) {
297
- this.top += addition.height | this.top;
298
- this.left += addition.width | this.top;
299
- return this;
300
- }
301
- }
302
-
303
- // import { SVGPolgonPattern } from "../../../../utils/model";
304
- class MarkerPattern {
305
- constructor(fontSize) {
306
- const backgroundFactor = 1;
307
- const foregroundFactor = 0.7;
308
- const maxBg = fontSize * backgroundFactor;
309
- const maxFg = fontSize * foregroundFactor;
310
- this.bgOffset = (maxBg - maxFg) / 2;
311
- this.markerUp = { top: maxFg / 2 + ",0", left: "0," + maxFg, right: maxFg + "," + maxFg };
312
- this.markerUpBackground = { top: maxBg / 2 + ",0", left: "0," + maxBg, right: maxBg + "," + maxBg };
313
- this.markerDown = { bottom: maxFg / 2 + "," + maxFg, left: "0,0", right: maxFg + ",0" };
314
- this.markerDownBackground = { bottom: maxBg / 2 + "," + maxBg, left: "0,0", right: maxBg + ",0" };
315
- this.markerRight = { bottom: "0," + maxFg, top: "0,0", right: maxFg + "," + maxFg / 2 };
316
- this.markerRightBackground = { bottom: "0," + maxBg, top: "0,0", right: maxBg + "," + maxBg / 2 };
317
- this.markerLeft = { bottom: maxFg + "," + maxFg, top: maxFg + ",0", left: "0," + maxFg / 2 };
318
- this.markerLeftBackground = { bottom: maxBg + "," + maxBg, top: maxBg + ",0", Left: "0," + maxBg / 2 };
319
- }
320
- upMarkerPatternStrings() {
321
- return {
322
- background: this.markerUpBackground.left +
323
- " " +
324
- this.markerUpBackground.right +
325
- " " +
326
- this.markerUpBackground.top +
327
- " " +
328
- this.markerUpBackground.left,
329
- foreground: this.markerUp.left + " " + this.markerUp.right + " " + this.markerUp.top + " " + this.markerUp.left,
330
- bgOffset: this.bgOffset,
331
- };
332
- }
333
- downMarkerPatternStrings() {
334
- return {
335
- background: this.markerDownBackground.left +
336
- " " +
337
- this.markerDownBackground.right +
338
- " " +
339
- this.markerDownBackground.bottom +
340
- " " +
341
- this.markerDownBackground.left,
342
- foreground: this.markerDown.left + " " + this.markerDown.right + " " + this.markerDown.bottom + " " + this.markerDown.left,
343
- bgOffset: this.bgOffset,
344
- };
345
- }
346
- rightMarkerPatternStrings() {
347
- return {
348
- background: this.markerRightBackground.top +
349
- " " +
350
- this.markerRightBackground.right +
351
- " " +
352
- this.markerRightBackground.bottom +
353
- " " +
354
- this.markerRightBackground.top,
355
- foreground: this.markerRight.top +
356
- " " +
357
- this.markerRight.right +
358
- " " +
359
- this.markerRight.bottom +
360
- " " +
361
- this.markerRight.top,
362
- bgOffset: this.bgOffset,
363
- };
364
- }
365
- leftMarkerPatternStrings() {
366
- return {
367
- background: this.markerLeftBackground.top +
368
- " " +
369
- this.markerLeftBackground.Left +
370
- " " +
371
- this.markerLeftBackground.bottom +
372
- " " +
373
- this.markerLeftBackground.top,
374
- foreground: this.markerLeft.top + " " + this.markerLeft.left + " " + this.markerLeft.bottom + " " + this.markerLeft.top,
375
- bgOffset: this.bgOffset,
376
- };
377
- }
378
- createPatternMapForStructureBar() {
379
- const pattern = new Map();
380
- pattern.set("marker-up", this.upMarkerPatternStrings());
381
- pattern.set("marker-down", this.downMarkerPatternStrings());
382
- pattern.set("marker-right", this.rightMarkerPatternStrings());
383
- pattern.set("marker-left", this.leftMarkerPatternStrings());
384
- return pattern;
385
- }
386
- }
387
-
388
- /**
389
- * Generates SVG diagonal-line hatching patterns for forecast (FC) scenario bars.
390
- *
391
- * Creates a 10x10 SVG <pattern> tile with diagonal lines using the FC bar style colors.
392
- * The resulting pattern is used as the fill for FC columns/bars to visually distinguish
393
- * forecast data from actual data per IBCS conventions (hatched = forecast, solid = actual).
394
- *
395
- * bgOffset is computed from font size to center the foreground shape within the background.
396
- */
397
- class CustomPattern {
398
- constructor(styles) {
399
- this.container = new Svg();
400
- this.pattern = this.createFCPattern(this.container.group(), styles);
401
- this.styles = styles;
402
- const backgroundFactor = 1;
403
- const foregroundFactor = 0.7;
404
- let fontSize = 10;
405
- if (styles != null && styles.fontStyles != null && styles.fontStyles.size) {
406
- fontSize = styles.fontStyles.size;
407
- }
408
- const maxBg = fontSize * backgroundFactor;
409
- const maxFg = fontSize * foregroundFactor;
410
- this.bgOffset = (maxBg - maxFg) / 2;
411
- }
412
- createFCPattern(group, styles) {
413
- const _styles = styles;
414
- return group
415
- .pattern(10, 10, function (add) {
416
- add.rect(10, 10).fill(_styles.barStyles.fc.fill);
417
- add
418
- .line(0, 5, 5, 0)
419
- .stroke({ width: _styles.barStyles.fc.width, color: _styles.barStyles.fc.stroke, linecap: "square" });
420
- add
421
- .line(5, 10, 10, 5)
422
- .stroke({ width: _styles.barStyles.fc.width, color: _styles.barStyles.fc.stroke, linecap: "square" });
423
- })
424
- .id("pattern-time-fc");
425
- }
426
- getFCPolygonPattern() {
427
- return { background: "", foreground: "", bgOffset: 0, pattern: this.pattern };
428
- }
429
- toString() {
430
- return this.container.svg();
431
- }
432
- }
433
-
434
- // import { DataFormatDigits } from "../../../../utils/model/DataFormatDigits";
435
- // import { SiPrefix } from "../../../../utils/model/SiPrefix";
436
- /**
437
- * Anchor point for label positioning relative to its coordinates.
438
- * Vertical hooks control how the label is offset from its Y coordinate;
439
- * horizontal hooks control text-anchor alignment (start/middle/end).
440
- */
441
- var HookLocation;
442
- (function (HookLocation) {
443
- HookLocation[HookLocation["Left"] = 0] = "Left";
444
- HookLocation[HookLocation["Center"] = 1] = "Center";
445
- HookLocation[HookLocation["Right"] = 2] = "Right";
446
- HookLocation[HookLocation["Top"] = 3] = "Top";
447
- HookLocation[HookLocation["Bottom"] = 4] = "Bottom";
448
- })(HookLocation || (HookLocation = {}));
449
- /**
450
- * SVG text label used across all chart elements (columns, needles, markers, axes).
451
- *
452
- * Handles numeric formatting via Formatter.number() with configurable type (decimal/percent),
453
- * digit precision, and SI prefix scaling. Variance labels prepend a "+" sign for positive values.
454
- *
455
- * The label is drawn with a semi-transparent white background rectangle to ensure
456
- * readability over chart geometry. For stacked segments, the background is omitted
457
- * and text color is derived from the segment fill for contrast.
458
- *
459
- * Positioning uses a two-axis hook system: verticalHookLocation shifts the label
460
- * above/below/centered on the Y coordinate, horizontalHookLocation sets the SVG
461
- * text-anchor (start/middle/end) relative to X.
462
- */
463
- class Label {
464
- constructor(parent, xPosition, yPosition, groupPrefix, value, styles, verticalHookLocation, horizontalHookLocation) {
465
- this.ID_SCENARIOLABEL = "Label";
466
- this.CSS_CATEGORIES = "categories";
467
- this.isRelativeLabel = false;
468
- this.segmentFillColor = null;
469
- this.x = xPosition;
470
- this.y = yPosition;
471
- this.value = value;
472
- this.group = parent.group().id(this.createElementID(parent.toString(), groupPrefix));
473
- this.styles = styles;
474
- this.isVarianceLabel = false;
475
- this.verticalHookLocation = verticalHookLocation || HookLocation.Top;
476
- this.horizontalHookLocation = horizontalHookLocation || HookLocation.Left;
477
- }
478
- setToVarianceLabel() {
479
- this.isVarianceLabel = true;
480
- return this;
481
- }
482
- setToRelativeVarianceLabel() {
483
- this.isVarianceLabel = true;
484
- this.isRelativeLabel = true;
485
- return this;
486
- }
487
- setSegmentFill(color) {
488
- this.segmentFillColor = color;
489
- return this;
490
- }
491
- updateGroup(newGroup) {
492
- this.group = newGroup;
493
- return this;
494
- }
495
- draw(displayLabel = true, dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix()) {
496
- if (this.isEmpty()) {
497
- return this;
498
- }
499
- const label = this.group;
500
- let valueStr;
501
- let prefix = "";
502
- if (Number.isNaN(Number(this.value)) === false) {
503
- const value = this.value;
504
- let type = "percent";
505
- let digits = dataFormatDigits.percent;
506
- let digitsMin = dataFormatDigits.percent;
507
- let scale = 1;
508
- if (this.isRelativeLabel === false) {
509
- digits = dataFormatDigits.decimal;
510
- digitsMin = dataFormatDigits.decimal;
511
- scale = measureScale.value;
512
- type = "decimal";
513
- }
514
- valueStr = Formatter.number(Number(value), type, digits, digitsMin, scale);
515
- if (this.isVarianceLabel && Number(this.value) >= 0) {
516
- prefix = "+";
517
- }
518
- }
519
- else {
520
- valueStr = "" + this.value;
521
- // displayLabel = false;
522
- }
523
- const labelStr = prefix + valueStr;
524
- const text = this.drawLabel(label, labelStr);
525
- if (displayLabel === false) {
526
- text.addClass("hide");
527
- label.addClass("hide");
528
- }
529
- return this;
530
- }
531
- isEmpty() {
532
- return this.value == null || "" === this.value;
533
- }
534
- setPos(xPosition, yPosition) {
535
- this.x = xPosition;
536
- this.y = yPosition;
537
- return this;
538
- }
539
- forceStringTypeDraw() {
540
- const label = this.group;
541
- const labelStr = "" + this.value;
542
- this.drawLabel(label, labelStr);
543
- return this;
544
- }
545
- drawLabel(label, labelStr) {
546
- const background = this.styles.fontStyles.background || "#ffffff";
547
- //let text = label.text(labelStr)
548
- // .leading(1)
549
- // .addClass(this.CSS_CATEGORIES)
550
- // .font({anchor: 'middle'})
551
- // .move(this.x, this.y);
552
- let labelAnchor = "start";
553
- const text = label.text(labelStr);
554
- text.move(this.x, this.y);
555
- const boxWidth = text.bbox().w;
556
- const boxHeight = text.bbox().h;
557
- let rectX = 0;
558
- let rectY = 0;
559
- const textX = text.x();
560
- let textY = text.y();
561
- if (this.horizontalHookLocation === HookLocation.Left) {
562
- labelAnchor = "left";
563
- rectX = text.x();
564
- }
565
- else if (this.horizontalHookLocation === HookLocation.Center) {
566
- labelAnchor = "middle";
567
- rectX = text.x() - (boxWidth + 2) / 2;
568
- }
569
- else if (this.horizontalHookLocation === HookLocation.Right) {
570
- labelAnchor = "end";
571
- rectX = text.x() - boxWidth;
572
- }
573
- if (this.verticalHookLocation === HookLocation.Center) {
574
- textY = text.y() - (boxHeight * 1.2) / 2;
575
- rectY = textY + boxHeight * 0.2;
576
- }
577
- else if (this.verticalHookLocation === HookLocation.Top) {
578
- textY -= boxHeight / 4;
579
- rectY = textY + boxHeight * 0.2;
580
- }
581
- else if (this.verticalHookLocation === HookLocation.Bottom) {
582
- textY -= boxHeight;
583
- rectY = textY + boxHeight * 0.2; // + (boxHeight / 2);
584
- }
585
- text.move(textX, textY);
586
- text.font({ anchor: labelAnchor });
587
- if (this.segmentFillColor != null) {
588
- text.fill(getContrastTextColor(this.segmentFillColor));
589
- }
590
- else {
591
- label
592
- .rect(boxWidth + 2, boxHeight * 0.8)
593
- .stroke(background)
594
- .fill(background)
595
- .opacity(0.9)
596
- .move(rectX - 1, rectY)
597
- .insertBefore(text);
598
- }
599
- return text;
600
- }
601
- createElementID(prefix, groupPrefix) {
602
- return prefix + "_" + groupPrefix + "_" + this.ID_SCENARIOLABEL;
603
- }
604
- }
605
-
606
- /**
607
- * Scenario priority for label collision resolution.
608
- * Lower number = higher priority. AC always wins.
609
- */
610
- const SCENARIO_PRIORITY = {
611
- ac: 1,
612
- pp: 2,
613
- fc: 3,
614
- pl: 4,
615
- };
616
- /**
617
- * Direction a label can be placed relative to its marker.
618
- */
619
- var LabelDirection;
620
- (function (LabelDirection) {
621
- LabelDirection[LabelDirection["Above"] = 0] = "Above";
622
- LabelDirection[LabelDirection["Below"] = 1] = "Below";
623
- LabelDirection[LabelDirection["Left"] = 2] = "Left";
624
- LabelDirection[LabelDirection["Right"] = 3] = "Right";
625
- })(LabelDirection || (LabelDirection = {}));
626
- /**
627
- * Manages label collision detection across multiple line series in line charts.
628
- * Tracks the bounding boxes of all registered labels and detects overlaps.
629
- * Supports scenario-based priority: when labels collide and cannot be repositioned,
630
- * lower-priority scenario labels are hidden (AC > PP > FC > PL).
631
- *
632
- * Uses 4-direction placement: Above, Below, Left, Right.
633
- */
634
- class LabelCollisionManager {
635
- constructor() {
636
- this.labels = [];
637
- this.scenarioLabels = [];
638
- }
639
- /**
640
- * Clears all registered labels. Call this before drawing a new chart.
641
- */
642
- clear() {
643
- this.labels = [];
644
- this.scenarioLabels = [];
645
- }
646
- /**
647
- * Registers a label's bounding box for collision detection.
648
- */
649
- register(bounds) {
650
- this.labels.push(bounds);
651
- }
652
- /**
653
- * Checks if a label at the given bounds would collide with any existing labels.
654
- */
655
- hasCollision(bounds) {
656
- return this.labels.some((existing) => this.intersects(bounds, existing));
657
- }
658
- /**
659
- * Tries each direction in priorityOrder to find a non-colliding placement.
660
- * Returns the first non-colliding LabelPlacement, or null if all 4 collide
661
- * with higher-priority scenario labels (meaning this label should be hidden).
662
- *
663
- * @param centerX Center X position of the marker
664
- * @param markerY Y position of the marker center
665
- * @param width Estimated label width
666
- * @param height Estimated label height
667
- * @param pointIndex The data point index
668
- * @param markerSize The marker size
669
- * @param scenarioType e.g. "ac", "pp", "fc", "pl"
670
- * @param priorityOrder Directions to try, in priority order
671
- */
672
- getOptimalPlacement(centerX, markerY, width, height, pointIndex, markerSize, scenarioType, priorityOrder) {
673
- const priority = SCENARIO_PRIORITY[scenarioType] || 99;
674
- const gap = 8;
675
- const halfMarker = markerSize / 2;
676
- // Try each direction in the caller's preferred order
677
- for (const direction of priorityOrder) {
678
- const placement = this.calculatePlacementForDirection(centerX, markerY, width, height, pointIndex, halfMarker, gap, direction);
679
- if (!this.hasCollision(placement.bounds)) {
680
- return placement;
681
- }
682
- }
683
- // All 4 positions collide. Check if any collide ONLY with lower-priority
684
- // labels (meaning we could still place here — the other label would lose).
685
- // But to keep it simple: hide only if all positions collide with higher-priority labels.
686
- for (const direction of priorityOrder) {
687
- const placement = this.calculatePlacementForDirection(centerX, markerY, width, height, pointIndex, halfMarker, gap, direction);
688
- if (!this.collidesWithHigherPriority(placement.bounds, priority)) {
689
- // This position only collides with equal or lower priority — claim it
690
- return placement;
691
- }
692
- }
693
- // All positions collide with higher-priority labels — hide
694
- return null;
695
- }
696
- /**
697
- * Computes the LabelPlacement for a given direction.
698
- */
699
- calculatePlacementForDirection(centerX, markerY, width, height, pointIndex, halfMarker, gap, direction) {
700
- let labelX;
701
- let labelY;
702
- let verticalHook;
703
- let horizontalHook;
704
- let boundsX;
705
- let boundsY;
706
- switch (direction) {
707
- case LabelDirection.Above:
708
- labelX = centerX;
709
- labelY = markerY - halfMarker - gap;
710
- verticalHook = HookLocation.Bottom;
711
- horizontalHook = HookLocation.Center;
712
- boundsX = centerX - width / 2;
713
- boundsY = markerY - halfMarker - gap - height;
714
- break;
715
- case LabelDirection.Below:
716
- labelX = centerX;
717
- labelY = markerY + halfMarker + gap;
718
- verticalHook = HookLocation.Top;
719
- horizontalHook = HookLocation.Center;
720
- boundsX = centerX - width / 2;
721
- // Top hook shifts text up by height/4, so bounds start earlier
722
- boundsY = markerY + halfMarker + gap - height / 4;
723
- break;
724
- case LabelDirection.Left:
725
- labelX = centerX - halfMarker - gap;
726
- labelY = markerY;
727
- verticalHook = HookLocation.Center;
728
- horizontalHook = HookLocation.Right;
729
- boundsX = centerX - halfMarker - gap - width;
730
- // Center hook shifts text up by height*0.6
731
- boundsY = markerY - height * 0.6;
732
- break;
733
- case LabelDirection.Right:
734
- labelX = centerX + halfMarker + gap;
735
- labelY = markerY;
736
- verticalHook = HookLocation.Center;
737
- horizontalHook = HookLocation.Left;
738
- boundsX = centerX + halfMarker + gap;
739
- // Center hook shifts text up by height*0.6
740
- boundsY = markerY - height * 0.6;
741
- break;
742
- }
743
- const bounds = {
744
- x: boundsX,
745
- y: boundsY,
746
- width,
747
- height,
748
- pointIndex,
749
- preferredHook: verticalHook,
750
- };
751
- return { labelX, labelY, verticalHook, horizontalHook, bounds };
752
- }
753
- /**
754
- * Checks if bounds collide with any registered label that has higher priority.
755
- */
756
- collidesWithHigherPriority(bounds, priority) {
757
- return this.labels.some((existing) => {
758
- if (!existing.scenarioType)
759
- return false;
760
- const existingPriority = SCENARIO_PRIORITY[existing.scenarioType] || 99;
761
- return existingPriority < priority && this.intersects(bounds, existing);
762
- });
763
- }
764
- /**
765
- * Checks whether a scenario label at the end of a line should be hidden
766
- * because it's too close to a higher-priority scenario label.
767
- */
768
- shouldHideScenarioLabel(x, y, scenarioType, proximityThreshold = 20) {
769
- const priority = SCENARIO_PRIORITY[scenarioType] || 99;
770
- if (priority <= 1)
771
- return false; // AC is never hidden
772
- return this.scenarioLabels.some((existing) => {
773
- const existingPriority = SCENARIO_PRIORITY[existing.scenarioType] || 99;
774
- if (existingPriority >= priority)
775
- return false;
776
- const dy = Math.abs(y - existing.y);
777
- const dx = Math.abs(x - existing.x);
778
- return dy < proximityThreshold && dx < proximityThreshold;
779
- });
780
- }
781
- /**
782
- * Registers a scenario label position for proximity checking.
783
- */
784
- registerScenarioLabel(x, y, scenarioType) {
785
- this.scenarioLabels.push({ x, y, scenarioType });
786
- }
787
- /**
788
- * Checks if two bounding boxes intersect (overlap).
789
- */
790
- intersects(a, b) {
791
- return !(a.x + a.width < b.x || // a is completely to the left of b
792
- b.x + b.width < a.x || // b is completely to the left of a
793
- a.y + a.height < b.y || // a is completely above b
794
- b.y + b.height < a.y // b is completely above a
795
- );
796
- }
797
- /**
798
- * Gets the number of registered labels.
799
- */
800
- getLabelCount() {
801
- return this.labels.length;
802
- }
803
- }
804
-
805
- /**
806
- * A single renderable data point in a time-series chart.
807
- *
808
- * Encapsulates a numeric value, its IBCS scenario type, and the vertical scale factor.
809
- * Provides scaling and variance styling logic used by the chart renderer.
810
- *
811
- * Variance direction follows IBCS convention: the declared variance ("pos"/"neg") applies
812
- * to non-negative values; for negative values, the style is flipped (pos becomes neg and
813
- * vice versa) so that visual encoding always reflects the economic meaning.
814
- */
815
- class DataPoint {
816
- constructor(value, scenario, pixelPerUnit, variance) {
817
- this.value = value;
818
- this.scenario = scenario;
819
- this.pixelPerUnit = pixelPerUnit || 1;
820
- if (variance === "neg" || variance === Scenario.NEG) {
821
- this.variance = Scenario.NEG;
822
- }
823
- else if (variance === "pos" || variance === Scenario.POS) {
824
- this.variance = Scenario.POS;
825
- }
826
- else {
827
- this.variance = Scenario.NEU;
828
- }
829
- }
830
- isEmpty() {
831
- return undefined === this.value || null == this.scenario;
832
- }
833
- /** Returns the value scaled to pixel height for absolute (non-percentage) bars. */
834
- getScaledUnit() {
835
- if (this.value == null) {
836
- return 0;
837
- }
838
- return this.value * this.pixelPerUnit;
839
- }
840
- /**
841
- * Returns the percentage value scaled to pixel height, clipped at +/-145%.
842
- *
843
- * Values beyond +/-1.45 (145%) are clamped to prevent extreme bars from
844
- * distorting the chart layout. Use {@link isClipped} to check if clipping occurred.
845
- */
846
- getScaledPercentUnit() {
847
- if (this.value == null) {
848
- return 0;
849
- }
850
- if (this.value > 1.45) {
851
- return 1.45 * this.pixelPerUnit;
852
- }
853
- if (this.value < -1.45) {
854
- return -1.45 * this.pixelPerUnit;
855
- }
856
- return this.value * this.pixelPerUnit;
857
- }
858
- /**
859
- * Returns the IBCS variance color style, flipping pos/neg for negative values.
860
- *
861
- * IBCS rule: a "positive variance" on a negative value is economically unfavorable,
862
- * so the visual style must invert. NEU (neutral) is never flipped.
863
- */
864
- getVarianceStyle() {
865
- if (this.value == null) {
866
- return this.variance;
867
- }
868
- if (this.value >= 0) {
869
- return this.variance;
870
- }
871
- //flip the style
872
- if (Scenario.NEU === this.variance) {
873
- return Scenario.NEU;
874
- }
875
- if (Scenario.POS === this.variance) {
876
- return Scenario.NEG;
877
- }
878
- return Scenario.POS;
879
- }
880
- /** Returns true if the percentage value exceeds the +/-145% clipping threshold. */
881
- isClipped() {
882
- if (this.value == null) {
883
- return false;
884
- }
885
- return Math.abs(this.value) > 1.45;
886
- }
887
- /** Returns the fixed display value (145) shown on clipped percentage bars. */
888
- getClippedValue() {
889
- return 145;
890
- }
891
- /** Extracts the 2-character scenario type prefix (e.g. "ac" from "ac1", "pl" from "pl2"). */
892
- getScenario() {
893
- var _a;
894
- return (_a = this.scenario) === null || _a === void 0 ? void 0 : _a.slice(0, 2);
895
- }
896
- }
897
-
898
- // import { IAdapter } from "../../../../utils/helper/IAdapter";
899
- // import { CompareUtil } from "../../../../utils/helper/CompareUtil";
900
- /**
901
- * IBCS-compliant data row for time-series chart visualizations.
902
- *
903
- * Extends the standard table data row schema with a Luxon {@link DateTime} field for temporal
904
- * positioning on the x-axis. Shares the same three-level row hierarchy, two-level column hierarchy,
905
- * and 16 scenario value slots as {@link TableDataRow}.
906
- */
907
- class TimeChartDataRow {
908
- constructor() {
909
- this.operation = "+";
910
- }
911
- addRowGroup(name, index) {
912
- this.rowGroup = name;
913
- this.rowGroupIndex = index;
914
- }
915
- addCategory(name, index) {
916
- this.category = name;
917
- this.categoryIndex = index;
918
- }
919
- addSubCategory(name, index) {
920
- this.subCategory = name;
921
- this.subCategoryIndex = index;
922
- }
923
- addColumnGroup(name, index) {
924
- this.columnGroup = name;
925
- this.columnGroupIndex = index;
926
- }
927
- addSubColumnGroup(name, index) {
928
- this.columnSubGroup = name;
929
- this.columnSubGroupIndex = index;
930
- }
931
- }
932
- /**
933
- * Converts untyped JSON records into validated {@link TimeChartDataRow} instances.
934
- *
935
- * Parses the `date` field from an ISO 8601 string into a Luxon DateTime.
936
- * Invalid dates are silently dropped (field remains undefined).
937
- */
938
- class TimeChartDataRowAdapter {
939
- constructor() { }
940
- adapt(data) {
941
- const dataRow = new TimeChartDataRow();
942
- if (CompareUtil.isString(data.date)) {
943
- dataRow.date = this.parseDateString(data.date);
944
- }
945
- //if (CompareUtil.isExisting(data.date)) {
946
- // else if (CompareUtil.isDate(data.date)) {
947
- // dataRow.date = data.date;
948
- // }
949
- //}
950
- if (CompareUtil.isOperator(data.operation)) {
951
- dataRow.operation = data.operation;
952
- }
953
- if (CompareUtil.isNumber(data.rowGroupIndex) && CompareUtil.isString(data.rowGroup)) {
954
- dataRow.addRowGroup(data.rowGroup, data.rowGroupIndex);
955
- }
956
- if (CompareUtil.isNumber(data.categoryIndex) && CompareUtil.isString(data.category)) {
957
- dataRow.addCategory(data.category, data.categoryIndex);
958
- }
959
- if (CompareUtil.isNumber(data.subCategoryIndex) && CompareUtil.isString(data.subCategory)) {
960
- dataRow.addSubCategory(data.subCategory, data.subCategoryIndex);
961
- }
962
- if (CompareUtil.isNumber(data.columnGroupIndex) && CompareUtil.isString(data.columnGroup)) {
963
- dataRow.addColumnGroup(data.columnGroup, data.columnGroupIndex);
964
- }
965
- if (CompareUtil.isNumber(data.columnSubGroupIndex) && CompareUtil.isString(data.columnSubGroup)) {
966
- dataRow.addSubColumnGroup(data.columnSubGroup, data.columnSubGroupIndex);
967
- }
968
- this.setActualValues(data, dataRow);
969
- this.setPlanValues(data, dataRow);
970
- this.setPreviousPeriodValues(data, dataRow);
971
- this.setForecastValues(data, dataRow);
972
- return dataRow;
973
- }
974
- parseDateString(date) {
975
- const timestamp = DateTime.fromISO(date);
976
- if (timestamp.isValid) {
977
- return timestamp;
978
- }
979
- console.warn(`TimeChartDataRow: invalid date value '${date}' — skipping row`);
980
- return undefined;
981
- }
982
- default() {
983
- return new TimeChartDataRow();
984
- }
985
- setActualValues(data, dataRow) {
986
- if (CompareUtil.isNumber(data.ac1)) {
987
- dataRow.ac1 = data.ac1;
988
- }
989
- if (CompareUtil.isNumber(data.ac2)) {
990
- dataRow.ac2 = data.ac2;
991
- }
992
- if (CompareUtil.isNumber(data.ac3)) {
993
- dataRow.ac3 = data.ac3;
994
- }
995
- if (CompareUtil.isNumber(data.ac4)) {
996
- dataRow.ac4 = data.ac4;
997
- }
998
- }
999
- setPlanValues(data, dataRow) {
1000
- if (CompareUtil.isNumber(data.pl1)) {
1001
- dataRow.pl1 = data.pl1;
1002
- }
1003
- if (CompareUtil.isNumber(data.pl2)) {
1004
- dataRow.pl2 = data.pl2;
1005
- }
1006
- if (CompareUtil.isNumber(data.pl3)) {
1007
- dataRow.pl3 = data.pl3;
1008
- }
1009
- if (CompareUtil.isNumber(data.pl4)) {
1010
- dataRow.pl4 = data.pl4;
1011
- }
1012
- }
1013
- setPreviousPeriodValues(data, dataRow) {
1014
- if (CompareUtil.isNumber(data.pp1)) {
1015
- dataRow.pp1 = data.pp1;
1016
- }
1017
- if (CompareUtil.isNumber(data.pp2)) {
1018
- dataRow.pp2 = data.pp2;
1019
- }
1020
- if (CompareUtil.isNumber(data.pp3)) {
1021
- dataRow.pp3 = data.pp3;
1022
- }
1023
- if (CompareUtil.isNumber(data.pp4)) {
1024
- dataRow.pp4 = data.pp4;
1025
- }
1026
- }
1027
- setForecastValues(data, dataRow) {
1028
- if (CompareUtil.isNumber(data.fc1)) {
1029
- dataRow.fc1 = data.fc1;
1030
- }
1031
- if (CompareUtil.isNumber(data.fc2)) {
1032
- dataRow.fc2 = data.fc2;
1033
- }
1034
- if (CompareUtil.isNumber(data.fc3)) {
1035
- dataRow.fc3 = data.fc3;
1036
- }
1037
- if (CompareUtil.isNumber(data.fc4)) {
1038
- dataRow.fc4 = data.fc4;
1039
- }
1040
- }
1041
- }
1042
-
1043
- // import { IAdapter } from "../../../../../utils/helper/IAdapter";
1044
- // import { SVGPolgonPattern } from "../../../../../utils/model";
1045
- /** Aggregates all style configuration for a time chart: scale factors, fonts, colors, patterns, and padding. */
1046
- class TimeChartStyle {
1047
- constructor(scaleFactors, fontStyles, axisStyles, barStyles, varianceStyles, padding) {
1048
- this.scaleFactors = scaleFactors;
1049
- this.fontStyles = fontStyles;
1050
- this.axisStyles = axisStyles;
1051
- this.barStyles = barStyles;
1052
- this.varianceStyles = varianceStyles;
1053
- this.padding = padding;
1054
- this.pattern = new Map();
1055
- }
1056
- }
1057
- /** Adapts raw componentStyle JSON into a TimeChartStyle, falling back to defaults for missing properties. */
1058
- class TimeChartStylesAdapter {
1059
- constructor(scaleFactorsStructureChartAdapter, fontStyleAdapter, svgStyleGroupAdapter, svgVariancesStyleGroupAdapter, paddingadapter) {
1060
- this.scaleFactorsStructureChartAdapter = scaleFactorsStructureChartAdapter;
1061
- this.fontStyleAdapter = fontStyleAdapter;
1062
- this.svgStyleGroupAdapter = svgStyleGroupAdapter;
1063
- this.svgVariancesStyleGroupAdapter = svgVariancesStyleGroupAdapter;
1064
- this.paddingadapter = paddingadapter;
1065
- }
1066
- adapt(data) {
1067
- const styles = new TimeChartStyle(this.scaleFactorsStructureChartAdapter.default(), this.fontStyleAdapter.default(), this.svgStyleGroupAdapter.default(), this.svgStyleGroupAdapter.default(), this.svgVariancesStyleGroupAdapter.default(), this.paddingadapter.default());
1068
- if (CompareUtil.isExisting(data)) {
1069
- if (CompareUtil.isExisting(data.scaleFactors)) {
1070
- styles.scaleFactors = this.scaleFactorsStructureChartAdapter.adapt(data.scaleFactors);
1071
- }
1072
- if (CompareUtil.isExisting(data.fontStyles)) {
1073
- styles.fontStyles = this.fontStyleAdapter.adapt(data.fontStyles);
1074
- }
1075
- if (CompareUtil.isExisting(data.axisStyles)) {
1076
- styles.axisStyles = this.svgStyleGroupAdapter.adapt(data.axisStyles);
1077
- }
1078
- if (CompareUtil.isExisting(data.barStyles)) {
1079
- styles.barStyles = this.svgStyleGroupAdapter.adapt(data.barStyles);
1080
- }
1081
- if (CompareUtil.isExisting(data.varianceStyles)) {
1082
- styles.varianceStyles = this.svgVariancesStyleGroupAdapter.adapt(data.varianceStyles);
1083
- }
1084
- if (CompareUtil.isExisting(data.padding)) {
1085
- styles.padding = this.paddingadapter.adapt(data.padding);
1086
- }
1087
- styles.pattern = new MarkerPattern(styles.fontStyles.size).createPatternMapForStructureBar();
1088
- }
1089
- return styles;
1090
- }
1091
- default() {
1092
- return new TimeChartStyle(this.scaleFactorsStructureChartAdapter.default(), this.fontStyleAdapter.default(), this.svgStyleGroupAdapter.default(), this.svgStyleGroupAdapter.default(), this.svgVariancesStyleGroupAdapter.default(), this.paddingadapter.default());
1093
- }
1094
- }
1095
-
1096
- /**
1097
- * IBCS scenario enumeration for time-series charts.
1098
- *
1099
- * Includes all 16 scenario slots (4 each of ac, pp, fc, pl) plus three
1100
- * variance direction markers: POS (positive/favorable), NEG (negative/unfavorable),
1101
- * NEU (neutral).
1102
- */
1103
- var Scenario;
1104
- (function (Scenario) {
1105
- Scenario["AC1"] = "ac1";
1106
- Scenario["PP1"] = "pp1";
1107
- Scenario["FC1"] = "fc1";
1108
- Scenario["PL1"] = "pl1";
1109
- Scenario["AC2"] = "ac2";
1110
- Scenario["PP2"] = "pp2";
1111
- Scenario["FC2"] = "fc2";
1112
- Scenario["PL2"] = "pl2";
1113
- Scenario["AC3"] = "ac3";
1114
- Scenario["PP3"] = "pp3";
1115
- Scenario["FC3"] = "fc3";
1116
- Scenario["PL3"] = "pl3";
1117
- Scenario["AC4"] = "ac4";
1118
- Scenario["PP4"] = "pp4";
1119
- Scenario["FC4"] = "fc4";
1120
- Scenario["PL4"] = "pl4";
1121
- /** Positive/favorable variance (rendered in green per IBCS). */
1122
- Scenario["POS"] = "pos";
1123
- /** Negative/unfavorable variance (rendered in red per IBCS). */
1124
- Scenario["NEG"] = "neg";
1125
- /** Neutral variance (rendered in grey per IBCS). */
1126
- Scenario["NEU"] = "neu";
1127
- })(Scenario || (Scenario = {}));
1128
- /** Chart-internal table aggregation modes. */
1129
- var TableType;
1130
- (function (TableType) {
1131
- TableType["LIST"] = "LIST";
1132
- TableType["SUM"] = "SUM";
1133
- TableType["OPT"] = "OPT";
1134
- })(TableType || (TableType = {}));
1135
-
1136
- /**
1137
- * Renders the horizontal baseline axis for a time chart.
1138
- *
1139
- * The axis line spans from the left padding to the end of the data area.
1140
- * A CSS class based on the scenario type (e.g. "axis-ac", "axis-pp") is applied
1141
- * to control stroke style (solid for AC, dashed for FC, etc. per IBCS rules).
1142
- * An optional title label (e.g. "AC" or variance expression) is drawn above the axis.
1143
- */
1144
- class Axis {
1145
- constructor(axis, position, svgParentGroup) {
1146
- this.ID_AXIS = "axis";
1147
- this.CSS_AXIS_TITLE = "categories";
1148
- this.scenarioType = axis.scenarioType;
1149
- this.labelText = axis.labelText || null;
1150
- this.isRelative = axis.isRelative || false;
1151
- this.position = position;
1152
- this.svgGroup = svgParentGroup.group().id(this.ID_AXIS);
1153
- }
1154
- drawAxisTitle(group, text) {
1155
- if (null == text) {
1156
- text = "";
1157
- }
1158
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1159
- const title = group.text(text).addClass(this.CSS_AXIS_TITLE).attr("text-anchor", "middle");
1160
- title.move(this.position.getAxisTitlePositionX(group), this.position.getAxisTitlePositionY(true, this.isRelative));
1161
- }
1162
- draw() {
1163
- if (this.labelText) {
1164
- this.drawAxisTitle(this.svgGroup, this.labelText);
1165
- }
1166
- this.svgGroup
1167
- .line(this.position.getAxisPositionX(), this.position.getAxisPositionY(this.isRelative), this.position.getAxisEndPositionX(), this.position.getAxisPositionY(this.isRelative))
1168
- .addClass(this.ID_AXIS + "-" + this.convertScenarioType());
1169
- return this;
1170
- }
1171
- convertScenarioType() {
1172
- if (this.scenarioType === undefined || this.scenarioType == null) {
1173
- return "default";
1174
- }
1175
- return `${this.scenarioType}`.slice(0, 2);
1176
- }
1177
- }
1178
-
1179
- // import { DataFormatDigits } from "../../../../utils/model/DataFormatDigits";
1180
- // import { SiPrefix } from "../../../../utils/model/SiPrefix";
1181
- /**
1182
- * Renders a vertical bar (column) in an IBCS time chart.
1183
- *
1184
- * Coordinate system: SVG Y-axis is inverted -- positive values grow upward from the
1185
- * axis baseline, so yPos decreases as value increases. Negative values extend downward.
1186
- *
1187
- * Overflow handling: When a bar exceeds the available chart height (determined by
1188
- * OverflowConfig), the bar is split into a base segment and an overdrive segment
1189
- * separated by a zigzag break indicator. The overdrive zone maps the overflow amount
1190
- * proportionally into a fixed pixel region so all overflowing bars remain comparable.
1191
- *
1192
- * Primary columns (AC foreground) carry data labels and scenario labels;
1193
- * secondary columns (PP background) render without labels by default.
1194
- */
1195
- class Column {
1196
- constructor(position, styles, dataPoint, index, isPrimaryColumn, scenarioGroup, columnLabel, overflowConfig = null) {
1197
- this.ID_DATA_PREFIX = "DATA";
1198
- this.ID_SCENARIO_PREFIX = "SCENARIO";
1199
- this.ID_RECT = "RECT";
1200
- this.FALLBACK_COLOUR = "#000000";
1201
- this.label = null;
1202
- this.scenarioLabel = null;
1203
- this.isVarianceColumn = false;
1204
- this.overflowConfig = null;
1205
- this.isOverflowing = false;
1206
- this.overdriveHeight = 0;
1207
- this.dimensions = {
1208
- columnLength: 0,
1209
- xPos: 0,
1210
- yPos: 0,
1211
- labelYPos: 0,
1212
- scenarioLabelXPos: 0,
1213
- scenarioLabelYPos: 0,
1214
- clipped: false,
1215
- };
1216
- this.hasData = false;
1217
- this.dataPoint = dataPoint;
1218
- this.index = index;
1219
- this.isPrimaryColumn = isPrimaryColumn;
1220
- this.position = position;
1221
- this.columnBarStyles = styles.barStyles;
1222
- this.overflowConfig = overflowConfig;
1223
- this.scenarioGroup = scenarioGroup;
1224
- this.styles = styles;
1225
- this.columnGroup = scenarioGroup.group().id(scenarioGroup.toString() + "_" + this.ID_RECT);
1226
- if ((dataPoint === null || dataPoint === void 0 ? void 0 : dataPoint.isEmpty()) !== true) {
1227
- this.hasData = true;
1228
- this.dimensions = this.createDimensions(dataPoint, index, isPrimaryColumn);
1229
- this.label = this.getDataLabel(dataPoint);
1230
- this.scenarioLabel = this.getScenarioLabel(columnLabel);
1231
- }
1232
- }
1233
- setAsVariance() {
1234
- var _a;
1235
- this.isVarianceColumn = true;
1236
- (_a = this.label) === null || _a === void 0 ? void 0 : _a.setToVarianceLabel();
1237
- return this;
1238
- }
1239
- updateLabelGroup(newGroup) {
1240
- var _a;
1241
- if (this.isEmpty()) {
1242
- return this;
1243
- }
1244
- (_a = this.label) === null || _a === void 0 ? void 0 : _a.updateGroup(newGroup);
1245
- return this;
1246
- }
1247
- draw(dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix()) {
1248
- // TODE: JHE: Remove DataFOrmatDigits Type Duplicates
1249
- if (this.isEmpty()) {
1250
- return this;
1251
- }
1252
- const scenarioStyle = this.getScenarioStyle();
1253
- const strokeStyle = this.convertToSVGStyle(scenarioStyle, "stroke");
1254
- const fillStyle = this.getFillStyle(scenarioStyle);
1255
- if (this.columnGroup != null) {
1256
- if (this.isOverflowing && this.overflowConfig) {
1257
- this.drawOverdriveBar(fillStyle, strokeStyle);
1258
- }
1259
- else {
1260
- this.columnGroup
1261
- .rect(this.position.getColumnWidth(), this.dimensions.columnLength)
1262
- .fill(fillStyle)
1263
- .stroke(strokeStyle)
1264
- .y(this.dimensions.yPos)
1265
- .cx(this.dimensions.xPos);
1266
- }
1267
- }
1268
- this.drawColumnDataLabel(dataFormatDigits, measureScale);
1269
- this.drawScenarioLabel();
1270
- }
1271
- /**
1272
- * Draws a broken bar: base segment + break gap + overdrive segment.
1273
- * The break gap is filled with a white background and zigzag lines.
1274
- */
1275
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1276
- drawOverdriveBar(fillStyle, strokeStyle) {
1277
- if (!this.columnGroup || !this.overflowConfig)
1278
- return;
1279
- const axisY = this.position.getColumnPositionY();
1280
- const colWidth = this.position.getColumnWidth();
1281
- const effectiveCut = this.dimensions.columnLength; // scenario-aware cut height
1282
- const { breakGap } = this.overflowConfig;
1283
- // Base bar: from axis up to effective cut height
1284
- const baseY = axisY - effectiveCut;
1285
- this.columnGroup.rect(colWidth, effectiveCut).fill(fillStyle).stroke(strokeStyle).y(baseY).cx(this.dimensions.xPos);
1286
- // Overdrive bar: above the break gap
1287
- const overdriveY = baseY - breakGap - this.overdriveHeight;
1288
- this.columnGroup
1289
- .rect(colWidth, this.overdriveHeight)
1290
- .fill(fillStyle)
1291
- .stroke(strokeStyle)
1292
- .y(overdriveY)
1293
- .cx(this.dimensions.xPos);
1294
- // Break indicator: zigzag lines across bar width
1295
- this.drawBreakIndicator(baseY, breakGap);
1296
- }
1297
- /** Draws top and bottom zigzag lines across the column width to indicate a broken axis. */
1298
- drawBreakIndicator(baseY, breakGap) {
1299
- if (!this.columnGroup)
1300
- return;
1301
- const colWidth = this.position.getColumnWidth();
1302
- const xLeft = this.dimensions.xPos - colWidth / 2;
1303
- const midY = baseY - breakGap / 2;
1304
- const halfGap = breakGap * 0.35;
1305
- const zigCount = 3;
1306
- const segWidth = colWidth / zigCount;
1307
- // Top zigzag line
1308
- let topPath = `M ${xLeft} ${midY - halfGap}`;
1309
- for (let i = 0; i < zigCount; i++) {
1310
- const x1 = xLeft + segWidth * (i + 0.5);
1311
- const x2 = xLeft + segWidth * (i + 1);
1312
- const yPeak = midY - halfGap - breakGap * 0.3;
1313
- topPath += ` L ${x1} ${yPeak} L ${x2} ${midY - halfGap}`;
1314
- }
1315
- // Bottom zigzag line
1316
- let bottomPath = `M ${xLeft} ${midY + halfGap}`;
1317
- for (let i = 0; i < zigCount; i++) {
1318
- const x1 = xLeft + segWidth * (i + 0.5);
1319
- const x2 = xLeft + segWidth * (i + 1);
1320
- const yPeak = midY + halfGap + breakGap * 0.3;
1321
- bottomPath += ` L ${x1} ${yPeak} L ${x2} ${midY + halfGap}`;
1322
- }
1323
- // White background to cover the bar behind the break
1324
- this.columnGroup
1325
- .rect(colWidth + 2, breakGap)
1326
- .fill("#ffffff")
1327
- .stroke("none")
1328
- .y(baseY - breakGap)
1329
- .cx(this.dimensions.xPos);
1330
- this.columnGroup.path(topPath).fill("none").stroke({ color: "#000000", width: 1 });
1331
- this.columnGroup.path(bottomPath).fill("none").stroke({ color: "#000000", width: 1 });
1332
- }
1333
- /**
1334
- * Computes the pixel geometry for the column: position, height, label anchors.
1335
- * Handles three cases: overflow (broken bar), negative value, and normal positive.
1336
- * For overflow, the column is capped at effectiveCut height and an overdrive zone is added.
1337
- */
1338
- createDimensions(dataPoint, index, isPrimaryBar) {
1339
- const scaledUnit = dataPoint.getScaledUnit();
1340
- // Determine effective cut height: AC scenarios use full cutHeight, others break lower
1341
- if (this.overflowConfig && scaledUnit > 0) {
1342
- const isAC = dataPoint.getScenario() === "ac";
1343
- const effectiveCut = isAC
1344
- ? this.overflowConfig.cutHeight
1345
- : this.overflowConfig.cutHeight - this.overflowConfig.scenarioCutOffset;
1346
- if (scaledUnit > effectiveCut) {
1347
- this.isOverflowing = true;
1348
- const { breakGap, overdriveZoneHeight, maxOverflow } = this.overflowConfig;
1349
- const overflowAmount = scaledUnit - effectiveCut;
1350
- this.overdriveHeight = maxOverflow > 0 ? (overflowAmount / maxOverflow) * overdriveZoneHeight : 0;
1351
- const totalVisualHeight = effectiveCut + breakGap + this.overdriveHeight;
1352
- const axisY = this.position.getColumnPositionY();
1353
- return {
1354
- clipped: false,
1355
- columnLength: effectiveCut,
1356
- xPos: this.position.getColumnPositionX(index, isPrimaryBar),
1357
- yPos: axisY - effectiveCut,
1358
- labelYPos: axisY - totalVisualHeight - this.position.spacings.labelToColumn,
1359
- scenarioLabelXPos: this.position.getColumnPositionX(index, isPrimaryBar) +
1360
- this.position.getScenarioLabelPositionOffsetX(isPrimaryBar),
1361
- scenarioLabelYPos: axisY - effectiveCut * 0.5,
1362
- };
1363
- }
1364
- }
1365
- if (scaledUnit < 0) {
1366
- return {
1367
- clipped: false,
1368
- columnLength: Math.abs(scaledUnit),
1369
- xPos: this.position.getColumnPositionX(index, isPrimaryBar),
1370
- yPos: this.position.getColumnPositionY(),
1371
- labelYPos: this.position.getColumnDataLabelPositionY(scaledUnit),
1372
- scenarioLabelXPos: this.position.getColumnPositionX(index, isPrimaryBar) +
1373
- this.position.getScenarioLabelPositionOffsetX(isPrimaryBar),
1374
- scenarioLabelYPos: this.position.getColumnPositionY() + Math.abs(scaledUnit) * 0.5,
1375
- };
1376
- }
1377
- else {
1378
- return {
1379
- clipped: false,
1380
- columnLength: scaledUnit,
1381
- xPos: this.position.getColumnPositionX(index, isPrimaryBar),
1382
- yPos: this.position.getColumnPositionY() - scaledUnit,
1383
- labelYPos: this.position.getColumnDataLabelPositionY(scaledUnit),
1384
- scenarioLabelXPos: this.position.getColumnPositionX(index, isPrimaryBar) +
1385
- this.position.getScenarioLabelPositionOffsetX(isPrimaryBar),
1386
- scenarioLabelYPos: this.position.getColumnPositionY() - Math.abs(scaledUnit) * 0.5,
1387
- };
1388
- }
1389
- }
1390
- getDataLabel(dataPoint) {
1391
- let labelHook = HookLocation.Bottom;
1392
- if (dataPoint.value != null && dataPoint.value < 0) {
1393
- labelHook = HookLocation.Top;
1394
- }
1395
- const labelY = this.isOverflowing
1396
- ? this.dimensions.labelYPos
1397
- : this.position.getColumnDataLabelPositionY(this.dataPoint.getScaledUnit());
1398
- return new Label(this.scenarioGroup, this.position.getColumnCenterPositionX(this.index), labelY, this.ID_DATA_PREFIX, dataPoint.value, this.styles, labelHook, HookLocation.Center);
1399
- }
1400
- getScenarioLabel(columnLabel) {
1401
- if (this.isPrimaryColumn) {
1402
- return new Label(this.scenarioGroup, -1, -1, this.ID_SCENARIO_PREFIX, columnLabel, this.styles, HookLocation.Center, HookLocation.Left);
1403
- }
1404
- return new Label(this.scenarioGroup, -1, -1, this.ID_SCENARIO_PREFIX, columnLabel, this.styles, HookLocation.Center, HookLocation.Right);
1405
- }
1406
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1407
- convertToSVGStyle(style, mode) {
1408
- if (style == null) {
1409
- style = [];
1410
- }
1411
- style["color"] = style[mode] || this.FALLBACK_COLOUR;
1412
- return Object.assign({}, style);
1413
- }
1414
- drawScenarioLabel() {
1415
- if (this.scenarioLabel != null && !this.scenarioLabel.isEmpty() && !this.isVarianceColumn) {
1416
- this.scenarioLabel.setPos(this.dimensions.scenarioLabelXPos, this.dimensions.scenarioLabelYPos).draw(true);
1417
- }
1418
- }
1419
- drawColumnDataLabel(dataFormatDigits, measureScale = new SiPrefix()) {
1420
- var _a;
1421
- (_a = this.label) === null || _a === void 0 ? void 0 : _a.draw(this.isPrimaryColumn, dataFormatDigits, measureScale);
1422
- }
1423
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1424
- getFillStyle(scenarioStyle) {
1425
- var _a, _b, _c, _d;
1426
- const pattern = this.columnBarStyles[this.dataPoint.getScenario()];
1427
- if ((pattern === null || pattern === void 0 ? void 0 : pattern.fillpattern) && ((_a = this.styles.pattern.get(pattern.fillpattern)) === null || _a === void 0 ? void 0 : _a.pattern)) {
1428
- return (_d = (_c = (_b = this.styles) === null || _b === void 0 ? void 0 : _b.pattern) === null || _c === void 0 ? void 0 : _c.get(pattern.fillpattern)) === null || _d === void 0 ? void 0 : _d.pattern;
1429
- }
1430
- return this.convertToSVGStyle(scenarioStyle, "fill");
1431
- }
1432
- getScenarioStyle() {
1433
- var _a;
1434
- if (this.isVarianceColumn) {
1435
- return (_a = this.styles) === null || _a === void 0 ? void 0 : _a.varianceStyles.getSVGStyle(this.dataPoint.getVarianceStyle());
1436
- }
1437
- return this.columnBarStyles[this.dataPoint.getScenario()];
1438
- }
1439
- isEmpty() {
1440
- return false === this.hasData || Number.isNaN(this.dataPoint.value);
1441
- }
1442
- }
1443
-
1444
- /**
1445
- * Renders a diamond/triangle marker indicator for PP or PL reference values in a time chart.
1446
- *
1447
- * Markers are small polygon shapes (defined by SVGPolgonPattern) positioned at the
1448
- * data point's scaled value height. They consist of a white background polygon for
1449
- * contrast and a foreground polygon with scenario-specific fill/stroke.
1450
- *
1451
- * Primary markers appear to the left of the column center; secondary markers to the right.
1452
- * Each carries an optional scenario label that is drawn at the marker's data level.
1453
- */
1454
- class Marker {
1455
- constructor(position, markerGroup, markerPattern, scenario, styles, dataPoint, index, labelText, isPrimaryMarker) {
1456
- this.ID_DATA_PREFIX = "DATA";
1457
- this.ID_SCENARIO_PREFIX = "SCENARIO";
1458
- this.FALLBACK_COLOUR = "#000000";
1459
- this.scenarioLabel = null;
1460
- this._defaultMarkerPattern = null;
1461
- this.dimensions = {
1462
- columnLength: 0,
1463
- xPos: 0,
1464
- yPos: 0,
1465
- labelYPos: 0,
1466
- scenarioLabelXPos: 0,
1467
- scenarioLabelYPos: 0,
1468
- clipped: false,
1469
- };
1470
- this.hasData = false;
1471
- this.position = position;
1472
- this.markerGroup = markerGroup || null;
1473
- this.markerPattern = markerPattern || this._defaultMarkerPattern;
1474
- this.styles = styles;
1475
- this.barStyles = styles ? styles.barStyles : null;
1476
- this.scenario = scenario;
1477
- if ((dataPoint === null || dataPoint === void 0 ? void 0 : dataPoint.isEmpty()) !== true) {
1478
- this.hasData = true;
1479
- this.dimensions = this.createMarkerDimensions(dataPoint, index, isPrimaryMarker);
1480
- this.scenarioLabel = this.getScenarioLabel(labelText, styles, isPrimaryMarker);
1481
- }
1482
- }
1483
- draw() {
1484
- if (this.isEmpty()) {
1485
- return this;
1486
- }
1487
- const whiteBorder = "#ffffff";
1488
- const strokeStyle = this.convertToSVGStyle(this.barStyles[this.getScenario()], "stroke");
1489
- let fillStyle = this.convertToSVGStyle(this.barStyles[this.getScenario()], "fill");
1490
- const pattern = this.barStyles[this.getScenario()];
1491
- if (pattern != null && pattern.fillpattern) {
1492
- const polygonPattern = this.styles.pattern.get(pattern.fillpattern);
1493
- if (polygonPattern != null) {
1494
- fillStyle = polygonPattern.pattern;
1495
- }
1496
- }
1497
- this.markerGroup
1498
- .polygon(this.markerPattern.background)
1499
- .fill(whiteBorder)
1500
- .cy(this.dimensions.yPos - this.dimensions.columnLength)
1501
- .cx(this.dimensions.xPos);
1502
- this.markerGroup
1503
- .polygon(this.markerPattern.foreground)
1504
- .fill(fillStyle)
1505
- .stroke(strokeStyle)
1506
- .cy(this.dimensions.yPos - this.dimensions.columnLength)
1507
- .cx(this.dimensions.xPos);
1508
- if (this.scenarioLabel != null && !this.scenarioLabel.isEmpty()) {
1509
- this.scenarioLabel.setPos(this.dimensions.scenarioLabelXPos, this.dimensions.scenarioLabelYPos).draw();
1510
- }
1511
- return this;
1512
- }
1513
- createMarkerDimensions(dataPoint, index, isPrimaryMarker) {
1514
- if (dataPoint.getScaledUnit() < 0) {
1515
- return {
1516
- clipped: false,
1517
- labelYPos: 0,
1518
- columnLength: dataPoint.getScaledUnit(),
1519
- xPos: this.position.getMarkerPositionX(index, isPrimaryMarker),
1520
- yPos: this.position.getMarkerPositionY(),
1521
- scenarioLabelXPos: this.position.getMarkerPositionX(index, isPrimaryMarker) +
1522
- this.position.getMarkerScenarioLabelPositionOffsetX(isPrimaryMarker),
1523
- scenarioLabelYPos: this.position.getMarkerPositionY() + Math.abs(dataPoint.getScaledUnit()),
1524
- };
1525
- }
1526
- else {
1527
- return {
1528
- clipped: false,
1529
- labelYPos: 0,
1530
- columnLength: dataPoint.getScaledUnit(),
1531
- xPos: this.position.getMarkerPositionX(index, isPrimaryMarker),
1532
- yPos: this.position.getMarkerPositionY(),
1533
- scenarioLabelXPos: this.position.getMarkerPositionX(index, isPrimaryMarker) +
1534
- this.position.getMarkerScenarioLabelPositionOffsetX(isPrimaryMarker),
1535
- scenarioLabelYPos: this.position.getMarkerPositionY() - Math.abs(dataPoint.getScaledUnit()),
1536
- };
1537
- }
1538
- }
1539
- getScenarioLabel(labelText, styles, isPrimaryMarker) {
1540
- if (this.markerGroup == null) {
1541
- return null;
1542
- }
1543
- if (isPrimaryMarker) {
1544
- return new Label(this.markerGroup, -1, -1, this.ID_DATA_PREFIX, labelText, styles, HookLocation.Center, HookLocation.Right);
1545
- }
1546
- return new Label(this.markerGroup, -1, -1, this.ID_DATA_PREFIX, labelText, styles, HookLocation.Center, HookLocation.Left);
1547
- }
1548
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1549
- convertToSVGStyle(style, mode) {
1550
- if (style == null) {
1551
- style = [];
1552
- }
1553
- style["color"] = style[mode] || this.FALLBACK_COLOUR;
1554
- return Object.assign({}, style);
1555
- }
1556
- isEmpty() {
1557
- return false === this.hasData;
1558
- }
1559
- getScenario() {
1560
- var _a;
1561
- return (_a = this.scenario) === null || _a === void 0 ? void 0 : _a.slice(0, 2);
1562
- }
1563
- }
1564
-
1565
- // import {SVGVariancesStyleGroup} from "../../../../utils/model/styles/SVGVariancesStyleGroup";
1566
- /**
1567
- * Renders a relative variance pin (needle) in an IBCS time chart.
1568
- *
1569
- * A needle is a thin vertical bar representing a percentage variance value,
1570
- * topped with an arrowhead. The head style depends on clipping:
1571
- * - Normal: a rectangular crossbar (T-shape)
1572
- * - Clipped (value exceeds 145% scale): a double-arrow polygon indicating the
1573
- * value was truncated to fit the chart area
1574
- *
1575
- * The needle body uses variance-based fill (positive/negative coloring),
1576
- * while the head always uses the AC scenario style for visual emphasis.
1577
- */
1578
- class Needle {
1579
- constructor(position, styles, dataPoint, index, scenarioGroup) {
1580
- this.ID_DATA_PREFIX = "DATA";
1581
- this.ID_SCENARIO_PREFIX = "SCENARIO";
1582
- this.ID_RECT = "RECT";
1583
- this.FALLBACK_COLOUR = "#000000";
1584
- this.dataLabel = null;
1585
- this.dimensions = {
1586
- columnLength: 0,
1587
- xPos: 0,
1588
- yPos: 0,
1589
- labelYPos: 0,
1590
- scenarioLabelXPos: 0,
1591
- scenarioLabelYPos: 0,
1592
- clipped: false,
1593
- };
1594
- this.hasData = false;
1595
- this.dataPoint = dataPoint;
1596
- this.index = index;
1597
- this.position = position;
1598
- this.barStyles = styles.barStyles;
1599
- this.scenarioGroup = scenarioGroup;
1600
- this.styles = styles;
1601
- this.barGroup = scenarioGroup.group().id(scenarioGroup.toString() + "_" + this.ID_RECT);
1602
- if ((dataPoint === null || dataPoint === void 0 ? void 0 : dataPoint.isEmpty()) !== true) {
1603
- this.hasData = true;
1604
- this.dimensions = this.createDimensions(position, dataPoint, index);
1605
- this.dataLabel = new Label(this.scenarioGroup, this.position.getColumnCenterPositionX(this.index), this.position.getNeedleDataLabelPositionY(this.dataPoint.getScaledPercentUnit()), this.ID_DATA_PREFIX, dataPoint.value, this.styles, HookLocation.Center, HookLocation.Center);
1606
- this.dataLabel.setToRelativeVarianceLabel();
1607
- }
1608
- }
1609
- updateLabelGroup(newGroup) {
1610
- var _a;
1611
- if (this.isEmpty()) {
1612
- return this;
1613
- }
1614
- (_a = this.dataLabel) === null || _a === void 0 ? void 0 : _a.updateGroup(newGroup);
1615
- return this;
1616
- }
1617
- draw() {
1618
- var _a;
1619
- if (this.isEmpty()) {
1620
- return this;
1621
- }
1622
- const scenarioStyle = this.styles.varianceStyles[this.dataPoint.getVarianceStyle()];
1623
- const strokeStyle = this.convertToSVGStyle(scenarioStyle, "stroke");
1624
- let fillStyle = this.convertToSVGStyle(scenarioStyle, "fill");
1625
- const strokeStyleHead = this.convertToSVGStyle(this.styles.varianceStyles["ac"], "stroke");
1626
- const fillStyleHead = this.convertToSVGStyle(this.styles.varianceStyles["ac"], "fill");
1627
- const pattern = this.barStyles[this.dataPoint.getScenario()];
1628
- if (pattern != null && pattern.fillpattern) {
1629
- const polygonPattern = this.styles.pattern.get(pattern.fillpattern);
1630
- if (polygonPattern != null) {
1631
- fillStyle = polygonPattern.pattern;
1632
- }
1633
- }
1634
- if (this.dimensions.clipped) {
1635
- this.createClippedNeedleHead(fillStyle, strokeStyle);
1636
- }
1637
- else {
1638
- this.createNeedleHead(strokeStyleHead, fillStyleHead);
1639
- }
1640
- this.barGroup
1641
- .rect(this.position.getNeedleWidth(), this.dimensions.columnLength)
1642
- .cx(this.dimensions.xPos)
1643
- .y(this.dimensions.yPos)
1644
- .fill(fillStyle)
1645
- .stroke(strokeStyle);
1646
- (_a = this.dataLabel) === null || _a === void 0 ? void 0 : _a.draw();
1647
- }
1648
- createDimensions(position, dataPoint, index) {
1649
- if (dataPoint.getScaledPercentUnit() < 0) {
1650
- return {
1651
- labelYPos: 0,
1652
- scenarioLabelXPos: 0,
1653
- scenarioLabelYPos: 0,
1654
- columnLength: Math.abs(dataPoint.getScaledPercentUnit()),
1655
- xPos: position.getColumnCenterPositionX(index),
1656
- yPos: position.getNeedlePositionY(),
1657
- clipped: dataPoint.isClipped(),
1658
- };
1659
- }
1660
- else {
1661
- return {
1662
- columnLength: dataPoint.getScaledPercentUnit(),
1663
- xPos: position.getColumnCenterPositionX(index),
1664
- yPos: position.getNeedlePositionY() - dataPoint.getScaledPercentUnit(),
1665
- labelYPos: 0,
1666
- scenarioLabelXPos: 0,
1667
- scenarioLabelYPos: 0,
1668
- clipped: dataPoint.isClipped(),
1669
- };
1670
- }
1671
- }
1672
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1673
- convertToSVGStyle(style, mode) {
1674
- if (style == null) {
1675
- style = [];
1676
- }
1677
- style["color"] = style[mode] || this.FALLBACK_COLOUR;
1678
- return Object.assign({}, style);
1679
- }
1680
- createClippedNeedleHead(fillStyle, strokeStyle) {
1681
- const arrowUp = "0,0 5,9 -5,9 0,0 0,5 5,13 -5,13 0,5";
1682
- const head = this.barGroup
1683
- .polygon(arrowUp)
1684
- .fill(fillStyle)
1685
- .cx(this.dimensions.xPos)
1686
- .cy(this.getHeadYPosition())
1687
- .fill(fillStyle)
1688
- .stroke(strokeStyle);
1689
- if (this.dataPoint.value != null && this.dataPoint.value < 0) {
1690
- head.flip("y");
1691
- }
1692
- }
1693
- createNeedleHead(strokeStyleHead, fillStyleHead) {
1694
- this.barGroup
1695
- .rect(2 * this.position.getNeedleWidth(), this.position.getNeedleHeadWidth())
1696
- .cx(this.dimensions.xPos)
1697
- .cy(this.getHeadYPosition())
1698
- .fill(strokeStyleHead)
1699
- .stroke(fillStyleHead);
1700
- }
1701
- isEmpty() {
1702
- return false === this.hasData || Number.isNaN(this.dataPoint.value);
1703
- }
1704
- getHeadYPosition() {
1705
- let yPosition = this.dimensions.yPos;
1706
- if (this.dataPoint.value != null && this.dataPoint.value < 0) {
1707
- yPosition += this.dimensions.columnLength;
1708
- }
1709
- return yPosition;
1710
- }
1711
- }
1712
-
1713
- const IBCS_LINE_STYLES = {
1714
- ac: { markerFill: "#000000", markerStroke: "#000000", lineColor: "#000000" },
1715
- pp: { markerFill: "#999999", markerStroke: "#999999", lineColor: "#999999" },
1716
- fc: { markerFill: "#ffffff", markerStroke: "#000000", lineColor: "#000000", lineDashArray: "4,4" },
1717
- pl: { markerFill: "#ffffff", markerStroke: "#000000", lineColor: "#000000" },
1718
- };
1719
- class LineSeries {
1720
- constructor(position, styles, dataPoints, scenarioGroup, labelGroup, scenarioName, scenarioLabel, _i18n, collisionManager = null) {
1721
- this.MARKER_SIZE = 8;
1722
- this.LINE_WIDTH = 2;
1723
- this.ID_LINE_PREFIX = "LINE";
1724
- this.ID_MARKER_PREFIX = "MARKER";
1725
- this.ID_LABEL_PREFIX = "LABEL";
1726
- this.ESTIMATED_LABEL_WIDTH = 56;
1727
- this.ESTIMATED_LABEL_HEIGHT = 24;
1728
- this.position = position;
1729
- this.styles = styles;
1730
- this.dataPoints = dataPoints;
1731
- this.scenarioGroup = scenarioGroup;
1732
- this.labelGroup = labelGroup;
1733
- this.scenarioName = scenarioName;
1734
- this.scenarioLabel = scenarioLabel;
1735
- this.collisionManager = collisionManager;
1736
- }
1737
- /**
1738
- * Backward-compatible: draws everything (geometry + labels) in one call.
1739
- */
1740
- draw(dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix()) {
1741
- this.drawGeometry();
1742
- this.drawLabels(dataFormatDigits, measureScale);
1743
- return this;
1744
- }
1745
- /**
1746
- * Phase 1: Draw only geometry (lines + markers). No labels.
1747
- */
1748
- drawGeometry() {
1749
- if (this.dataPoints.length === 0) {
1750
- return this;
1751
- }
1752
- const lineStyle = this.getLineStyle();
1753
- this.drawLines(lineStyle);
1754
- this.drawMarkers(lineStyle);
1755
- return this;
1756
- }
1757
- /**
1758
- * Phase 2: Draw only labels (value labels + scenario label).
1759
- * Call this after all series geometry is drawn, in priority order.
1760
- */
1761
- drawLabels(dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix()) {
1762
- if (this.dataPoints.length === 0) {
1763
- return this;
1764
- }
1765
- // Draw scenario labels first (behind), then value labels on top
1766
- this.drawScenarioLabel();
1767
- this.drawValueLabels(dataFormatDigits, measureScale);
1768
- return this;
1769
- }
1770
- getLineStyle() {
1771
- var _a, _b;
1772
- const scenarioType = ((_b = (_a = this.scenarioName) === null || _a === void 0 ? void 0 : _a.slice(0, 2)) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "ac";
1773
- return IBCS_LINE_STYLES[scenarioType] || IBCS_LINE_STYLES.ac;
1774
- }
1775
- /**
1776
- * Extracts the scenario variant number (1-4) from the scenario name.
1777
- * e.g., "ac1" -> 1, "pp2" -> 2, "fc3" -> 3, "pl4" -> 4
1778
- */
1779
- getScenarioVariant() {
1780
- var _a;
1781
- const variant = parseInt(((_a = this.scenarioName) === null || _a === void 0 ? void 0 : _a.slice(-1)) || "1", 10);
1782
- return isNaN(variant) ? 1 : Math.min(Math.max(variant, 1), 4);
1783
- }
1784
- /**
1785
- * Draws a square marker (variant 1: ac1, pp1, fc1, pl1)
1786
- */
1787
- drawSquareMarker(group, cx, cy, style) {
1788
- const halfSize = this.MARKER_SIZE / 2;
1789
- group
1790
- .rect(this.MARKER_SIZE, this.MARKER_SIZE)
1791
- .fill(style.markerFill)
1792
- .stroke({ color: style.markerStroke, width: 1 })
1793
- .move(cx - halfSize, cy - halfSize);
1794
- }
1795
- /**
1796
- * Draws a circle marker (variant 2: ac2, pp2, fc2, pl2)
1797
- */
1798
- drawCircleMarker(group, cx, cy, style) {
1799
- group
1800
- .circle(this.MARKER_SIZE)
1801
- .fill(style.markerFill)
1802
- .stroke({ color: style.markerStroke, width: 1 })
1803
- .center(cx, cy);
1804
- }
1805
- /**
1806
- * Draws a triangle marker pointing up (variant 3: ac3, pp3, fc3, pl3)
1807
- */
1808
- drawTriangleMarker(group, cx, cy, style) {
1809
- const s = this.MARKER_SIZE / 2;
1810
- group
1811
- .polygon(`${cx},${cy - s} ${cx - s},${cy + s} ${cx + s},${cy + s}`)
1812
- .fill(style.markerFill)
1813
- .stroke({ color: style.markerStroke, width: 1 });
1814
- }
1815
- /**
1816
- * Draws a diamond marker (variant 4: ac4, pp4, fc4, pl4)
1817
- */
1818
- drawDiamondMarker(group, cx, cy, style) {
1819
- const s = this.MARKER_SIZE / 2;
1820
- group
1821
- .polygon(`${cx},${cy - s} ${cx + s},${cy} ${cx},${cy + s} ${cx - s},${cy}`)
1822
- .fill(style.markerFill)
1823
- .stroke({ color: style.markerStroke, width: 1 });
1824
- }
1825
- drawLines(lineStyle) {
1826
- const lineGroup = this.scenarioGroup.group().id(this.ID_LINE_PREFIX);
1827
- for (let i = 1; i < this.dataPoints.length; i++) {
1828
- const prevPoint = this.dataPoints[i - 1];
1829
- const currPoint = this.dataPoints[i];
1830
- // Skip if either point has no data
1831
- if (prevPoint.dataPoint.isEmpty() || currPoint.dataPoint.isEmpty()) {
1832
- continue;
1833
- }
1834
- const prevX = this.position.getColumnCenterPositionX(prevPoint.index);
1835
- const prevY = this.position.getColumnPositionY() - prevPoint.dataPoint.getScaledUnit();
1836
- const currX = this.position.getColumnCenterPositionX(currPoint.index);
1837
- const currY = this.position.getColumnPositionY() - currPoint.dataPoint.getScaledUnit();
1838
- const line = lineGroup
1839
- .line([
1840
- [prevX, prevY],
1841
- [currX, currY],
1842
- ])
1843
- .stroke({
1844
- color: lineStyle.lineColor,
1845
- width: this.LINE_WIDTH,
1846
- linecap: "round",
1847
- })
1848
- .fill("none");
1849
- if (lineStyle.lineDashArray) {
1850
- line.attr("stroke-dasharray", lineStyle.lineDashArray);
1851
- }
1852
- }
1853
- }
1854
- drawMarkers(lineStyle) {
1855
- const markerGroup = this.scenarioGroup.group().id(this.ID_MARKER_PREFIX);
1856
- const variant = this.getScenarioVariant();
1857
- for (const point of this.dataPoints) {
1858
- if (point.dataPoint.isEmpty()) {
1859
- continue;
1860
- }
1861
- const centerX = this.position.getColumnCenterPositionX(point.index);
1862
- const centerY = this.position.getColumnPositionY() - point.dataPoint.getScaledUnit();
1863
- // Draw marker shape based on scenario variant
1864
- switch (variant) {
1865
- case 2:
1866
- this.drawCircleMarker(markerGroup, centerX, centerY, lineStyle);
1867
- break;
1868
- case 3:
1869
- this.drawTriangleMarker(markerGroup, centerX, centerY, lineStyle);
1870
- break;
1871
- case 4:
1872
- this.drawDiamondMarker(markerGroup, centerX, centerY, lineStyle);
1873
- break;
1874
- default: // variant 1 or unknown
1875
- this.drawSquareMarker(markerGroup, centerX, centerY, lineStyle);
1876
- break;
1877
- }
1878
- }
1879
- }
1880
- /**
1881
- * Returns direction priority based on line direction at a given point.
1882
- * Default: Above. Only use Below first for true local minima
1883
- * (both neighbors higher than current point).
1884
- */
1885
- getLabelPositionPriority(pointIndex) {
1886
- const current = this.dataPoints[pointIndex];
1887
- // Find nearest non-empty neighbor forward
1888
- let next = null;
1889
- for (let j = pointIndex + 1; j < this.dataPoints.length; j++) {
1890
- if (!this.dataPoints[j].dataPoint.isEmpty()) {
1891
- next = this.dataPoints[j];
1892
- break;
1893
- }
1894
- }
1895
- // Find nearest non-empty neighbor backward
1896
- let prev = null;
1897
- for (let j = pointIndex - 1; j >= 0; j--) {
1898
- if (!this.dataPoints[j].dataPoint.isEmpty()) {
1899
- prev = this.dataPoints[j];
1900
- break;
1901
- }
1902
- }
1903
- // True local minimum: both neighbors exist and are higher
1904
- const currentVal = current.dataPoint.getScaledUnit();
1905
- const isLocalMin = prev && next && prev.dataPoint.getScaledUnit() > currentVal && next.dataPoint.getScaledUnit() > currentVal;
1906
- if (isLocalMin) {
1907
- return [LabelDirection.Below, LabelDirection.Left, LabelDirection.Right, LabelDirection.Above];
1908
- }
1909
- // Default: Above first
1910
- return [LabelDirection.Above, LabelDirection.Left, LabelDirection.Right, LabelDirection.Below];
1911
- }
1912
- getScenarioType() {
1913
- var _a, _b;
1914
- return ((_b = (_a = this.scenarioName) === null || _a === void 0 ? void 0 : _a.slice(0, 2)) === null || _b === void 0 ? void 0 : _b.toLowerCase()) || "ac";
1915
- }
1916
- drawValueLabels(dataFormatDigits, measureScale) {
1917
- const scenarioType = this.getScenarioType();
1918
- for (let i = 0; i < this.dataPoints.length; i++) {
1919
- const point = this.dataPoints[i];
1920
- if (point.dataPoint.isEmpty() || point.dataPoint.value === null) {
1921
- continue;
1922
- }
1923
- const centerX = this.position.getColumnCenterPositionX(point.index);
1924
- const markerY = this.position.getColumnPositionY() - point.dataPoint.getScaledUnit();
1925
- // Use collision manager with 4-direction placement if available
1926
- let labelX = centerX;
1927
- let labelY = markerY - this.MARKER_SIZE / 2 - 2;
1928
- let verticalHook = HookLocation.Bottom;
1929
- let horizontalHook = HookLocation.Center;
1930
- if (this.collisionManager) {
1931
- const directionPriority = this.getLabelPositionPriority(i);
1932
- const placement = this.collisionManager.getOptimalPlacement(centerX, markerY, this.ESTIMATED_LABEL_WIDTH, this.ESTIMATED_LABEL_HEIGHT, point.index, this.MARKER_SIZE, scenarioType, directionPriority);
1933
- if (placement === null) {
1934
- continue; // All positions collide with higher-priority labels — hide
1935
- }
1936
- labelX = placement.labelX;
1937
- labelY = placement.labelY;
1938
- verticalHook = placement.verticalHook;
1939
- horizontalHook = placement.horizontalHook;
1940
- // Register bounds with scenario type
1941
- const bounds = Object.assign(Object.assign({}, placement.bounds), { scenarioType });
1942
- this.collisionManager.register(bounds);
1943
- }
1944
- const label = new Label(this.labelGroup, labelX, labelY, this.ID_LABEL_PREFIX, point.dataPoint.value, this.styles, verticalHook, horizontalHook);
1945
- label.draw(true, dataFormatDigits, measureScale);
1946
- }
1947
- }
1948
- drawScenarioLabel() {
1949
- if (!this.scenarioLabel) {
1950
- return;
1951
- }
1952
- // Find the last non-empty data point
1953
- let lastValidPoint = null;
1954
- for (let i = this.dataPoints.length - 1; i >= 0; i--) {
1955
- if (!this.dataPoints[i].dataPoint.isEmpty()) {
1956
- lastValidPoint = this.dataPoints[i];
1957
- break;
1958
- }
1959
- }
1960
- if (!lastValidPoint) {
1961
- return;
1962
- }
1963
- const lastX = this.position.getColumnCenterPositionX(lastValidPoint.index) + this.MARKER_SIZE + 4;
1964
- const lastY = this.position.getColumnPositionY() - lastValidPoint.dataPoint.getScaledUnit();
1965
- const scenarioType = this.getScenarioType();
1966
- // Hide this scenario label if it's too close to a higher-priority one (e.g. AC)
1967
- if (this.collisionManager) {
1968
- if (this.collisionManager.shouldHideScenarioLabel(lastX, lastY, scenarioType)) {
1969
- return;
1970
- }
1971
- this.collisionManager.registerScenarioLabel(lastX, lastY, scenarioType);
1972
- }
1973
- const scenarioLabelElement = new Label(this.labelGroup, lastX, lastY, "SCENARIO_LABEL", this.scenarioLabel, this.styles, HookLocation.Center, HookLocation.Left);
1974
- scenarioLabelElement.forceStringTypeDraw();
1975
- }
1976
- }
1977
-
1978
- /**
1979
- * Renders a single segment within a stacked bar column in a time chart.
1980
- *
1981
- * Each StackedColumn represents one layer of the stack. It is positioned vertically
1982
- * based on its cumulative baseline value and draws a colored rectangle.
1983
- *
1984
- * Supports three stacking modes:
1985
- * - ABSOLUTE: segment height = value * pixelPerUnit
1986
- * - RELATIVE (100%): segment height proportional to its share of totalValue
1987
- * - ABSOLUTE_RELATIVE: same as absolute but labels show percentages
1988
- *
1989
- * Segment labels are shown only when the segment is tall enough (>= 18px) to avoid clutter.
1990
- * The topmost segment can draw a total label above the full stack via drawTotalLabel().
1991
- */
1992
- class StackedColumn {
1993
- constructor(position, styles, dataPoint, index, baselineValue, _segmentLabel, segmentIndex, stackMode, totalValue, _isScenarioStack, parentGroup) {
1994
- this.hasData = false;
1995
- this.position = position;
1996
- this.styles = styles;
1997
- this.dataPoint = dataPoint;
1998
- this.index = index;
1999
- this.baselineValue = baselineValue;
2000
- this.segmentIndex = segmentIndex;
2001
- this.stackMode = stackMode;
2002
- this.totalValue = totalValue;
2003
- this.group = parentGroup;
2004
- this.columnGroup = parentGroup.group().id(`stacked_col_${index}_seg_${segmentIndex}`);
2005
- if ((dataPoint === null || dataPoint === void 0 ? void 0 : dataPoint.isEmpty()) !== true && dataPoint.value != null) {
2006
- this.hasData = true;
2007
- }
2008
- }
2009
- draw(dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix()) {
2010
- if (!this.hasData || this.dataPoint.value == null) {
2011
- return;
2012
- }
2013
- const value = this.dataPoint.value;
2014
- const pixelPerUnit = this.dataPoint.pixelPerUnit;
2015
- let segmentHeight;
2016
- let yPos;
2017
- const axisY = this.position.getColumnPositionY();
2018
- if (this.stackMode === StackMode.RELATIVE) {
2019
- // 100% stacked: segment height is proportion of total
2020
- const proportion = this.totalValue !== 0 ? Math.abs(value) / Math.abs(this.totalValue) : 0;
2021
- // Use a fixed total height based on pixelPerUnit (total=1.0 for 100%)
2022
- const totalPixelHeight = pixelPerUnit; // pixelPerUnit represents the height for 100%
2023
- segmentHeight = proportion * totalPixelHeight;
2024
- const baselinePixels = (this.baselineValue / Math.abs(this.totalValue)) * totalPixelHeight;
2025
- yPos = axisY - baselinePixels - segmentHeight;
2026
- }
2027
- else {
2028
- // Absolute or absolute-relative: use real pixel scaling
2029
- segmentHeight = Math.abs(value * pixelPerUnit);
2030
- const baselinePixels = this.baselineValue * pixelPerUnit;
2031
- yPos = axisY - baselinePixels - segmentHeight;
2032
- }
2033
- const xPos = this.position.getColumnCenterPositionX(this.index);
2034
- const columnWidth = this.position.getColumnWidth();
2035
- // Unified IBCS 3-color palette for all stacking modes
2036
- const fillColor = getStackFill(this.segmentIndex);
2037
- const fillStyle = { color: fillColor };
2038
- const strokeStyle = { color: getStackStroke(this.segmentIndex), width: 0.5 };
2039
- // Draw rectangle
2040
- this.columnGroup
2041
- .rect(columnWidth, Math.max(segmentHeight, 0.5))
2042
- .fill(fillStyle)
2043
- .stroke(strokeStyle)
2044
- .y(yPos)
2045
- .cx(xPos);
2046
- // Draw segment value label if segment is tall enough (min ~18px)
2047
- const MIN_SEGMENT_HEIGHT_FOR_LABEL = 18;
2048
- if (segmentHeight >= MIN_SEGMENT_HEIGHT_FOR_LABEL) {
2049
- const labelY = yPos + segmentHeight / 2;
2050
- if (this.stackMode === StackMode.RELATIVE || this.stackMode === StackMode.ABSOLUTE_RELATIVE) {
2051
- const pct = this.totalValue !== 0 ? (value / this.totalValue) * 100 : 0;
2052
- const labelValue = pct.toFixed(dataFormatDigits.percent) + "%";
2053
- new Label(this.group, xPos, labelY, "STACK_SEG", labelValue, this.styles, HookLocation.Center, HookLocation.Center)
2054
- .setSegmentFill(fillColor)
2055
- .forceStringTypeDraw();
2056
- }
2057
- else {
2058
- // Pass raw numeric value — Label.draw() formats with measureScale
2059
- new Label(this.group, xPos, labelY, "STACK_SEG", value, this.styles, HookLocation.Center, HookLocation.Center)
2060
- .setSegmentFill(fillColor)
2061
- .draw(true, dataFormatDigits, measureScale);
2062
- }
2063
- }
2064
- }
2065
- /**
2066
- * Draw the total label above the topmost segment.
2067
- */
2068
- drawTotalLabel(dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix()) {
2069
- if (this.stackMode === StackMode.RELATIVE) {
2070
- // Don't show total for 100% stacked (always 100%)
2071
- return;
2072
- }
2073
- const xPos = this.position.getColumnCenterPositionX(this.index);
2074
- const axisY = this.position.getColumnPositionY();
2075
- const totalPixels = this.totalValue * this.dataPoint.pixelPerUnit;
2076
- const labelY = axisY - totalPixels - this.position.spacings.labelToColumn;
2077
- const label = new Label(this.group, xPos, labelY, "STACK_TOTAL", this.totalValue, this.styles, HookLocation.Bottom, HookLocation.Center);
2078
- label.draw(true, dataFormatDigits, measureScale);
2079
- }
2080
- }
2081
-
2082
- /**
2083
- * IBCS-style area fill colors for stacked area charts.
2084
- */
2085
- const SCENARIO_AREA_STYLES = {
2086
- ac: { fill: "#000000", opacity: 0.3, lineColor: "#000000" },
2087
- pp: { fill: "#999999", opacity: 0.3, lineColor: "#999999" },
2088
- fc: { fill: "#000000", opacity: 0.2, lineColor: "#000000", dashArray: "4,4" },
2089
- pl: { fill: "#000000", opacity: 0.1, lineColor: "#000000" },
2090
- };
2091
- const GRAYSCALE_AREA_STYLES = [
2092
- { fill: "#000000", opacity: 0.3 },
2093
- { fill: "#555555", opacity: 0.25 },
2094
- { fill: "#999999", opacity: 0.2 },
2095
- { fill: "#bbbbbb", opacity: 0.15 },
2096
- { fill: "#dddddd", opacity: 0.1 },
2097
- ];
2098
- /**
2099
- * Draws an SVG path filling the area between an upper boundary polyline
2100
- * and a lower boundary polyline — used for stacked area charts.
2101
- */
2102
- class AreaFill {
2103
- constructor(parentGroup, upperPoints, lowerPoints, scenarioType, segmentIndex, isScenarioStack) {
2104
- this.group = parentGroup.group().id(`area_fill_${segmentIndex}`);
2105
- this.upperPoints = upperPoints;
2106
- this.lowerPoints = lowerPoints;
2107
- this.scenarioType = scenarioType;
2108
- this.segmentIndex = segmentIndex;
2109
- this.isScenarioStack = isScenarioStack;
2110
- }
2111
- draw() {
2112
- if (this.upperPoints.length < 2 || this.lowerPoints.length < 2) {
2113
- return;
2114
- }
2115
- // Build SVG path: upper line forward, then lower line backward
2116
- let pathStr = `M ${this.upperPoints[0].x},${this.upperPoints[0].y}`;
2117
- for (let i = 1; i < this.upperPoints.length; i++) {
2118
- pathStr += ` L ${this.upperPoints[i].x},${this.upperPoints[i].y}`;
2119
- }
2120
- // Walk lower points in reverse to close the shape
2121
- for (let i = this.lowerPoints.length - 1; i >= 0; i--) {
2122
- pathStr += ` L ${this.lowerPoints[i].x},${this.lowerPoints[i].y}`;
2123
- }
2124
- pathStr += " Z";
2125
- let fill;
2126
- let opacity;
2127
- if (this.isScenarioStack && this.scenarioType) {
2128
- const prefix = this.scenarioType.slice(0, 2).toLowerCase();
2129
- const style = SCENARIO_AREA_STYLES[prefix] || SCENARIO_AREA_STYLES["ac"];
2130
- fill = style.fill;
2131
- opacity = style.opacity;
2132
- }
2133
- else {
2134
- const idx = Math.min(this.segmentIndex, GRAYSCALE_AREA_STYLES.length - 1);
2135
- fill = GRAYSCALE_AREA_STYLES[idx].fill;
2136
- opacity = GRAYSCALE_AREA_STYLES[idx].opacity;
2137
- }
2138
- this.group.path(pathStr).fill(fill).opacity(opacity).stroke("none");
2139
- }
2140
- /**
2141
- * Draw the boundary line on top of the area fill.
2142
- */
2143
- drawBoundaryLine() {
2144
- if (this.upperPoints.length < 2) {
2145
- return;
2146
- }
2147
- let lineColor = "#000000";
2148
- let dashArray;
2149
- if (this.isScenarioStack && this.scenarioType) {
2150
- const prefix = this.scenarioType.slice(0, 2).toLowerCase();
2151
- const style = SCENARIO_AREA_STYLES[prefix] || SCENARIO_AREA_STYLES["ac"];
2152
- lineColor = style.lineColor;
2153
- dashArray = style.dashArray;
2154
- }
2155
- const polyline = this.group
2156
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2157
- .polyline(this.upperPoints.map((p) => [p.x, p.y]))
2158
- .fill("none")
2159
- .stroke({ color: lineColor, width: 1.5 });
2160
- if (dashArray) {
2161
- polyline.attr("stroke-dasharray", dashArray);
2162
- }
2163
- }
2164
- }
2165
-
2166
- // import { DataFormatDigits } from "../../../../utils/model/DataFormatDigits";
2167
- // import { SiPrefix } from "../../../../utils/model/SiPrefix";
2168
- /**
2169
- * Renders a line segment connecting two consecutive DataPoints in a time chart.
2170
- *
2171
- * Each Line instance represents the segment from a previous data point to the current one.
2172
- * Dimensions for both endpoints are computed so the SVG line can be drawn between them.
2173
- * The primary line (first scenario) receives the scenario label at the end of the series.
2174
- *
2175
- * Used by the overlay layer (average/median lines), not by the main LineSeries rendering.
2176
- */
2177
- class Line {
2178
- constructor(position, styles, dataPoint, previousDataPoint, index, isPrimaryLine, scenarioGroup, LineLabel) {
2179
- this.ID_DATA_PREFIX = "DATA";
2180
- this.ID_SCENARIO_PREFIX = "SCENARIO";
2181
- this.ID_RECT = "RECT";
2182
- this.FALLBACK_COLOUR = "#000000";
2183
- this.label = null;
2184
- this.scenarioLabel = null;
2185
- this.isVarianceLine = false;
2186
- this.dimensions = {
2187
- columnLength: 0,
2188
- xPos: 0,
2189
- yPos: 0,
2190
- labelYPos: 0,
2191
- scenarioLabelXPos: 0,
2192
- scenarioLabelYPos: 0,
2193
- clipped: false,
2194
- };
2195
- this.previousDimensions = {
2196
- columnLength: 0,
2197
- xPos: 0,
2198
- yPos: 0,
2199
- labelYPos: 0,
2200
- scenarioLabelXPos: 0,
2201
- scenarioLabelYPos: 0,
2202
- clipped: false,
2203
- };
2204
- this.hasData = false;
2205
- this.dataPoint = dataPoint;
2206
- // this.previousDataPoint = previousDataPoint;
2207
- this.index = index;
2208
- this.isPrimaryLine = isPrimaryLine;
2209
- this.position = position;
2210
- this.LineBarStyles = styles.barStyles;
2211
- this.scenarioGroup = scenarioGroup;
2212
- this.styles = styles;
2213
- this.LineGroup = scenarioGroup.group().id(scenarioGroup.toString() + "_" + this.ID_RECT);
2214
- if ((dataPoint === null || dataPoint === void 0 ? void 0 : dataPoint.isEmpty()) !== true) {
2215
- this.hasData = true;
2216
- this.dimensions = this.createDimensions(dataPoint, index, isPrimaryLine);
2217
- this.label = this.getDataLabel(dataPoint);
2218
- this.scenarioLabel = this.getScenarioLabel(LineLabel);
2219
- }
2220
- this.previousDimensions = this.createDimensions(previousDataPoint, index - 1, isPrimaryLine);
2221
- }
2222
- setAsVariance() {
2223
- var _a;
2224
- this.isVarianceLine = true;
2225
- (_a = this.label) === null || _a === void 0 ? void 0 : _a.setToVarianceLabel();
2226
- return this;
2227
- }
2228
- updateLabelGroup(newGroup) {
2229
- var _a;
2230
- if (this.isEmpty()) {
2231
- return this;
2232
- }
2233
- (_a = this.label) === null || _a === void 0 ? void 0 : _a.updateGroup(newGroup);
2234
- return this;
2235
- }
2236
- draw(dataFormatDigits = { percent: 2, decimal: 1 }, measureScale = new SiPrefix()) {
2237
- // TODE: JHE: Remove DataFOrmatDigits Type Duplicates
2238
- if (this.isEmpty()) {
2239
- return this;
2240
- }
2241
- const scenarioStyle = this.getScenarioStyle();
2242
- // let strokeStyle = "#00FF00"; //this.convertToSVGStyle(scenarioStyle, "stroke");
2243
- const fillStyle = this.getFillStyle(scenarioStyle);
2244
- if (this.LineGroup != null) {
2245
- this.LineGroup.line([
2246
- [this.previousDimensions.xPos, this.previousDimensions.yPos],
2247
- [this.dimensions.xPos, this.dimensions.yPos],
2248
- ])
2249
- .fill(fillStyle)
2250
- .stroke({ color: "#f06", width: 3, linecap: "round" });
2251
- }
2252
- this.drawLineDataLabel(dataFormatDigits, measureScale);
2253
- this.drawScenarioLabel();
2254
- }
2255
- createDimensions(dataPoint, index, isPrimaryBar) {
2256
- return {
2257
- clipped: false,
2258
- columnLength: dataPoint.getScaledUnit(),
2259
- xPos: this.position.getColumnPositionX(index, isPrimaryBar),
2260
- yPos: this.position.getColumnPositionY() - dataPoint.getScaledUnit(),
2261
- labelYPos: this.position.getColumnDataLabelPositionY(dataPoint.getScaledUnit()),
2262
- scenarioLabelXPos: this.position.getColumnPositionX(index, isPrimaryBar) +
2263
- this.position.getScenarioLabelPositionOffsetX(isPrimaryBar),
2264
- scenarioLabelYPos: this.position.getColumnPositionY() - dataPoint.getScaledUnit(),
2265
- };
2266
- }
2267
- getDataLabel(dataPoint) {
2268
- let labelHook = HookLocation.Bottom;
2269
- if (dataPoint.value != null && dataPoint.value < 0) {
2270
- labelHook = HookLocation.Top;
2271
- }
2272
- return new Label(this.scenarioGroup, this.position.getColumnCenterPositionX(this.index), this.position.getColumnDataLabelPositionY(this.dataPoint.getScaledUnit()), this.ID_DATA_PREFIX, dataPoint.value, this.styles, labelHook, HookLocation.Center);
2273
- }
2274
- getScenarioLabel(LineLabel) {
2275
- return new Label(this.scenarioGroup, 0, 0, this.ID_SCENARIO_PREFIX, LineLabel, this.styles, HookLocation.Bottom, HookLocation.Left);
2276
- }
2277
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2278
- convertToSVGStyle(style, mode) {
2279
- if (style == null) {
2280
- style = [];
2281
- }
2282
- style["color"] = style[mode] || this.FALLBACK_COLOUR;
2283
- return Object.assign({}, style);
2284
- }
2285
- drawScenarioLabel() {
2286
- if (this.scenarioLabel != null && !this.scenarioLabel.isEmpty() && !this.isVarianceLine) {
2287
- this.scenarioLabel.setPos(this.dimensions.scenarioLabelXPos, this.dimensions.scenarioLabelYPos).draw(true);
2288
- }
2289
- }
2290
- drawLineDataLabel(dataFormatDigits, measureScale = new SiPrefix()) {
2291
- var _a;
2292
- (_a = this.label) === null || _a === void 0 ? void 0 : _a.draw(this.isPrimaryLine, dataFormatDigits, measureScale);
2293
- }
2294
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
2295
- getFillStyle(scenarioStyle) {
2296
- var _a, _b, _c, _d;
2297
- const pattern = this.LineBarStyles[this.dataPoint.getScenario()];
2298
- if ((pattern === null || pattern === void 0 ? void 0 : pattern.fillpattern) && ((_a = this.styles.pattern.get(pattern.fillpattern)) === null || _a === void 0 ? void 0 : _a.pattern)) {
2299
- return (_d = (_c = (_b = this.styles) === null || _b === void 0 ? void 0 : _b.pattern) === null || _c === void 0 ? void 0 : _c.get(pattern.fillpattern)) === null || _d === void 0 ? void 0 : _d.pattern;
2300
- }
2301
- return this.convertToSVGStyle(scenarioStyle, "fill");
2302
- }
2303
- getScenarioStyle() {
2304
- var _a;
2305
- if (this.isVarianceLine) {
2306
- return (_a = this.styles) === null || _a === void 0 ? void 0 : _a.varianceStyles.getSVGStyle(this.dataPoint.getVarianceStyle());
2307
- }
2308
- return this.LineBarStyles[this.dataPoint.getScenario()];
2309
- }
2310
- isEmpty() {
2311
- return false === this.hasData || Number.isNaN(this.dataPoint.value);
2312
- }
2313
- }
2314
-
2315
- /**
2316
- * Factory for creating chart element instances (Column, Needle, Marker, Line, LineSeries)
2317
- * within the correct SVG group hierarchy.
2318
- *
2319
- * Manages 4 SVG group layers for z-ordering (back-to-front):
2320
- * - scenario2: secondary bars (PP) -- inserted before scenario1 so they render behind
2321
- * - scenario1: primary bars (AC) -- foreground
2322
- * - scenario3: primary markers (e.g. FC diamonds)
2323
- * - scenario4: secondary markers (e.g. PL triangles)
2324
- * - scenario1Label: label group, always rendered on top of all geometry
2325
- *
2326
- * createPrimaryBar() produces a foreground Column (AC) with data + scenario labels.
2327
- * createSecondaryBar() produces a background Column (PP) without data labels.
2328
- * createPrimaryMarker() / createSecondaryMarker() produce Marker instances on opposite sides.
2329
- * createVarianceBar() wraps a Column with variance styling.
2330
- * createRelativeVarianceBar() creates a Needle for percentage variance display.
2331
- * createLineSeries() creates a LineSeries for line chart mode.
2332
- */
2333
- class ScenarioFactory {
2334
- constructor(position, scenariosGroupParent, styles, elementCnt, i18n) {
2335
- this.pixelPerUnit = 1;
2336
- this.collisionManager = null;
2337
- this.overflowConfig = null;
2338
- this.i18n = i18n;
2339
- const primScenario = scenariosGroupParent.group().id("Scenario1");
2340
- const secondScenario = scenariosGroupParent.group().id("Scenario2").insertBefore(primScenario);
2341
- this.svgGroups = {
2342
- parent: scenariosGroupParent,
2343
- scenario1: primScenario,
2344
- scenario2: secondScenario,
2345
- scenario3: scenariosGroupParent.group().id("Scenario3"),
2346
- scenario4: scenariosGroupParent.group().id("Scenario4"),
2347
- scenario1Label: scenariosGroupParent.group().id("label"),
2348
- };
2349
- this.styles = styles;
2350
- this.position = position;
2351
- this.elementCnt = elementCnt;
2352
- }
2353
- setOverflowConfig(config) {
2354
- this.overflowConfig = config;
2355
- }
2356
- createLine(name, dataPoint, previousDataPoint, index) {
2357
- const isPrimaryColumn = false;
2358
- const columnGroup = this.svgGroups.scenario1.group().id("" + index);
2359
- const labelGroup = this.svgGroups.scenario1Label.group().id("" + index);
2360
- let lineLabel = null;
2361
- if (this.isLastDataPoint(index - 1)) {
2362
- lineLabel = name; ///`${this.i18n.get(dataPoint.scenario as string) || dataPoint.scenario}`;
2363
- }
2364
- return new Line(this.position, this.styles, dataPoint, previousDataPoint, index, isPrimaryColumn, columnGroup, lineLabel).updateLabelGroup(labelGroup);
2365
- }
2366
- createPrimaryBar(dataPoint, index) {
2367
- const isPrimaryColumn = true;
2368
- const columnGroup = this.svgGroups.scenario1.group().id("" + index);
2369
- const labelGroup = this.svgGroups.scenario1Label.group().id("" + index);
2370
- let columnLabel = null;
2371
- if (this.isLastDataPoint(index)) {
2372
- columnLabel = `${this.i18n.get(dataPoint.scenario) || dataPoint.scenario}`;
2373
- }
2374
- return new Column(this.position, this.styles, dataPoint, index, isPrimaryColumn, columnGroup, columnLabel, this.overflowConfig).updateLabelGroup(labelGroup);
2375
- }
2376
- createVarianceBar(dataPoint, index) {
2377
- const isPrimaryColumn = true;
2378
- const columnGroup = this.svgGroups.scenario1.group().id("" + index);
2379
- const labelGroup = this.svgGroups.scenario1Label.group().id("" + index);
2380
- let columnLabel = null;
2381
- if (this.isLastDataPoint(index)) {
2382
- columnLabel = `${this.i18n.get(dataPoint.scenario) || dataPoint.scenario}`;
2383
- }
2384
- return new Column(this.position, this.styles, dataPoint, index, isPrimaryColumn, columnGroup, columnLabel, this.overflowConfig)
2385
- .updateLabelGroup(labelGroup)
2386
- .setAsVariance();
2387
- }
2388
- createRelativeVarianceBar(dataPoint, index) {
2389
- const needleGroup = this.svgGroups.scenario1.group().id("" + index);
2390
- const labelGroup = this.svgGroups.scenario1Label.group().id("" + index);
2391
- return new Needle(this.position, this.styles, dataPoint, index, needleGroup).updateLabelGroup(labelGroup);
2392
- }
2393
- createSecondaryBar(dataPoint, index) {
2394
- const isPrimaryBar = false;
2395
- const barGroup = this.svgGroups.scenario2.group().id("" + index);
2396
- let columnLabel = null;
2397
- if (this.isFirstDataPoint(index)) {
2398
- columnLabel = `${this.i18n.get(dataPoint.scenario) || dataPoint.scenario}`;
2399
- }
2400
- return new Column(this.position, this.styles, dataPoint, index, isPrimaryBar, barGroup, columnLabel, this.overflowConfig);
2401
- }
2402
- createPrimaryMarker(dataPoint, index) {
2403
- const markerGroup = this.svgGroups.scenario3.group().id("" + index);
2404
- const markerPattern = this.styles.pattern.get("marker-right") || {
2405
- foreground: "#000000",
2406
- background: "#ffffff",
2407
- bgOffset: 0,
2408
- };
2409
- const isPrimaryMarker = true;
2410
- let columnLabel = null;
2411
- if (this.isFirstDataPoint(index)) {
2412
- columnLabel = `${this.i18n.get(dataPoint.scenario) || dataPoint.scenario}`;
2413
- }
2414
- return new Marker(this.position, markerGroup, markerPattern, dataPoint.scenario, this.styles, dataPoint, index, columnLabel, isPrimaryMarker);
2415
- }
2416
- createSecondaryMarker(dataPoint, index) {
2417
- const markerGroup = this.svgGroups.scenario4.group().id("" + index);
2418
- const markerPattern = this.styles.pattern.get("marker-left") || {
2419
- foreground: "#000000",
2420
- background: "#ffffff",
2421
- bgOffset: 0,
2422
- };
2423
- const isPrimaryMarker = false;
2424
- let columnLabel = null;
2425
- if (this.isLastDataPoint(index)) {
2426
- columnLabel = `${this.i18n.get(dataPoint.scenario) || dataPoint.scenario}`;
2427
- }
2428
- return new Marker(this.position, markerGroup, markerPattern, dataPoint.scenario, this.styles, dataPoint, index, columnLabel, isPrimaryMarker);
2429
- }
2430
- isLastDataPoint(index) {
2431
- return this.elementCnt - 1 === index;
2432
- }
2433
- isFirstDataPoint(index) {
2434
- return 0 === index;
2435
- }
2436
- /**
2437
- * Sets the collision manager for line series label collision detection.
2438
- * Should be called before creating line series to enable collision detection across all series.
2439
- */
2440
- setCollisionManager(manager) {
2441
- this.collisionManager = manager;
2442
- }
2443
- /**
2444
- * Moves the label group to the front of the SVG tree so labels render on top of all geometry.
2445
- */
2446
- moveLabelsToFront() {
2447
- this.svgGroups.scenario1Label.front();
2448
- }
2449
- createLineSeries(dataPoints, scenarioName) {
2450
- const lineSeriesGroup = this.svgGroups.parent.group().id("LineSeries_" + scenarioName);
2451
- const labelGroup = this.svgGroups.scenario1Label.group().id("LineSeries_Label_" + scenarioName);
2452
- // Scenario label for the line (to be shown at the right of the last data point)
2453
- const scenarioLabel = `${this.i18n.get(scenarioName) || scenarioName}`;
2454
- return new LineSeries(this.position, this.styles, dataPoints, lineSeriesGroup, labelGroup, scenarioName, scenarioLabel, this.i18n, this.collisionManager);
2455
- }
2456
- }
2457
-
2458
- /** Tracks whether the internal data model needs to be regenerated. */
2459
- var FactoryState;
2460
- (function (FactoryState) {
2461
- FactoryState[FactoryState["UP_TO_DATE"] = 0] = "UP_TO_DATE";
2462
- FactoryState[FactoryState["DIRTY"] = 1] = "DIRTY";
2463
- })(FactoryState || (FactoryState = {}));
2464
- /** Classifies how a data model entry should be rendered: as an absolute or relative variance, or as a regular scenario. */
2465
- var VarianceType;
2466
- (function (VarianceType) {
2467
- VarianceType["RELATIVE"] = "dr";
2468
- VarianceType["ABSOLUTE"] = "d";
2469
- VarianceType["NONE"] = "";
2470
- })(VarianceType || (VarianceType = {}));
2471
- /**
2472
- * Orchestrates the full rendering pipeline for an IBCS time series chart.
2473
- *
2474
- * Rendering pipeline (in draw()):
2475
- * 1. Clears the SVG container
2476
- * 2. Routes to the appropriate drawing method based on chart type:
2477
- * - Variance chart: drawVarianceScenario() for absolute/relative variance bars
2478
- * - Stacked chart: drawStackedScenarios() or drawStackedAreaScenarios() (line mode)
2479
- * - Standard chart: drawScenarios() (bar mode) or drawLineScenarios() (line mode)
2480
- * 3. Draws axis baseline + date labels via drawAxisAndLabels()
2481
- *
2482
- * Data pipeline (in setConfig()):
2483
- * 1. Raw data is filtered via AlaSQL (optional WHERE clause)
2484
- * 2. Dates are normalized to the configured interval (day/week/month/quarter/year)
2485
- * 3. Scenarios are aggregated per date bucket (SUM with operation sign)
2486
- * 4. Missing date buckets are filled via leftOuterJoinDates()
2487
- * 5. Variance model is computed from base/delta scenario pairs
2488
- * 6. Min/max DataPoints are found for coordinate system sizing
2489
- *
2490
- * Auto chart mode: when dataModel.length exceeds maxBars, switches from bar to line.
2491
- */
2492
- class TimeChart {
2493
- constructor(ruleSet, config, styles, availableWidth = 0) {
2494
- this.CSS_CATEGORIES = "categories";
2495
- this.dataModel = [];
2496
- this.variancesDataModel = [];
2497
- this.title = "";
2498
- this.smallestDataPointValue = new DataPoint(0, Scenario.AC1, 1, Scenario.NEU);
2499
- this.highestDataPointValue = new DataPoint(0, Scenario.AC1, 1, Scenario.NEU);
2500
- this.smallestVarianceDataPointValue = new DataPoint(0, Scenario.AC1, 1, Scenario.NEU);
2501
- this.highestVarianceDataPointValue = new DataPoint(0, Scenario.AC1, 1, Scenario.NEU);
2502
- this.pixelPerUnit = 1;
2503
- this.pixelPerPercentage = 1;
2504
- this.hideAxisLabels = false;
2505
- this.axisScenario = Scenario.AC1;
2506
- this.preparedDataSet = [];
2507
- this.axisCategoryArea = { width: 0, height: 0 };
2508
- this.scenariosArea = { width: 0, height: 0 };
2509
- this.state = FactoryState.DIRTY;
2510
- this.i18n = new Map();
2511
- this.leftSideOffsetForHorizontalSync = -1;
2512
- this.dateInterval = DateDistance.DAY;
2513
- this.locale = "de";
2514
- this.axisLabelsMode = AxisLabelsMode.SMART;
2515
- this.intervalSpanLimit = 32;
2516
- this.measureScale = new SiPrefix();
2517
- this.measureUnit = "";
2518
- this.dataFormatDigits = { percent: 2, decimal: 1 };
2519
- this.showOverlayMedian = false;
2520
- this.showOverlayAvg = false;
2521
- this.chartMode = ChartMode.BAR;
2522
- this.maxBars = 28;
2523
- this.stackConfig = null;
2524
- this.lineFullWidth = true;
2525
- this.availableWidth = 0;
2526
- this.overflowConfig = null;
2527
- this.lastScenarios = [];
2528
- this.initSQLFunctions();
2529
- this.ruleSet = ruleSet || new IBCSRuleSet();
2530
- this.i18n = this.createI18n(new Map());
2531
- this.styles = styles;
2532
- this.availableWidth = availableWidth;
2533
- this.setConfig(config);
2534
- this.position = this.createElementPosition(config.scenarios);
2535
- }
2536
- updatePosition(scenarios) {
2537
- this.position = this.createElementPosition(scenarios);
2538
- }
2539
- initSQLFunctions() {
2540
- alasql.fn.transformOperator = function (a) {
2541
- return a === "-" ? -1 : 1;
2542
- };
2543
- // @ts-ignore
2544
- alasql.fn.normalizeDate = function (date, normalizationLevel, _locale) {
2545
- if (date === undefined || !date.isValid) {
2546
- return undefined;
2547
- }
2548
- return date.startOf(normalizationLevel);
2549
- };
2550
- }
2551
- setStyles(newStyle) {
2552
- this.styles = newStyle;
2553
- }
2554
- setAvailableWidth(w) {
2555
- this.availableWidth = w;
2556
- }
2557
- setAvailableHeight(availableHeight) {
2558
- // Only apply overdrive for manual scaling in bar mode
2559
- if (this.pixelPerUnit <= 0 || availableHeight <= 0) {
2560
- this.overflowConfig = null;
2561
- return;
2562
- }
2563
- if (this.stackConfig != null) {
2564
- this.overflowConfig = null;
2565
- return;
2566
- }
2567
- const effectiveMode = this.determineEffectiveChartMode();
2568
- if (effectiveMode !== ChartMode.BAR) {
2569
- this.overflowConfig = null;
2570
- return;
2571
- }
2572
- this.overflowConfig = this.calculateOverflowConfig(availableHeight);
2573
- // Rebuild position with virtual max so the coordinate system fits the container
2574
- if (this.overflowConfig) {
2575
- this.updatePosition(this.lastScenarios);
2576
- }
2577
- }
2578
- calculateOverflowConfig(availableHeight) {
2579
- const highest = this.isVarianceChart() ? this.highestVarianceDataPointValue : this.highestDataPointValue;
2580
- const highestScaledUnit = highest.getScaledUnit();
2581
- if (highestScaledUnit <= 0)
2582
- return null;
2583
- const fontSize = this.styles.fontStyles.size;
2584
- // Non-bar overhead: everything except the bars themselves (labels, axis, padding)
2585
- const nonBarOverhead = this.position.dataLabelHeight +
2586
- this.position.spacings.labelToColumn +
2587
- this.position.padding.top +
2588
- this.position.padding.bottom +
2589
- this.position.spacings.labelToAxis +
2590
- fontSize; // axis labels approximate height
2591
- const overdriveZoneHeight = fontSize * 1.5;
2592
- const breakGap = fontSize * 0.3;
2593
- const cutHeight = availableHeight - nonBarOverhead - overdriveZoneHeight - breakGap;
2594
- // Non-AC scenarios break lower than AC by this offset
2595
- const scenarioCutOffset = fontSize * 0.8;
2596
- if (cutHeight <= scenarioCutOffset)
2597
- return null;
2598
- // Use the lower (non-AC) cut height for overflow detection threshold
2599
- const lowestCutHeight = cutHeight - scenarioCutOffset;
2600
- // No bar exceeds even the lowest cut height → no overflow needed
2601
- if (highestScaledUnit <= lowestCutHeight)
2602
- return null;
2603
- // maxOverflow based on lowest cut height so no bar exceeds overdriveZoneHeight
2604
- const maxOverflow = highestScaledUnit - lowestCutHeight;
2605
- return {
2606
- cutHeight,
2607
- overdriveZoneHeight,
2608
- breakGap,
2609
- maxOverflow,
2610
- scenarioCutOffset,
2611
- };
2612
- }
2613
- setConfig(config) {
2614
- var _a;
2615
- this.state = FactoryState.DIRTY;
2616
- this.sortScenariosbyVisualisationRules(config);
2617
- this.setData([...config.data], config.filter);
2618
- this.hideAxisLabels = config.hideAxisLabels || false;
2619
- this.pixelPerUnit = config.pixelPerUnit;
2620
- this.pixelPerPercentage = config.pixelPerPercentage;
2621
- this.axisLabelsMode = config.axisLabelsMode;
2622
- this.intervalSpanLimit = config.intervalSpanLimit;
2623
- this.dateInterval = this.findDateInterval(config.dateInterval);
2624
- this.dataModel = this.populateModel(config.scenarios, this.dateInterval, config.level, config.sortOrder);
2625
- this.variancesDataModel = this.populateVarianceModel(config.variances, this.dataModel);
2626
- this.title = config.title || Formatter.translateScenarioLabel((_a = config === null || config === void 0 ? void 0 : config.variances) === null || _a === void 0 ? void 0 : _a.toString(), this.i18n);
2627
- this.smallestDataPointValue = this.findSmallestDataPointValue(this.dataModel);
2628
- this.smallestVarianceDataPointValue = this.findSmallestDataPointValue(this.variancesDataModel);
2629
- this.highestDataPointValue = this.findHighestDataPointValue(this.dataModel);
2630
- this.highestVarianceDataPointValue = this.findHighestDataPointValue(this.variancesDataModel);
2631
- this.axisScenario = this.setAxisScenario(config.variances);
2632
- this.leftSideOffsetForHorizontalSync = config.leftSideOffsetForHorizontalSync;
2633
- this.measureScale = config.measureScale;
2634
- this.measureUnit = config.measureUnit;
2635
- this.dataFormatDigits = config.dataFormatDigits;
2636
- this.showOverlayMedian = config.showOverlayMedian;
2637
- this.showOverlayAvg = config.showOverlayAvg;
2638
- this.chartMode = config.chartMode;
2639
- this.maxBars = config.maxBars;
2640
- this.stackConfig = config.stackConfig;
2641
- this.lineFullWidth = config.lineFullWidth;
2642
- this.lastScenarios = config.scenarios;
2643
- this.updatePosition(config.scenarios);
2644
- }
2645
- getFooter() {
2646
- if (this.measureScale.value === 1 && this.measureUnit === "") {
2647
- return " ";
2648
- }
2649
- return Formatter.translateScenarioLabel("in", this.i18n) + " " + this.measureScale.prefix + this.measureUnit;
2650
- }
2651
- sortScenariosbyVisualisationRules(config) {
2652
- const self = this;
2653
- config.scenarios
2654
- .sort((n1, n2) => {
2655
- return self.ruleSet.getScenarioSorIndex(n1) - self.ruleSet.getScenarioSorIndex(n2);
2656
- })
2657
- .reverse();
2658
- }
2659
- /**
2660
- * Init load of translation dictionary map
2661
- * map is used to translate lables in the table
2662
- *
2663
- * example:
2664
- * ```
2665
- * let i18n: Map<string, string> = new Map();
2666
- * [{key: 'ac',value: 'AC'}].forEach(function(entry){
2667
- * i18n.set(entry.key, entry.value);
2668
- * })
2669
- * ```
2670
- * @param i18n
2671
- */
2672
- setI18n(i18n) {
2673
- this.i18n = this.createI18n(i18n);
2674
- }
2675
- /**
2676
- * Init load raw datasets the loaded dataset is
2677
- * the base on which the filters defined in the config
2678
- * are apllied on internaly it is called prepared DataSet
2679
- *
2680
- * @param data
2681
- * @param filter - data filter
2682
- * @param customColumnNameMap Custon ColumnNameMap can be used if data uses non standard columnames
2683
- */
2684
- setData(data, filter) {
2685
- if (data == null) {
2686
- return;
2687
- }
2688
- this.state = FactoryState.DIRTY; // mark dataSet for update
2689
- this.preparedDataSet.length = 0; // cleans formerly loaded and prepared dataset
2690
- if (filter != null && filter.length > 0) {
2691
- try {
2692
- this.preparedDataSet = alasql(`SELECT * FROM ? WHERE ${filter}`, [data]);
2693
- }
2694
- catch (e) {
2695
- console.error("TimeChart: filter query failed, using unfiltered data", filter, e);
2696
- this.preparedDataSet = data;
2697
- }
2698
- }
2699
- else {
2700
- this.preparedDataSet = data;
2701
- }
2702
- }
2703
- getAllocatedCanvasWidth() {
2704
- // Analytical calculation — doesn't rely on text bbox (unreliable in detached SVGs)
2705
- const axisEnd = this.position.getAxisEndPositionX();
2706
- // Buffer for the last date label extending beyond axis end
2707
- const labelBuffer = this.styles.fontStyles.size * 3;
2708
- // Also consider bbox-based measurement as a fallback (works for rects)
2709
- const bboxWidth = Math.max(this.axisCategoryArea.width, this.scenariosArea.width);
2710
- const bboxTotal = bboxWidth > 0 ? bboxWidth + this.position.leftSideLabelLength : 0;
2711
- return Math.max(axisEnd + labelBuffer, bboxTotal);
2712
- }
2713
- getAllocatedCanvasHeight() {
2714
- if (this.smallestVarianceDataPointValue.value == null ||
2715
- this.highestVarianceDataPointValue.value == null ||
2716
- this.smallestDataPointValue.value == null ||
2717
- this.highestDataPointValue.value == null) {
2718
- return 0;
2719
- }
2720
- // Analytical calculation — doesn't rely on text bbox
2721
- const isRelative = this.isVarianceChart() &&
2722
- this.variancesDataModel.some((e) => e.type === VarianceType.RELATIVE);
2723
- const axisY = this.position.getAxisPositionY(isRelative);
2724
- // Space below axis: gap to date labels + date label height + bottom padding
2725
- const belowAxis = this.position.spacings.labelToAxis + this.position.dataLabelHeight + this.styles.padding.bottom;
2726
- let analyticalHeight;
2727
- if (!this.isOnSameAxisSide()) {
2728
- // Bars extend below axis — account for negative bar + its data label
2729
- const min = this.isVarianceChart() ? this.smallestVarianceDataPointValue : this.smallestDataPointValue;
2730
- const minScaled = Math.abs(min.getScaledUnit());
2731
- analyticalHeight =
2732
- axisY + minScaled + this.position.spacings.labelToColumn + this.position.dataLabelHeight + belowAxis;
2733
- }
2734
- else {
2735
- analyticalHeight = axisY + belowAxis;
2736
- }
2737
- // Also consider bbox-based measurement as a fallback
2738
- const isOnSameAxisSide = this.isOnSameAxisSide();
2739
- const bboxHeight = isOnSameAxisSide
2740
- ? this.axisCategoryArea.height + this.scenariosArea.height
2741
- : this.scenariosArea.height;
2742
- return Math.max(analyticalHeight, bboxHeight);
2743
- }
2744
- toString() {
2745
- const container = new Svg();
2746
- this.draw(container);
2747
- container.id("drawCanvas");
2748
- container.width(this.getAllocatedCanvasWidth());
2749
- container.height(this.getAllocatedCanvasHeight());
2750
- container.attr("overflow", "visible");
2751
- return container.svg();
2752
- }
2753
- draw(svgContainer) {
2754
- this.cleanSVGforRedraw(svgContainer);
2755
- if (this.state === FactoryState.DIRTY) {
2756
- this.state = FactoryState.UP_TO_DATE;
2757
- }
2758
- if (this.isVarianceChart()) {
2759
- this.drawVarianceScenario(this.variancesDataModel, svgContainer);
2760
- this.drawAxisAndLabels(this.variancesDataModel, svgContainer);
2761
- }
2762
- else if (this.stackConfig != null) {
2763
- const effectiveChartMode = this.determineEffectiveChartMode();
2764
- if (effectiveChartMode === ChartMode.LINE) {
2765
- this.drawStackedAreaScenarios(this.dataModel, svgContainer);
2766
- this.drawAxisAndLabelsForLineChart(this.dataModel, svgContainer);
2767
- }
2768
- else {
2769
- this.drawStackedScenarios(this.dataModel, svgContainer);
2770
- this.drawStackedHeaders(this.dataModel, svgContainer);
2771
- this.drawAxisAndLabels(this.dataModel, svgContainer);
2772
- }
2773
- }
2774
- else {
2775
- const effectiveChartMode = this.determineEffectiveChartMode();
2776
- if (effectiveChartMode === ChartMode.LINE) {
2777
- this.drawLineScenarios(this.dataModel, svgContainer);
2778
- this.drawAxisAndLabelsForLineChart(this.dataModel, svgContainer);
2779
- }
2780
- else {
2781
- this.drawScenarios(this.dataModel, svgContainer);
2782
- this.drawOverlayLayer(this.dataModel, svgContainer);
2783
- this.drawAxisAndLabels(this.dataModel, svgContainer);
2784
- }
2785
- }
2786
- }
2787
- determineEffectiveChartMode() {
2788
- if (this.chartMode === ChartMode.LINE) {
2789
- return ChartMode.LINE;
2790
- }
2791
- if (this.chartMode === ChartMode.AUTO) {
2792
- // Auto-switch to line mode when data points exceed maxBars threshold
2793
- if (this.dataModel.length > this.maxBars) {
2794
- return ChartMode.LINE;
2795
- }
2796
- }
2797
- return ChartMode.BAR;
2798
- }
2799
- setPattern(fc, fcPolygonPattern) {
2800
- this.styles.pattern.set(fc, fcPolygonPattern);
2801
- }
2802
- hasNoData() {
2803
- return this.dataModel.length === 0;
2804
- }
2805
- isOnSameAxisSide() {
2806
- if (this.smallestVarianceDataPointValue.value == null ||
2807
- this.highestVarianceDataPointValue.value == null ||
2808
- this.smallestDataPointValue.value == null ||
2809
- this.highestDataPointValue.value == null) {
2810
- return false;
2811
- }
2812
- if (this.isVarianceChart()) {
2813
- return (Math.sign(this.smallestVarianceDataPointValue.value) === Math.sign(this.highestVarianceDataPointValue.value) ||
2814
- (this.smallestDataPointValue.value === 0 && Math.sign(this.highestDataPointValue.value) === 1));
2815
- }
2816
- else {
2817
- return (Math.sign(this.smallestDataPointValue.value) === Math.sign(this.highestDataPointValue.value) ||
2818
- (this.smallestDataPointValue.value === 0 && Math.sign(this.highestDataPointValue.value) === 1));
2819
- }
2820
- }
2821
- createI18n(i18n) {
2822
- this.state = FactoryState.DIRTY;
2823
- const defaultI18n = new Map([
2824
- ["SEPERATOR_WS", ", "],
2825
- ["in", "in"],
2826
- ["ORDER_asc", "↑"],
2827
- ["ORDER_desc", "↓"],
2828
- ["ac1", "AC"],
2829
- ["pp1", "PY"],
2830
- ["fc1", "FC"],
2831
- ["pl1", "PL"],
2832
- ["ac2", "AC2"],
2833
- ["pp2", "PY2"],
2834
- ["fc2", "FC2"],
2835
- ["pl2", "PL2"],
2836
- ["ac3", "AC3"],
2837
- ["pp3", "PY3"],
2838
- ["fc3", "FC3"],
2839
- ["pl3", "PL3"],
2840
- ["ac4", "AC4"],
2841
- ["pp4", "PY4"],
2842
- ["fc4", "FC4"],
2843
- ["pl4", "PL4"],
2844
- ["category", " "],
2845
- ["operation", " "],
2846
- ["there_of", "davon"],
2847
- ["part_of", "in % von"],
2848
- ["ibcssymbol_delta_ac", "Δ{%}"],
2849
- ["ibcssymbol_delta_generic", "Δ({%})"],
2850
- ["ibcssymbol_delta_ac_relative", "Δ{%}%"],
2851
- ["ibcssymbol_delta_generic_relative", "Δ({%})%"],
2852
- ["SUM_TOTAL", "❖"],
2853
- ]);
2854
- return new Map([...defaultI18n, ...i18n]);
2855
- }
2856
- createElementPosition(scenarios) {
2857
- let maxLabelLengthLeft;
2858
- // only need scenarios written on the leftside of bar/ marker
2859
- const scenarioLabelLeft = CalculateSize(scenarios
2860
- .filter((_value, index) => index === 1 || index === 2)
2861
- .map((scenario) => Formatter.translateScenarioLabel(scenario, this.i18n))
2862
- .reduce((a, b) => (a.length < b.length ? b : a), ""), {
2863
- font: this.styles.fontStyles.font,
2864
- fontSize: this.styles.fontStyles.size + "px",
2865
- }).width;
2866
- const titleLength = this.calculateTitleLength(this.leftSideOffsetForHorizontalSync);
2867
- if (scenarioLabelLeft > titleLength) {
2868
- maxLabelLengthLeft = scenarioLabelLeft;
2869
- }
2870
- else {
2871
- maxLabelLengthLeft = titleLength;
2872
- }
2873
- if (this.position != null) {
2874
- maxLabelLengthLeft = maxLabelLengthLeft + this.position.spacings.labelToColumn;
2875
- }
2876
- //if (maxLabelLengthLeft < this.leftSideOffsetForHorizontalSync) {
2877
- // maxLabelLengthLeft = this.leftSideOffsetForHorizontalSync;
2878
- //}
2879
- if (this.leftSideOffsetForHorizontalSync > -1) {
2880
- maxLabelLengthLeft = this.leftSideOffsetForHorizontalSync;
2881
- }
2882
- let min;
2883
- let max;
2884
- if (this.isVarianceChart()) {
2885
- min = this.smallestVarianceDataPointValue;
2886
- max = this.highestVarianceDataPointValue;
2887
- }
2888
- else {
2889
- min = this.smallestDataPointValue;
2890
- max = this.highestDataPointValue;
2891
- }
2892
- // When overflow config is active, create a virtual max so the coordinate system
2893
- // allocates exactly cutHeight + breakGap + overdriveZoneHeight instead of the
2894
- // full (clipped) bar height.
2895
- if (this.overflowConfig) {
2896
- const { cutHeight, overdriveZoneHeight, breakGap } = this.overflowConfig;
2897
- const virtualHeight = cutHeight + overdriveZoneHeight + breakGap;
2898
- // Create a virtual DataPoint with pixelPerUnit=1 so getScaledUnit() returns virtualHeight directly
2899
- max = new DataPoint(virtualHeight, max.scenario, 1, max.variance);
2900
- }
2901
- // In line mode with lineFullWidth enabled, override categoryWidth so data points
2902
- // are evenly distributed across the available container width.
2903
- let effectiveScaleFactors = this.styles.scaleFactors;
2904
- const effectiveMode = this.determineEffectiveChartMode();
2905
- if (this.lineFullWidth &&
2906
- this.availableWidth > 0 &&
2907
- this.dataModel.length > 0 &&
2908
- !this.isVarianceChart() &&
2909
- effectiveMode === ChartMode.LINE) {
2910
- const fontSize = this.styles.fontStyles.size;
2911
- const padding = this.styles.padding;
2912
- const sf = this.styles.scaleFactors;
2913
- // Fixed overhead: padding + scenarioOffset + leftSideLabels + half columnWidth (right margin)
2914
- const fixedOverhead = padding.left + padding.right + fontSize * sf.scenarioOffset + maxLabelLengthLeft + fontSize * sf.columnWidth;
2915
- const availableDataWidth = this.availableWidth - fixedOverhead;
2916
- if (availableDataWidth > 0) {
2917
- const customCategoryWidthFactor = availableDataWidth / this.dataModel.length / fontSize;
2918
- // Enforce minimum to prevent label overlap
2919
- const minFactor = sf.columnWidth * 1.2;
2920
- const finalFactor = Math.max(customCategoryWidthFactor, minFactor);
2921
- // Clone scaleFactors with overridden categoryWidth
2922
- const cloned = new ScaleFactorsTimeChart();
2923
- Object.assign(cloned, sf);
2924
- cloned.categoryWidth = finalFactor;
2925
- effectiveScaleFactors = cloned;
2926
- }
2927
- }
2928
- return new ElementPositions(new Padding(this.styles.padding), effectiveScaleFactors, this.styles.fontStyles, min, max, this.dataModel.length, maxLabelLengthLeft);
2929
- }
2930
- calculateTitleLength(minWidth) {
2931
- let tmpTitle = "_______"; // default width if this.title is sorther
2932
- if (tmpTitle.length < this.title.length) {
2933
- tmpTitle = this.title;
2934
- }
2935
- const width = CalculateSize(tmpTitle, {
2936
- font: this.styles.fontStyles.font,
2937
- fontSize: this.styles.fontStyles.size + "px",
2938
- }).width;
2939
- if (width < minWidth) {
2940
- return minWidth;
2941
- }
2942
- return width;
2943
- }
2944
- setAxisScenario(scenarios) {
2945
- let result = Scenario.AC1;
2946
- if (scenarios != null && scenarios.length > 0) {
2947
- const axis = new VarianceScenario(scenarios.toString());
2948
- if (axis.isValid) {
2949
- result = axis.delta;
2950
- }
2951
- }
2952
- if (result === null) {
2953
- // arrays with invalid scenarios are set to Senario.AC Fallback
2954
- result = Scenario.AC1;
2955
- }
2956
- return result;
2957
- }
2958
- populateModel(selectedScenarios, dateInterval, _level, _sortOrder) {
2959
- var _a;
2960
- if (((_a = this.preparedDataSet) === null || _a === void 0 ? void 0 : _a.length) === 0) {
2961
- return [];
2962
- }
2963
- const select = ``;
2964
- const order = "";
2965
- let result = this.queryDataSet(dateInterval, select, order);
2966
- this.detectNaNCells(selectedScenarios, result);
2967
- result = this.leftOuterJoinDates(result, dateInterval);
2968
- const dataModel = this.createDataRows(result, selectedScenarios);
2969
- return dataModel;
2970
- }
2971
- detectNaNCells(scenarios, res) {
2972
- res.forEach((row) => {
2973
- scenarios.forEach((scenario) => {
2974
- const varianceScenario = new VarianceScenario(scenario);
2975
- if (varianceScenario.isValid === true) {
2976
- if (row[varianceScenario.base + "_cnt"] === 0 || row[varianceScenario.delta + "_cnt"] === 0) {
2977
- row[scenario] = Number.NaN;
2978
- }
2979
- }
2980
- else {
2981
- if (row[scenario + "_cnt"] === 0) {
2982
- row[scenario] = Number.NaN;
2983
- }
2984
- }
2985
- });
2986
- return row;
2987
- });
2988
- }
2989
- findDateInterval(dateInterval) {
2990
- var _a, _b, _c;
2991
- if (dateInterval !== DateDistance.AUTO) {
2992
- return dateInterval;
2993
- }
2994
- const resultMinMax = this.queryMinMaxDates();
2995
- let localDateInterval = DateDistance.DAY;
2996
- if (((_a = resultMinMax[0]) === null || _a === void 0 ? void 0 : _a.mindate) != null) {
2997
- localDateInterval = new DateStringFactory().calculateDistanceType((_b = resultMinMax[0]) === null || _b === void 0 ? void 0 : _b.mindate, (_c = resultMinMax[0]) === null || _c === void 0 ? void 0 : _c.maxdate, this.intervalSpanLimit);
2998
- }
2999
- return localDateInterval;
3000
- }
3001
- queryMinMaxDates() {
3002
- var _a, _b, _c, _d;
3003
- //let result: any[] = [];
3004
- const result = alasql(`SELECT MAX(${"date"}) as maxdate, MIN(${"date"}) as mindate FROM ?`, [this.preparedDataSet]);
3005
- if (((_a = result[0]) === null || _a === void 0 ? void 0 : _a.mindate) != null) {
3006
- result[0].mindate = DateTime.fromMillis((_b = result[0]) === null || _b === void 0 ? void 0 : _b.mindate);
3007
- }
3008
- if (((_c = result[0]) === null || _c === void 0 ? void 0 : _c.maxdate) != null) {
3009
- result[0].maxdate = DateTime.fromMillis((_d = result[0]) === null || _d === void 0 ? void 0 : _d.maxdate);
3010
- }
3011
- return result;
3012
- }
3013
- queryDataSet(dateInterval, select, order) {
3014
- const scenarios = [
3015
- "ac1",
3016
- "ac2",
3017
- "ac3",
3018
- "ac4",
3019
- "pp1",
3020
- "pp2",
3021
- "pp3",
3022
- "pp4",
3023
- "fc1",
3024
- "fc2",
3025
- "fc3",
3026
- "fc4",
3027
- "pl1",
3028
- "pl2",
3029
- "pl3",
3030
- "pl4",
3031
- ];
3032
- const dateSelect = `normalizeDate([date], '${dateInterval}' , '${this.locale}') as calcdate`;
3033
- const result = alasql(`SELECT ${"p.calcdate"} ${select},
3034
- ${scenarios
3035
- .map((scenario) => {
3036
- return `SUM(${scenario} * transformOperator(operation)) as ${scenario}, COUNT(ISNULL(${scenario})) as ${scenario}_cnt`;
3037
- })
3038
- .join(",")}
3039
-
3040
- FROM (SELECT ${dateSelect} ${select},
3041
- ac1,
3042
- ac2,
3043
- ac3,
3044
- ac4,
3045
- pp1,
3046
- pp2,
3047
- pp3,
3048
- pp4,
3049
- fc1,
3050
- fc2,
3051
- fc3,
3052
- fc4,
3053
- pl1,
3054
- pl2,
3055
- pl3,
3056
- pl4
3057
- FROM ?) as p
3058
- GROUP BY ${"calcdate"} ${order}
3059
- ORDER BY ${"calcdate asc"}`, [this.preparedDataSet]);
3060
- return result;
3061
- }
3062
- createDataRows(result, selectedScenarios) {
3063
- const dataModel = [];
3064
- result.forEach((element, index) => {
3065
- dataModel.push({
3066
- id: index,
3067
- category: element.category,
3068
- type: VarianceType.NONE,
3069
- date: element["calcdate"],
3070
- scenario1: new DataPoint(element[selectedScenarios[0]], selectedScenarios[0], this.pixelPerUnit, Scenario.NEU),
3071
- scenario2: new DataPoint(element[selectedScenarios[1]], selectedScenarios[1], this.pixelPerUnit, Scenario.NEU),
3072
- scenario3: new DataPoint(element[selectedScenarios[2]], selectedScenarios[2], this.pixelPerUnit, Scenario.NEU),
3073
- scenario4: new DataPoint(element[selectedScenarios[3]], selectedScenarios[3], this.pixelPerUnit, Scenario.NEU),
3074
- });
3075
- //}
3076
- });
3077
- return dataModel;
3078
- }
3079
- findSmallestDataPointValue(dataModel) {
3080
- const pixel = this.isVarianceChart() ? this.pixelPerPercentage : this.pixelPerUnit;
3081
- let smallestDataPoint = new DataPoint(0, "default", pixel, Scenario.NEU);
3082
- for (const entry of dataModel) {
3083
- for (const current of [entry.scenario1, entry.scenario2, entry.scenario3, entry.scenario4]) {
3084
- if (current && current.value != null) {
3085
- if (current.value < Number(smallestDataPoint.value)) {
3086
- smallestDataPoint = current;
3087
- }
3088
- }
3089
- }
3090
- }
3091
- return smallestDataPoint;
3092
- }
3093
- findHighestDataPointValue(dataModel) {
3094
- const pixel = this.isVarianceChart() ? this.pixelPerPercentage : this.pixelPerUnit;
3095
- let highestDataPoint = new DataPoint(0, "default", pixel, Scenario.NEU);
3096
- for (const entry of dataModel) {
3097
- for (const current of [entry.scenario1, entry.scenario2, entry.scenario3, entry.scenario4]) {
3098
- if (current != null) {
3099
- if (current.value > Number(highestDataPoint.value)) {
3100
- highestDataPoint = current;
3101
- }
3102
- }
3103
- }
3104
- }
3105
- return highestDataPoint;
3106
- }
3107
- populateVarianceModel(variancesConfig, dataModel) {
3108
- const varianceModel = [];
3109
- if (variancesConfig == null || variancesConfig.length === 0) {
3110
- return varianceModel;
3111
- }
3112
- let firstRow = null;
3113
- if (dataModel != null && dataModel.length > 0) {
3114
- firstRow = dataModel[0];
3115
- }
3116
- for (const varianceScenario in variancesConfig) {
3117
- const scenarios = new VarianceScenario(variancesConfig[varianceScenario]);
3118
- if (scenarios.isValid) {
3119
- const scenariomap = this.mapScenarios(scenarios, firstRow);
3120
- const directon = scenarios.direction;
3121
- const pixelPerUnit = scenarios.type === "dr" ? this.pixelPerPercentage : this.pixelPerUnit;
3122
- for (const index in dataModel) {
3123
- varianceModel.push({
3124
- id: Number(index),
3125
- category: dataModel[index].category,
3126
- type: scenarios.type === "dr" ? VarianceType.RELATIVE : VarianceType.ABSOLUTE,
3127
- date: dataModel[index].date,
3128
- scenario1: new DataPoint(this.calculateVariance(scenarios, dataModel[index], scenariomap), scenarios.delta, pixelPerUnit, directon),
3129
- scenario2: new DataPoint(null, null, null, null),
3130
- scenario3: new DataPoint(null, null, null, null),
3131
- scenario4: new DataPoint(null, null, null, null),
3132
- });
3133
- }
3134
- }
3135
- }
3136
- return varianceModel;
3137
- }
3138
- calculateVariance(scenarios, element, scenarioMap) {
3139
- const scenarioBase = scenarioMap.get(scenarios.base);
3140
- const scenarioDelta = scenarioMap.get(scenarios.delta);
3141
- if (scenarioBase == null || scenarioDelta == null) {
3142
- return null;
3143
- }
3144
- if (element[scenarioBase].value == null || element[scenarioDelta].value == null) {
3145
- return null;
3146
- }
3147
- const isRelativeVariance = scenarios.type === VarianceType.RELATIVE;
3148
- if (isRelativeVariance) {
3149
- return (element[scenarioBase].value - element[scenarioDelta].value) / element[scenarioDelta].value;
3150
- }
3151
- else {
3152
- return element[scenarioBase].value - element[scenarioDelta].value;
3153
- }
3154
- }
3155
- mapScenarios(scenarios, firstRow) {
3156
- const varianceMap = new Map();
3157
- if (firstRow == null) {
3158
- return varianceMap;
3159
- }
3160
- ["scenario1", "scenario2", "scenario3", "scenario4"].forEach((scenarioKey) => {
3161
- if (firstRow[scenarioKey].scenario === scenarios.delta) {
3162
- varianceMap.set(scenarios.delta, scenarioKey);
3163
- }
3164
- else if (firstRow[scenarioKey].scenario === scenarios.base) {
3165
- varianceMap.set(scenarios.base, scenarioKey);
3166
- }
3167
- });
3168
- return varianceMap;
3169
- }
3170
- cleanSVGforRedraw(svgContainer) {
3171
- svgContainer.clear();
3172
- }
3173
- isVarianceChart() {
3174
- return this.variancesDataModel && this.variancesDataModel.length > 0;
3175
- }
3176
- createDateFactory() {
3177
- const factory = new DateStringFactory();
3178
- return factory;
3179
- }
3180
- drawAxisAndLabels(dataModel, svgContainer) {
3181
- const dateStringFactory = this.createDateFactory();
3182
- const axisLabelGroup = svgContainer.group().id("AxisAndDateLables");
3183
- let isRelative = false;
3184
- if (this.hideAxisLabels === false) {
3185
- dataModel.forEach((elements, index) => {
3186
- let hookLocation = HookLocation.Top;
3187
- let offset = this.position.spacings.labelToAxis;
3188
- if (elements["scenario1"]["value"] < 0) {
3189
- hookLocation = HookLocation.Bottom;
3190
- offset *= -1;
3191
- }
3192
- if (elements["type"] === VarianceType.RELATIVE) {
3193
- isRelative = true;
3194
- }
3195
- let datelabel = dateStringFactory.getDateString(elements.date, this.dateInterval);
3196
- if (this.axisLabelsMode === AxisLabelsMode.SMART) {
3197
- datelabel = dateStringFactory.getSmartDateString(elements.date, this.dateInterval);
3198
- if (index === 0 && this.dateInterval !== DateDistance.YEAR) {
3199
- datelabel = dateStringFactory.getShortDateString(elements.date, this.dateInterval);
3200
- }
3201
- }
3202
- else if (this.axisLabelsMode === AxisLabelsMode.SHORT) {
3203
- datelabel = dateStringFactory.getShortDateString(elements.date, this.dateInterval);
3204
- }
3205
- new Label(axisLabelGroup, this.position.getColumnCenterPositionX(index), this.position.getAxisPositionY(isRelative) + offset, "", datelabel, this.styles, hookLocation, HookLocation.Center).forceStringTypeDraw();
3206
- });
3207
- }
3208
- else {
3209
- const element = dataModel === null || dataModel === void 0 ? void 0 : dataModel[0];
3210
- if (element && element["type"] === VarianceType.RELATIVE) {
3211
- isRelative = true;
3212
- }
3213
- }
3214
- new Axis({
3215
- scenarioType: this.axisScenario,
3216
- labelText: this.title,
3217
- isRelative: isRelative,
3218
- }, this.position, axisLabelGroup).draw();
3219
- this.axisCategoryArea = {
3220
- height: axisLabelGroup.height(),
3221
- width: axisLabelGroup.width(),
3222
- };
3223
- }
3224
- drawScenarios(dataModel, svgContainer) {
3225
- const columnGroup = svgContainer.group().id("Scenarios");
3226
- const scenarioFactory = new ScenarioFactory(this.position, columnGroup, this.styles, dataModel.length, this.i18n);
3227
- scenarioFactory.setOverflowConfig(this.overflowConfig);
3228
- let hasValidPrim = false;
3229
- dataModel.forEach((elements, index) => {
3230
- scenarioFactory.createPrimaryBar(elements["scenario1"], index).draw(this.dataFormatDigits, this.measureScale);
3231
- scenarioFactory.createSecondaryBar(elements["scenario2"], index).draw();
3232
- scenarioFactory.createPrimaryMarker(elements["scenario3"], index).draw();
3233
- scenarioFactory.createSecondaryMarker(elements["scenario4"], index).draw();
3234
- if (elements["scenario1"].isEmpty() === false) {
3235
- hasValidPrim = true;
3236
- }
3237
- });
3238
- let heightOffset = 0;
3239
- if (hasValidPrim === false) {
3240
- if (this.isOnSameAxisSide()) {
3241
- heightOffset = this.position.dataLabelHeight;
3242
- }
3243
- else {
3244
- heightOffset = this.position.dataLabelHeight * 2;
3245
- }
3246
- }
3247
- this.scenariosArea = {
3248
- height: columnGroup.height() + this.styles.padding.top + this.styles.padding.bottom + heightOffset,
3249
- width: columnGroup.width() + this.position.spacings.columnWidth,
3250
- };
3251
- }
3252
- drawLineScenarios(dataModel, svgContainer) {
3253
- var _a, _b;
3254
- const lineGroup = svgContainer.group().id("LineScenarios");
3255
- // Create collision manager for label overlap detection across all line series
3256
- const collisionManager = new LabelCollisionManager();
3257
- const scenarioFactory = new ScenarioFactory(this.position, lineGroup, this.styles, dataModel.length, this.i18n);
3258
- scenarioFactory.setCollisionManager(collisionManager);
3259
- // Collect data points for each scenario
3260
- const slotDefaults = ["ac1", "pp1", "fc1", "pl1"];
3261
- const slotPoints = [[], [], [], []];
3262
- dataModel.forEach((elements, index) => {
3263
- const keys = ["scenario1", "scenario2", "scenario3", "scenario4"];
3264
- keys.forEach((key, slotIdx) => {
3265
- if (elements[key]) {
3266
- slotPoints[slotIdx].push({ dataPoint: elements[key], index });
3267
- }
3268
- });
3269
- });
3270
- // Build scenario info (only non-empty scenarios)
3271
- const scenarios = [];
3272
- for (let i = 0; i < slotPoints.length; i++) {
3273
- const points = slotPoints[i];
3274
- if (points.length > 0 && points.some((p) => !p.dataPoint.isEmpty())) {
3275
- const scenarioName = ((_b = (_a = points[0]) === null || _a === void 0 ? void 0 : _a.dataPoint) === null || _b === void 0 ? void 0 : _b.scenario) || slotDefaults[i];
3276
- const scenarioType = scenarioName.slice(0, 2).toLowerCase();
3277
- scenarios.push({ points, scenarioName, scenarioType });
3278
- }
3279
- }
3280
- // Sort by z-order: lowest priority first so SVG groups are created in correct render order
3281
- // PL(4) → FC(3) → PP(2) → AC(1) — AC geometry on top of PP geometry
3282
- scenarios.sort((a, b) => {
3283
- const pa = SCENARIO_PRIORITY[a.scenarioType] || 99;
3284
- const pb = SCENARIO_PRIORITY[b.scenarioType] || 99;
3285
- return pb - pa;
3286
- });
3287
- // Create LineSeries in z-order (SVG group creation order = render order)
3288
- const seriesList = [];
3289
- for (const scenario of scenarios) {
3290
- const series = scenarioFactory.createLineSeries(scenario.points, scenario.scenarioName);
3291
- seriesList.push({ series, scenarioType: scenario.scenarioType });
3292
- }
3293
- // Phase 1: Draw geometry (groups already in correct z-order from creation)
3294
- for (const entry of seriesList) {
3295
- entry.series.drawGeometry();
3296
- }
3297
- // Move label group to front so labels render on top of all lines/markers
3298
- scenarioFactory.moveLabelsToFront();
3299
- // Phase 2: Draw labels in priority order (highest priority first)
3300
- // AC(1) → PP(2) → FC(3) → PL(4) so AC claims best label positions first
3301
- const labelOrder = [...seriesList].sort((a, b) => {
3302
- const pa = SCENARIO_PRIORITY[a.scenarioType] || 99;
3303
- const pb = SCENARIO_PRIORITY[b.scenarioType] || 99;
3304
- return pa - pb; // lowest priority number first (AC first)
3305
- });
3306
- for (const entry of labelOrder) {
3307
- entry.series.drawLabels(this.dataFormatDigits, this.measureScale);
3308
- }
3309
- // In line mode the lines only span between data points (all above the axis),
3310
- // so lineGroup.height() does not extend to the axis like bar rects do.
3311
- // Use getColumnPositionY() (the axis baseline) as the minimum height
3312
- // so that axis date labels drawn below are not cut off.
3313
- const axisY = this.position.getColumnPositionY();
3314
- this.scenariosArea = {
3315
- height: Math.max(lineGroup.height() + this.styles.padding.top, axisY) + this.styles.padding.bottom,
3316
- width: lineGroup.width() + this.position.spacings.columnWidth,
3317
- };
3318
- }
3319
- drawAxisAndLabelsForLineChart(dataModel, svgContainer) {
3320
- const dateStringFactory = this.createDateFactory();
3321
- const axisLabelGroup = svgContainer.group().id("AxisAndDateLabelsLine");
3322
- const isRelative = false;
3323
- const lastIndex = dataModel.length - 1;
3324
- if (this.hideAxisLabels === false) {
3325
- dataModel.forEach((elements, index) => {
3326
- // Only show labels for first, last, and year change points
3327
- if (!this.shouldShowLineChartAxisLabel(dataModel, index)) {
3328
- return;
3329
- }
3330
- let hookLocation = HookLocation.Top;
3331
- let offset = this.position.spacings.labelToAxis;
3332
- if (elements["scenario1"]["value"] < 0) {
3333
- hookLocation = HookLocation.Bottom;
3334
- offset *= -1;
3335
- }
3336
- // Get the date label — use smart/short logic when full-width shows all labels
3337
- let datelabel;
3338
- if (this.lineFullWidth && this.availableWidth > 0) {
3339
- if (this.axisLabelsMode === AxisLabelsMode.SMART) {
3340
- datelabel = dateStringFactory.getSmartDateString(elements.date, this.dateInterval);
3341
- if (index === 0 && this.dateInterval !== DateDistance.YEAR) {
3342
- datelabel = dateStringFactory.getShortDateString(elements.date, this.dateInterval);
3343
- }
3344
- }
3345
- else if (this.axisLabelsMode === AxisLabelsMode.SHORT) {
3346
- datelabel = dateStringFactory.getShortDateString(elements.date, this.dateInterval);
3347
- }
3348
- else {
3349
- datelabel = dateStringFactory.getDateString(elements.date, this.dateInterval);
3350
- }
3351
- }
3352
- else {
3353
- datelabel = dateStringFactory.getShortDateString(elements.date, this.dateInterval);
3354
- }
3355
- new Label(axisLabelGroup, this.position.getColumnCenterPositionX(index), this.position.getAxisPositionY(isRelative) + offset, "", datelabel, this.styles, hookLocation, HookLocation.Center).forceStringTypeDraw();
3356
- // Draw vertical dashed separator line at year transitions (except for first and last)
3357
- if (index > 0 && index < lastIndex && this.isYearChange(dataModel, index)) {
3358
- this.drawYearSeparatorLine(axisLabelGroup, index, isRelative);
3359
- }
3360
- });
3361
- }
3362
- new Axis({
3363
- scenarioType: this.axisScenario,
3364
- labelText: this.title,
3365
- isRelative: isRelative,
3366
- }, this.position, axisLabelGroup).draw();
3367
- this.axisCategoryArea = {
3368
- height: axisLabelGroup.height(),
3369
- width: axisLabelGroup.width(),
3370
- };
3371
- }
3372
- shouldShowLineChartAxisLabel(dataModel, index) {
3373
- // In full-width mode, every data point gets a label (enough horizontal space)
3374
- if (this.lineFullWidth && this.availableWidth > 0) {
3375
- return true;
3376
- }
3377
- const lastIndex = dataModel.length - 1;
3378
- // Always show first and last labels
3379
- if (index === 0 || index === lastIndex) {
3380
- return true;
3381
- }
3382
- // Show label if year changed from previous data point
3383
- return this.isYearChange(dataModel, index);
3384
- }
3385
- isYearChange(dataModel, index) {
3386
- var _a, _b;
3387
- if (index === 0) {
3388
- return false;
3389
- }
3390
- const currentDate = (_a = dataModel[index]) === null || _a === void 0 ? void 0 : _a.date;
3391
- const previousDate = (_b = dataModel[index - 1]) === null || _b === void 0 ? void 0 : _b.date;
3392
- if (!currentDate || !previousDate) {
3393
- return false;
3394
- }
3395
- return currentDate.year !== previousDate.year;
3396
- }
3397
- drawYearSeparatorLine(group, index, isRelative) {
3398
- const xPos = this.position.getColumnCenterPositionX(index) - this.position.spacings.columnWidth / 2;
3399
- // Calculate chart height from the max data point
3400
- const chartHeight = this.position.columnValue.max.getScaledUnit() + this.position.dataLabelHeight;
3401
- const topY = this.position.getAxisPositionY(isRelative) - chartHeight;
3402
- const bottomY = this.position.getAxisPositionY(isRelative);
3403
- group
3404
- .line([
3405
- [xPos, topY],
3406
- [xPos, bottomY],
3407
- ])
3408
- .stroke({
3409
- color: "#999999",
3410
- width: 1,
3411
- dasharray: "4,4",
3412
- })
3413
- .attr("stroke-dasharray", "4,4");
3414
- }
3415
- drawVarianceScenario(dataModel, svgContainer) {
3416
- const columnGroup = svgContainer.group().id("Scenarios");
3417
- const scenarioFactory = new ScenarioFactory(this.position, columnGroup, this.styles, dataModel.length, this.i18n);
3418
- scenarioFactory.setOverflowConfig(this.overflowConfig);
3419
- dataModel.forEach((elements, index) => {
3420
- if (elements["type"] === VarianceType.RELATIVE) {
3421
- scenarioFactory.createRelativeVarianceBar(elements["scenario1"], index).draw();
3422
- }
3423
- else {
3424
- scenarioFactory.createVarianceBar(elements["scenario1"], index).draw(this.dataFormatDigits, this.measureScale);
3425
- }
3426
- });
3427
- this.scenariosArea = {
3428
- height: columnGroup.height() + this.styles.padding.top + this.styles.padding.bottom,
3429
- width: columnGroup.width() + this.position.spacings.columnWidth,
3430
- };
3431
- return columnGroup;
3432
- }
3433
- /**
3434
- * Draw stacked bar columns. Supports stacking by scenario or by data dimension.
3435
- * When stacking by scenario with multiple scenario types (e.g. ac+pl),
3436
- * uses overlay mode: each type group is drawn from the same baseline,
3437
- * back-to-front per IBCS convention (PL behind, AC on top).
3438
- */
3439
- drawStackedScenarios(dataModel, svgContainer) {
3440
- if (!this.stackConfig)
3441
- return;
3442
- const stackGroup = svgContainer.group().id("StackedScenarios");
3443
- const isScenarioStack = this.stackConfig.by === StackBy.SCENARIO;
3444
- dataModel.forEach((elements, index) => {
3445
- const scenarioKeys = ["scenario1", "scenario2", "scenario3", "scenario4"];
3446
- const segments = [];
3447
- if (isScenarioStack) {
3448
- for (const key of scenarioKeys) {
3449
- const dp = elements[key];
3450
- if (dp && !dp.isEmpty() && dp.value != null) {
3451
- segments.push({ value: dp.value, scenario: dp.scenario, dataPoint: dp });
3452
- }
3453
- }
3454
- }
3455
- else {
3456
- const dp = elements["scenario1"];
3457
- if (dp && !dp.isEmpty() && dp.value != null) {
3458
- segments.push({ value: dp.value, scenario: dp.scenario, dataPoint: dp });
3459
- }
3460
- }
3461
- if (segments.length === 0)
3462
- return;
3463
- // Check if we have multiple scenario type groups for overlay mode
3464
- const prefixes = isScenarioStack
3465
- ? new Set(segments.map((s) => getScenarioPrefix(s.scenario)))
3466
- : new Set();
3467
- if (prefixes.size > 1) {
3468
- // Overlay mode: group by scenario prefix, draw each group from same baseline
3469
- const groupMap = new Map();
3470
- for (const seg of segments) {
3471
- const prefix = getScenarioPrefix(seg.scenario);
3472
- if (!groupMap.has(prefix))
3473
- groupMap.set(prefix, []);
3474
- groupMap.get(prefix).push(seg);
3475
- }
3476
- const groups = [];
3477
- for (const prefix of IBCS_LAYER_ORDER) {
3478
- if (groupMap.has(prefix)) {
3479
- groups.push({ prefix, segments: groupMap.get(prefix) });
3480
- groupMap.delete(prefix);
3481
- }
3482
- }
3483
- for (const [prefix, segs] of groupMap) {
3484
- groups.push({ prefix, segments: segs });
3485
- }
3486
- // Draw each group from baseline=0 (overlapping)
3487
- groups.forEach((group, groupIdx) => {
3488
- const groupTotal = group.segments.reduce((sum, s) => sum + Math.abs(s.value), 0);
3489
- const colorIndex = groups.length - 1 - groupIdx;
3490
- let cumulativeValue = 0;
3491
- let lastColumn = null;
3492
- group.segments.forEach((seg) => {
3493
- const column = new StackedColumn(this.position, this.styles, seg.dataPoint, index, cumulativeValue, seg.scenario, colorIndex, this.stackConfig.mode, groupTotal, true, stackGroup);
3494
- column.draw(this.dataFormatDigits, this.measureScale);
3495
- cumulativeValue += Math.abs(seg.value);
3496
- lastColumn = column;
3497
- });
3498
- if (lastColumn) {
3499
- lastColumn.drawTotalLabel(this.dataFormatDigits, this.measureScale);
3500
- }
3501
- });
3502
- }
3503
- else {
3504
- // Single group or non-scenario: additive stacking
3505
- if (this.stackConfig.order === "asc") {
3506
- segments.sort((a, b) => a.value - b.value);
3507
- }
3508
- else if (this.stackConfig.order === "desc") {
3509
- segments.sort((a, b) => b.value - a.value);
3510
- }
3511
- const total = segments.reduce((sum, s) => sum + Math.abs(s.value), 0);
3512
- let cumulativeValue = 0;
3513
- let lastColumn = null;
3514
- segments.forEach((seg, segIdx) => {
3515
- const column = new StackedColumn(this.position, this.styles, seg.dataPoint, index, cumulativeValue, seg.scenario, segIdx, this.stackConfig.mode, total, isScenarioStack, stackGroup);
3516
- column.draw(this.dataFormatDigits, this.measureScale);
3517
- cumulativeValue += Math.abs(seg.value);
3518
- lastColumn = column;
3519
- });
3520
- if (lastColumn) {
3521
- lastColumn.drawTotalLabel(this.dataFormatDigits, this.measureScale);
3522
- }
3523
- }
3524
- });
3525
- this.scenariosArea = {
3526
- height: stackGroup.height() + this.styles.padding.top + this.styles.padding.bottom,
3527
- width: stackGroup.width() + this.position.spacings.columnWidth,
3528
- };
3529
- }
3530
- /**
3531
- * Draw column headers next to stacked columns showing what each group/segment represents.
3532
- * For overlay mode (multiple scenario types): shows one header per group.
3533
- * For single-group: shows individual segment headers.
3534
- */
3535
- drawStackedHeaders(dataModel, svgContainer) {
3536
- if (!this.stackConfig || dataModel.length === 0)
3537
- return;
3538
- const isScenarioStack = this.stackConfig.by === StackBy.SCENARIO;
3539
- if (!isScenarioStack)
3540
- return;
3541
- const headerGroup = svgContainer.group().id("StackedHeaders");
3542
- const firstRow = dataModel[0];
3543
- const scenarioKeys = ["scenario1", "scenario2", "scenario3", "scenario4"];
3544
- const segments = [];
3545
- for (const key of scenarioKeys) {
3546
- const dp = firstRow[key];
3547
- if (dp && !dp.isEmpty() && dp.value != null) {
3548
- segments.push({ value: dp.value, scenario: dp.scenario, dataPoint: dp });
3549
- }
3550
- }
3551
- if (segments.length === 0)
3552
- return;
3553
- const prefixes = new Set(segments.map((s) => getScenarioPrefix(s.scenario)));
3554
- const axisY = this.position.getColumnPositionY();
3555
- const xBase = this.position.getColumnCenterPositionX(0) - this.position.getColumnWidth() / 2;
3556
- const labelX = xBase - this.position.spacings.labelToColumn;
3557
- if (prefixes.size > 1) {
3558
- // Overlay mode: one header per group, centered vertically on group's column height
3559
- const groupMap = new Map();
3560
- for (const seg of segments) {
3561
- const prefix = getScenarioPrefix(seg.scenario);
3562
- if (!groupMap.has(prefix))
3563
- groupMap.set(prefix, []);
3564
- groupMap.get(prefix).push(seg);
3565
- }
3566
- const groups = [];
3567
- for (const prefix of IBCS_LAYER_ORDER) {
3568
- if (groupMap.has(prefix)) {
3569
- groups.push({ prefix, segments: groupMap.get(prefix) });
3570
- groupMap.delete(prefix);
3571
- }
3572
- }
3573
- for (const [prefix, segs] of groupMap) {
3574
- groups.push({ prefix, segments: segs });
3575
- }
3576
- groups.forEach((group) => {
3577
- const groupTotal = group.segments.reduce((sum, s) => sum + Math.abs(s.value), 0);
3578
- const pixelPerUnit = group.segments[0].dataPoint.pixelPerUnit;
3579
- const groupPixelHeight = this.stackConfig.mode === StackMode.RELATIVE ? pixelPerUnit : groupTotal * pixelPerUnit;
3580
- const centerY = axisY - groupPixelHeight / 2;
3581
- const labelText = this.i18n.get(group.prefix + "1") || group.prefix.toUpperCase();
3582
- new Label(headerGroup, labelX, centerY, "STACK_HEADER", labelText, this.styles, HookLocation.Center, HookLocation.Right).forceStringTypeDraw();
3583
- });
3584
- }
3585
- else {
3586
- // Single group: show individual segment headers
3587
- if (this.stackConfig.order === "asc")
3588
- segments.sort((a, b) => a.value - b.value);
3589
- else if (this.stackConfig.order === "desc")
3590
- segments.sort((a, b) => b.value - a.value);
3591
- const total = segments.reduce((sum, s) => sum + Math.abs(s.value), 0);
3592
- const pixelPerUnit = segments[0].dataPoint.pixelPerUnit;
3593
- let cumulativePixels = 0;
3594
- segments.forEach((seg) => {
3595
- let segmentHeight;
3596
- if (this.stackConfig.mode === StackMode.RELATIVE) {
3597
- const proportion = total !== 0 ? Math.abs(seg.value) / total : 0;
3598
- segmentHeight = proportion * pixelPerUnit;
3599
- }
3600
- else {
3601
- segmentHeight = Math.abs(seg.value * pixelPerUnit);
3602
- }
3603
- const centerY = axisY - cumulativePixels - segmentHeight / 2;
3604
- const labelText = this.i18n.get(seg.scenario) || seg.scenario;
3605
- new Label(headerGroup, labelX, centerY, "STACK_HEADER", labelText, this.styles, HookLocation.Center, HookLocation.Right).forceStringTypeDraw();
3606
- cumulativePixels += segmentHeight;
3607
- });
3608
- }
3609
- }
3610
- /**
3611
- * Draw stacked area chart (line mode with stack).
3612
- * Computes cumulative y-values and draws AreaFill paths between layers.
3613
- */
3614
- drawStackedAreaScenarios(dataModel, svgContainer) {
3615
- if (!this.stackConfig)
3616
- return;
3617
- const areaGroup = svgContainer.group().id("StackedAreaScenarios");
3618
- const isScenarioStack = this.stackConfig.by === StackBy.SCENARIO;
3619
- const stackMode = this.stackConfig.mode;
3620
- const scenarioKeys = ["scenario1", "scenario2", "scenario3", "scenario4"];
3621
- // Determine how many layers we have
3622
- const layerCount = isScenarioStack
3623
- ? scenarioKeys.filter((key) => dataModel.some((el) => el[key] && !el[key].isEmpty()))
3624
- .length
3625
- : 1;
3626
- if (layerCount === 0)
3627
- return;
3628
- // Build cumulative values per layer
3629
- // cumulativePoints[layerIdx][dataIdx] = cumulative y-value at that point
3630
- const cumulativeValues = [];
3631
- const layerScenarios = [];
3632
- // Identify active layers
3633
- const activeLayers = [];
3634
- for (const key of scenarioKeys) {
3635
- if (dataModel.some((el) => el[key] && !el[key].isEmpty())) {
3636
- activeLayers.push(key);
3637
- }
3638
- }
3639
- // Compute cumulative values
3640
- for (let layerIdx = 0; layerIdx < activeLayers.length; layerIdx++) {
3641
- const key = activeLayers[layerIdx];
3642
- const values = [];
3643
- for (let dataIdx = 0; dataIdx < dataModel.length; dataIdx++) {
3644
- const dp = dataModel[dataIdx][key];
3645
- const value = dp && !dp.isEmpty() && dp.value != null ? dp.value : 0;
3646
- const prevCumulative = layerIdx > 0 ? cumulativeValues[layerIdx - 1][dataIdx] : 0;
3647
- if (stackMode === StackMode.RELATIVE) {
3648
- // For relative: need total at each x position
3649
- const total = activeLayers.reduce((sum, k) => {
3650
- const d = dataModel[dataIdx][k];
3651
- return sum + (d && !d.isEmpty() && d.value != null ? Math.abs(d.value) : 0);
3652
- }, 0);
3653
- const proportion = total !== 0 ? Math.abs(value) / total : 0;
3654
- values.push(prevCumulative + proportion);
3655
- }
3656
- else {
3657
- values.push(prevCumulative + value);
3658
- }
3659
- }
3660
- cumulativeValues.push(values);
3661
- const firstDp = dataModel[0][key];
3662
- layerScenarios.push((firstDp === null || firstDp === void 0 ? void 0 : firstDp.scenario) || "ac1");
3663
- }
3664
- // Convert cumulative values to pixel coordinates
3665
- const axisY = this.position.getColumnPositionY();
3666
- const pixelPerUnit = this.pixelPerUnit;
3667
- const toAreaPoints = (values) => {
3668
- return values.map((val, idx) => ({
3669
- x: this.position.getColumnCenterPositionX(idx),
3670
- y: axisY -
3671
- (stackMode === StackMode.RELATIVE
3672
- ? val * pixelPerUnit // pixelPerUnit acts as "height for 100%"
3673
- : val * pixelPerUnit),
3674
- }));
3675
- };
3676
- // Baseline (y = axis)
3677
- const baselinePoints = dataModel.map((_, idx) => ({
3678
- x: this.position.getColumnCenterPositionX(idx),
3679
- y: axisY,
3680
- }));
3681
- // Draw area fills bottom-to-top
3682
- for (let layerIdx = 0; layerIdx < cumulativeValues.length; layerIdx++) {
3683
- const upperPoints = toAreaPoints(cumulativeValues[layerIdx]);
3684
- const lowerPoints = layerIdx === 0 ? baselinePoints : toAreaPoints(cumulativeValues[layerIdx - 1]);
3685
- const scenarioType = isScenarioStack ? layerScenarios[layerIdx] : null;
3686
- const areaFill = new AreaFill(areaGroup, upperPoints, lowerPoints, scenarioType, layerIdx, isScenarioStack);
3687
- areaFill.draw();
3688
- areaFill.drawBoundaryLine();
3689
- }
3690
- this.scenariosArea = {
3691
- height: areaGroup.height() + this.styles.padding.top + this.styles.padding.bottom,
3692
- width: areaGroup.width() + this.position.spacings.columnWidth,
3693
- };
3694
- }
3695
- drawOverlayLayer(dataModel, svgContainer) {
3696
- const overlayGroup = svgContainer.group().id("Overlay");
3697
- const scenarioFactory = new ScenarioFactory(this.position, overlayGroup, this.styles, dataModel.length, this.i18n);
3698
- if (this.showOverlayAvg === true) {
3699
- let previousDataPoint = null;
3700
- const avgDataModel = tranformToAvgDataModel(dataModel);
3701
- avgDataModel.forEach((elements, index) => {
3702
- if (previousDataPoint != null) {
3703
- scenarioFactory
3704
- .createLine(`Ø ${this.i18n.get(elements["scenario1"].scenario) || elements["scenario1"].scenario}`, elements["scenario1"], previousDataPoint, index - 1)
3705
- .draw(this.dataFormatDigits, this.measureScale);
3706
- }
3707
- previousDataPoint = elements["scenario1"];
3708
- });
3709
- }
3710
- if (this.showOverlayMedian === true) {
3711
- let previousDataPoint = null;
3712
- const medianDataModel = tranformToMedianDataModel(dataModel);
3713
- medianDataModel.forEach((elements, index) => {
3714
- if (previousDataPoint != null) {
3715
- scenarioFactory
3716
- .createLine(`Mdn ${this.i18n.get(elements["scenario1"].scenario) || elements["scenario1"].scenario}`, elements["scenario1"], previousDataPoint, index - 1)
3717
- .draw(this.dataFormatDigits, this.measureScale);
3718
- }
3719
- previousDataPoint = elements["scenario1"];
3720
- });
3721
- }
3722
- }
3723
- leftOuterJoinDates(result, dateInterval) {
3724
- const to = DateTime.max(...result.map(function (e) {
3725
- return e.calcdate;
3726
- }));
3727
- const from = DateTime.min(...result.map(function (e) {
3728
- return e.calcdate;
3729
- }));
3730
- const dateRange = new DateStringFactory().datesBetween(from, to, dateInterval, this.intervalSpanLimit);
3731
- const dateRangeEntries = new Map();
3732
- dateRange.forEach((element, idx) => {
3733
- dateRangeEntries.set(element.toISO(), {
3734
- id: idx,
3735
- calcdate: element,
3736
- category: null,
3737
- ac1: null,
3738
- ac2: null,
3739
- ac3: null,
3740
- ac4: null,
3741
- pp1: null,
3742
- pp2: null,
3743
- pp3: null,
3744
- pp4: null,
3745
- fc1: null,
3746
- fc2: null,
3747
- fc3: null,
3748
- fc4: null,
3749
- pl1: null,
3750
- pl2: null,
3751
- pl3: null,
3752
- pl4: null,
3753
- isEmpty: true,
3754
- });
3755
- });
3756
- result.forEach((element) => {
3757
- const millisecondKey = element.calcdate.toISO();
3758
- const placeholder = dateRangeEntries.get(millisecondKey);
3759
- if (placeholder && placeholder.isEmpty) {
3760
- const newElement = {
3761
- id: placeholder.id,
3762
- calcdate: element.calcdate,
3763
- category: element.category,
3764
- ac1: element.ac1,
3765
- ac2: element.ac2,
3766
- ac3: element.ac3,
3767
- ac4: element.ac4,
3768
- pp1: element.pp1,
3769
- pp2: element.pp2,
3770
- pp3: element.pp3,
3771
- pp4: element.pp4,
3772
- fc1: element.fc1,
3773
- fc2: element.fc2,
3774
- fc3: element.fc3,
3775
- fc4: element.fc4,
3776
- pl1: element.pl1,
3777
- pl2: element.pl2,
3778
- pl3: element.pl3,
3779
- pl4: element.pl4,
3780
- isEmpty: false,
3781
- };
3782
- dateRangeEntries.set(millisecondKey, newElement);
3783
- }
3784
- });
3785
- return Array.from(dateRangeEntries.values());
3786
- }
3787
- }
3788
- function tranformToAvgDataModel(dataModel) {
3789
- const total = dataModel.reduce((sum, elements) => {
3790
- var _a;
3791
- return sum + (((_a = elements["scenario1"]) === null || _a === void 0 ? void 0 : _a.value) || 0); // Sum up the values of scenario1
3792
- }, 0);
3793
- const count = dataModel.filter((elements) => { var _a; return ((_a = elements["scenario1"]) === null || _a === void 0 ? void 0 : _a.value) !== undefined; }).length; // Count valid scenario1 values
3794
- const average = count > 0 ? total / count : 0; // Calculate the average, avoid division by zero
3795
- // Create a new first element
3796
- const firstElement = Object.assign(Object.assign({}, dataModel[0]), { scenario1: new DataPoint(average, dataModel[0]["scenario1"].scenario, dataModel[0]["scenario1"].pixelPerUnit, dataModel[0]["scenario1"].variance) });
3797
- // Create a new last element
3798
- const lastElement = Object.assign(Object.assign({}, dataModel[dataModel.length - 1]), { scenario1: new DataPoint(average, dataModel[dataModel.length - 1]["scenario1"].scenario, dataModel[dataModel.length - 1]["scenario1"].pixelPerUnit, dataModel[dataModel.length - 1]["scenario1"].variance) });
3799
- // Add the new first and last elements to the transformed data model
3800
- return [
3801
- firstElement,
3802
- ...dataModel.map((elements) => {
3803
- return Object.assign(Object.assign({}, elements), { scenario1: new DataPoint(average, elements["scenario1"].scenario, elements["scenario1"].pixelPerUnit, elements["scenario1"].variance) });
3804
- }),
3805
- lastElement,
3806
- ];
3807
- }
3808
- function tranformToMedianDataModel(dataModel) {
3809
- const values = dataModel
3810
- .map((elements) => { var _a; return (_a = elements["scenario1"]) === null || _a === void 0 ? void 0 : _a.value; })
3811
- .filter((value) => value !== undefined)
3812
- .sort((a, b) => a - b);
3813
- const median = values.length % 2 === 0
3814
- ? (values[values.length / 2 - 1] + values[values.length / 2]) / 2
3815
- : values[Math.floor(values.length / 2)];
3816
- // Create a new first element
3817
- const firstElement = Object.assign(Object.assign({}, dataModel[0]), { scenario1: new DataPoint(median, dataModel[0]["scenario1"].scenario, dataModel[0]["scenario1"].pixelPerUnit, dataModel[0]["scenario1"].variance) });
3818
- // Create a new last element
3819
- const lastElement = Object.assign(Object.assign({}, dataModel[dataModel.length - 1]), { scenario1: new DataPoint(median, dataModel[dataModel.length - 1]["scenario1"].scenario, dataModel[dataModel.length - 1]["scenario1"].pixelPerUnit, dataModel[dataModel.length - 1]["scenario1"].variance) });
3820
- // Add the new first and last elements to the transformed data model
3821
- return [
3822
- firstElement,
3823
- ...dataModel.map((elements) => {
3824
- return Object.assign(Object.assign({}, elements), { scenario1: new DataPoint(median, elements["scenario1"].scenario, elements["scenario1"].pixelPerUnit, elements["scenario1"].variance) });
3825
- }),
3826
- lastElement,
3827
- ];
3828
- }
3829
-
3830
- // import { IAdapter } from "../../../../utils/helper/IAdapter";
3831
- // import { CompareUtil } from "../../../../utils/helper/CompareUtil";
3832
- // import { StringAdapter } from "../../../../utils/helper/StringAdapter";
3833
- // import { Order, OrderAdapter } from "../../../../utils/model/Order";
3834
- // import { AdapterUtils } from "../../../../utils/helper/AdapterUtils";
3835
- /**
3836
- * Configuration for an IBCS time-series chart component.
3837
- *
3838
- * Controls the vertical scale, date interval detection, axis labelling,
3839
- * and chart rendering mode (bar, line, etc.).
3840
- */
3841
- class TimeChartComponentConfig {
3842
- constructor(data, scenarios) {
3843
- this.data = data;
3844
- this.scenarios = scenarios;
3845
- /** Variance column identifiers (e.g. `["d_ac1_pl1_pos"]`) for delta visualizations. */
3846
- this.variances = [];
3847
- this.title = "";
3848
- this.hideAxisLabels = false;
3849
- /** Vertical scale factor: pixels per one data unit. Controls bar/line height. */
3850
- this.pixelPerUnit = 10;
3851
- /** Vertical scale factor for percentage variances: pixels per 1.0 (=100%). */
3852
- this.pixelPerPercentage = 50;
3853
- /** Maximum data points to display; 0 means unlimited. */
3854
- this.limit = 0;
3855
- this.sortOrder = new OrderAdapter(new StringAdapter()).default();
3856
- this.level = AggregationLevel.CATEGORY;
3857
- /** Pixel offset from left edge for horizontal alignment across multiple charts. -1 disables sync. */
3858
- this.leftSideOffsetForHorizontalSync = -1;
3859
- /** Date granularity (year, quarter, month, etc.). AUTO auto-detects from data. */
3860
- this.dateInterval = DateDistance.AUTO;
3861
- /** Controls how axis labels are rendered; SMART suppresses overlapping labels. */
3862
- this.axisLabelsMode = AxisLabelsMode.SMART;
3863
- /** Maximum number of date intervals before the chart truncates or scrolls. */
3864
- this.intervalSpanLimit = 28;
3865
- this.filter = "";
3866
- this.measureScale = new SiPrefix();
3867
- this.measureUnit = "";
3868
- this.showMeasureScale = true;
3869
- this.dataFormatDigits = { decimal: 1, percent: 2 };
3870
- this.showOverlayMedian = true;
3871
- this.showOverlayAvg = true;
3872
- this.chartMode = ChartMode.BAR;
3873
- /** Maximum number of bars to render before truncating; prevents visual overload. */
3874
- this.maxBars = 28;
3875
- this.stackConfig = null;
3876
- /** When true, line charts extend to the full width of the chart area. */
3877
- this.lineFullWidth = true;
3878
- }
3879
- }
3880
- /**
3881
- * Converts untyped JSON into a validated {@link TimeChartComponentConfig}.
3882
- *
3883
- * Requires the raw dataset for measure scale auto-calculation.
3884
- */
3885
- class TimeChartComponentConfigAdapter {
3886
- constructor(dataRowAdapter, orderAdapter, stringAdapter, dataFormatDigitsAdapter, dataSet) {
3887
- this.dataRowAdapter = dataRowAdapter;
3888
- this.orderAdapter = orderAdapter;
3889
- this.stringAdapter = stringAdapter;
3890
- this.dataFormatDigitsAdapter = dataFormatDigitsAdapter;
3891
- this.dataSet = dataSet;
3892
- }
3893
- adapt(data) {
3894
- const dataSet = AdapterUtils.adaptArray(data.data, this.dataRowAdapter);
3895
- const scenarios = AdapterUtils.adaptArray(data.scenarios, this.stringAdapter);
3896
- const config = new TimeChartComponentConfig(dataSet, scenarios);
3897
- if (CompareUtil.isArray(data.variances)) {
3898
- config.variances = AdapterUtils.adaptArray(data.variances, this.stringAdapter);
3899
- }
3900
- if (CompareUtil.isString(data.title)) {
3901
- config.title = data.title;
3902
- }
3903
- if (CompareUtil.isBoolean(data.hideAxisLabels)) {
3904
- config.hideAxisLabels = data.hideAxisLabels;
3905
- }
3906
- if (CompareUtil.isNumber(data.pixelPerUnit)) {
3907
- config.pixelPerUnit = data.pixelPerUnit;
3908
- }
3909
- if (CompareUtil.isNumber(data.pixelPerPercentage)) {
3910
- config.pixelPerPercentage = data.pixelPerPercentage;
3911
- }
3912
- if (CompareUtil.isNumber(data.limit)) {
3913
- config.limit = data.limit;
3914
- }
3915
- if (CompareUtil.isExisting(data.sortOrder)) {
3916
- config.sortOrder = this.orderAdapter.adapt(data.sortOrder);
3917
- }
3918
- if (CompareUtil.isExisting(data.level)) {
3919
- config.level = data.level;
3920
- }
3921
- if (CompareUtil.isExisting(data.dateInterval)) {
3922
- config.dateInterval = data.dateInterval;
3923
- }
3924
- if (CompareUtil.isExisting(data.axisLabelsMode)) {
3925
- config.axisLabelsMode = data.axisLabelsMode;
3926
- }
3927
- if (CompareUtil.isNumber(data.leftSideOffsetForHorizontalSync)) {
3928
- config.leftSideOffsetForHorizontalSync = data.leftSideOffsetForHorizontalSync;
3929
- }
3930
- if (CompareUtil.isNumber(data.intervalSpanLimit)) {
3931
- config.intervalSpanLimit = data.intervalSpanLimit;
3932
- }
3933
- if (CompareUtil.isString(data.filter)) {
3934
- config.filter = data.filter;
3935
- }
3936
- if (CompareUtil.isExisting(data.measureScale)) {
3937
- config.measureScale = DataAnalyzer.calculateMeasureScale(this.dataSet, config.scenarios, data.measureScale);
3938
- }
3939
- if (CompareUtil.isString(data.measureUnit)) {
3940
- config.measureUnit = data.measureUnit;
3941
- }
3942
- if (CompareUtil.isBoolean(data.showMeasureScale)) {
3943
- config.showMeasureScale = data.showMeasureScale;
3944
- }
3945
- if (CompareUtil.isExisting(data.dataFormatDigits)) {
3946
- config.dataFormatDigits = this.dataFormatDigitsAdapter.adapt(data.dataFormatDigits);
3947
- }
3948
- if (CompareUtil.isBoolean(data.showOverlayAvg)) {
3949
- config.showOverlayAvg = data.showOverlayAvg;
3950
- }
3951
- if (CompareUtil.isBoolean(data.showOverlayMedian)) {
3952
- config.showOverlayMedian = data.showOverlayMedian;
3953
- }
3954
- if (CompareUtil.isExisting(data.chartMode)) {
3955
- config.chartMode = data.chartMode;
3956
- }
3957
- if (CompareUtil.isNumber(data.maxBars)) {
3958
- config.maxBars = data.maxBars;
3959
- }
3960
- if (CompareUtil.isExisting(data.stackConfig)) {
3961
- config.stackConfig = data.stackConfig;
3962
- }
3963
- if (CompareUtil.isBoolean(data.lineFullWidth)) {
3964
- config.lineFullWidth = data.lineFullWidth;
3965
- }
3966
- return config;
3967
- }
3968
- default() {
3969
- return new TimeChartComponentConfig([], []);
3970
- }
3971
- }
3972
-
3973
- const ibcsChartTimeCss = () => `:host{position:relative;display:inline-block}.categories{text-align:right;font-size:var(--bn-font-size, 1em);font-family:var(--bn-font-family, "Noto Sans", "Helvetica Neue", Helvetica, sans-serif);color:var(--bn-font-color, black)}.label-bg{fill:var(--bn-font-background, white);opacity:0.7}.label-text{text-align:right;font-size:var(--bn-font-size, 1em);font-family:var(--bn-font-family, "Noto Sans", "Helvetica Neue", Helvetica, sans-serif);color:var(--bn-font-color, black)}.axis-title{text-align:center;font-family:var(--bn-font-family, "Noto Sans", "Helvetica Neue", Helvetica, sans-serif);color:var(--bn-font-color, black)}.axis-default{stroke:black;stroke-width:0.1em}.axis-ac{stroke:black;stroke-width:0.1em}.axis-pp{stroke:grey;stroke-width:0.1em}.axis-fc{stroke:black;stroke-dasharray:2;stroke-width:0.1em}.axis-pl{stroke:white;stroke-width:0.1em;outline-offset:0em;outline:0.1em solid black}canvas{image-rendering:-moz-crisp-edges;image-rendering:-webkit-crisp-edges;image-rendering:pixelated;image-rendering:crisp-edges}.measure{font-weight:bold}span{display:inline-block}.hidePatternContainer{height:0;width:0}div{float:left}.hide{opacity:0}.footer{margin:0.2em;font-size:0.6em}.footer-hide{margin:0.2em;font-size:0.6em;opacity:0}`;
3974
-
3975
- const IbcsChartTime = class {
3976
- constructor(hostRef) {
3977
- registerInstance(this, hostRef);
3978
- // @Prop() dimension: { height: number, width: number } = {height: 400, width: 450};
3979
- this.data = [];
3980
- this.scenarios = [];
3981
- this.variances = []; //["dfc_ac_neg"]
3982
- this.hideAxisLabels = false; //false
3983
- this.pixelPerUnit = 2; //2
3984
- this.pixelPerPercentage = 50; //2
3985
- this.limit = 0;
3986
- this.leftSideOffsetForHorizontalSync = -1;
3987
- this.i18n = new Map(); // I18nMode;
3988
- this.order = {
3989
- hierarchy: [],
3990
- direction: OrderDirection.ASC,
3991
- };
3992
- this.level = AggregationLevel.CATEGORY;
3993
- this.dateInterval = DateDistance.AUTO;
3994
- this.intervalSpanLimit = 28;
3995
- this.axisLabelsMode = AxisLabelsMode.SMART;
3996
- this.filter = "";
3997
- this.measureScale = "_";
3998
- this.measureUnit = "";
3999
- this.showMeasureScale = true;
4000
- this.showOverlayMedian = false;
4001
- this.showOverlayAvg = false;
4002
- this.chartMode = ChartMode.BAR;
4003
- this.maxBars = 28;
4004
- this.stackConfig = null;
4005
- this.lineFullWidth = true;
4006
- this.containerWidth = 0;
4007
- this.dataFormatDigits = { percent: 2, decimal: 1 };
4008
- this.parentDimensions = { width: 0, height: 0 };
4009
- }
4010
- render() {
4011
- var _a, _b, _c;
4012
- if (this.chart === undefined) {
4013
- return h(Host, null);
4014
- }
4015
- if (this.chart.hasNoData()) {
4016
- const errorMsg = this.i18n.get("NO_DATA") || "==No Data==";
4017
- return (h(Host, null, h("p", { class: "warning" }, errorMsg)));
4018
- }
4019
- return (h(Host, null, h("div", { innerHTML: (_a = this.pattern) === null || _a === void 0 ? void 0 : _a.toString(), class: "hidePatternContainer" }), h("div", { class: this.showMeasureScale ? "footer" : "footer-hide" }, (_b = this.chart) === null || _b === void 0 ? void 0 : _b.getFooter()), h("div", { innerHTML: (_c = this.chart) === null || _c === void 0 ? void 0 : _c.toString() })));
4020
- }
4021
- async componentWillLoad() {
4022
- var _a;
4023
- const config = this.prepareConfig();
4024
- const styles = this.prepareStyle();
4025
- const availableWidth = this.containerWidth || 0;
4026
- this.chart = new TimeChart(new IBCSRuleSet(), config, styles, availableWidth);
4027
- this.chart.setI18n(this.i18n);
4028
- this.autoFitScaling(config, styles);
4029
- this.chart.setAvailableHeight(((_a = this.parentDimensions) === null || _a === void 0 ? void 0 : _a.height) || 0);
4030
- this.pattern = new CustomPattern(this.chart.styles);
4031
- this.chart.setPattern("fc", this.pattern.getFCPolygonPattern());
4032
- }
4033
- async componentWillUpdate() {
4034
- var _a;
4035
- if (this.chart == null) {
4036
- return;
4037
- }
4038
- const config = this.prepareConfig();
4039
- const styles = this.prepareStyle();
4040
- this.chart.setI18n(this.i18n);
4041
- this.chart.setStyles(styles);
4042
- this.chart.setAvailableWidth(this.containerWidth || 0);
4043
- this.chart.setConfig(config);
4044
- this.autoFitScaling(config, styles);
4045
- this.chart.setAvailableHeight(((_a = this.parentDimensions) === null || _a === void 0 ? void 0 : _a.height) || 0);
4046
- this.pattern = new CustomPattern(this.chart.styles);
4047
- this.chart.setPattern("fc", this.pattern.getFCPolygonPattern());
4048
- }
4049
- /**
4050
- * Two-pass auto-fit: only when pixelPerUnit is 0 (auto mode).
4051
- * Explicit values are never overridden — the outer component warns
4052
- * about overflow via componentDidRender.
4053
- */
4054
- autoFitScaling(config, styles) {
4055
- var _a;
4056
- if (config.pixelPerUnit > 0) {
4057
- return; // Explicit value — respect it, do not override
4058
- }
4059
- const targetHeight = (_a = this.parentDimensions) === null || _a === void 0 ? void 0 : _a.height;
4060
- const availableWidth = this.containerWidth || 0;
4061
- if (!targetHeight || targetHeight <= 0) {
4062
- config.pixelPerUnit = 1; // No parent info — use fallback
4063
- this.chart = new TimeChart(new IBCSRuleSet(), config, styles, availableWidth);
4064
- this.chart.setI18n(this.i18n);
4065
- return;
4066
- }
4067
- // First pass with pixelPerUnit=1 to measure the real SVG height
4068
- config.pixelPerUnit = 1;
4069
- this.chart = new TimeChart(new IBCSRuleSet(), config, styles, availableWidth);
4070
- this.chart.setI18n(this.i18n);
4071
- this.chart.toString();
4072
- const svgHeight = this.chart.getAllocatedCanvasHeight();
4073
- if (svgHeight <= 0) {
4074
- return;
4075
- }
4076
- // Scale so the chart fits in ~90% of the available height
4077
- config.pixelPerUnit = (targetHeight * 0.9) / svgHeight;
4078
- // Second pass with the corrected scaling
4079
- this.chart = new TimeChart(new IBCSRuleSet(), config, styles, availableWidth);
4080
- this.chart.setI18n(this.i18n);
4081
- }
4082
- async componentWillRender() {
4083
- // return await (async () => {
4084
- // // console.log("componentWillRender", this.chart);
4085
- // if (this.chart) {
4086
- // // this.chart.draw(SVG(this.drawElement) as Svg);
4087
- // }
4088
- // })()
4089
- }
4090
- componentDidLoad() {
4091
- // if (this.chart == null) {
4092
- // return;
4093
- // }
4094
- // this.chart.draw(SVG(this.drawElement) as Svg);
4095
- // forceUpdate(getElement(this));
4096
- }
4097
- componentDidUpdate() {
4098
- //if (this.chart) {
4099
- // this.chart.draw(SVG(this.drawElement) as Svg);
4100
- //}
4101
- }
4102
- prepareConfig() {
4103
- return new TimeChartComponentConfigAdapter(new TimeChartDataRowAdapter(), new OrderAdapter(new StringAdapter()), new StringAdapter(), new DataFormatDigitsAdapter(), this.data).adapt({
4104
- data: this.data,
4105
- scenarios: this.scenarios,
4106
- variances: this.variances,
4107
- title: this.chartTitle,
4108
- hideAxisLabels: this.hideAxisLabels,
4109
- pixelPerUnit: this.pixelPerUnit,
4110
- pixelPerPercentage: this.pixelPerPercentage,
4111
- level: this.level,
4112
- dateInterval: this.dateInterval,
4113
- axisLabelsMode: this.axisLabelsMode,
4114
- limit: this.limit,
4115
- sortOrder: this.order,
4116
- leftSideOffsetForHorizontalSync: this.leftSideOffsetForHorizontalSync,
4117
- intervalSpanLimit: this.intervalSpanLimit,
4118
- filter: this.filter,
4119
- measureScale: this.measureScale,
4120
- measureUnit: this.measureUnit,
4121
- showMeasureScale: this.showMeasureScale,
4122
- dataFormatDigits: this.dataFormatDigits,
4123
- showOverlayMedian: this.showOverlayMedian,
4124
- showOverlayAvg: this.showOverlayAvg,
4125
- chartMode: this.chartMode,
4126
- maxBars: this.maxBars,
4127
- stackConfig: this.stackConfig,
4128
- lineFullWidth: this.lineFullWidth,
4129
- });
4130
- }
4131
- prepareStyle() {
4132
- return new TimeChartStylesAdapter(new ScaleFactorsTimeChartAdapter(), new FontStyleAdapter(), new SVGStyleGroupAdapter(new SVGStyleAdapter()), new SVGVariancesStyleGroupAdapter(new SVGStyleAdapter()), new PaddingAdapter()).adapt(this.styles);
4133
- }
4134
- get element() { return getElement(this); }
4135
- };
4136
- IbcsChartTime.style = ibcsChartTimeCss();
4137
-
4138
- export { IbcsChartTime as ibcs_chart_time };