@trebco/treb 37.0.0 → 37.0.1

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 (528) hide show
  1. package/build/package.json +119 -0
  2. package/build/treb-base-types/src/api_types.d.ts +11 -0
  3. package/build/treb-base-types/src/api_types.js +22 -0
  4. package/build/treb-base-types/src/api_types.js.map +1 -0
  5. package/build/treb-base-types/src/area-utils.d.ts +9 -0
  6. package/build/treb-base-types/src/area-utils.js +50 -0
  7. package/build/treb-base-types/src/area-utils.js.map +1 -0
  8. package/build/treb-base-types/src/area.d.ts +182 -0
  9. package/build/treb-base-types/src/area.js +715 -0
  10. package/build/treb-base-types/src/area.js.map +1 -0
  11. package/build/treb-base-types/src/basic_types.d.ts +20 -0
  12. package/build/treb-base-types/src/basic_types.js +22 -0
  13. package/build/treb-base-types/src/basic_types.js.map +1 -0
  14. package/build/treb-base-types/src/cell.d.ts +167 -0
  15. package/build/treb-base-types/src/cell.js +432 -0
  16. package/build/treb-base-types/src/cell.js.map +1 -0
  17. package/build/treb-base-types/src/cells.d.ts +251 -0
  18. package/build/treb-base-types/src/cells.js +1136 -0
  19. package/build/treb-base-types/src/cells.js.map +1 -0
  20. package/build/treb-base-types/src/color.d.ts +35 -0
  21. package/build/treb-base-types/src/color.js +162 -0
  22. package/build/treb-base-types/src/color.js.map +1 -0
  23. package/build/treb-base-types/src/dom-utilities.d.ts +70 -0
  24. package/build/treb-base-types/src/dom-utilities.js +144 -0
  25. package/build/treb-base-types/src/dom-utilities.js.map +1 -0
  26. package/build/treb-base-types/src/evaluate-options.d.ts +35 -0
  27. package/build/treb-base-types/src/evaluate-options.js +22 -0
  28. package/build/treb-base-types/src/evaluate-options.js.map +1 -0
  29. package/build/treb-base-types/src/font-stack.d.ts +37 -0
  30. package/build/treb-base-types/src/font-stack.js +93 -0
  31. package/build/treb-base-types/src/font-stack.js.map +1 -0
  32. package/build/treb-base-types/src/gradient.d.ts +18 -0
  33. package/build/treb-base-types/src/gradient.js +86 -0
  34. package/build/treb-base-types/src/gradient.js.map +1 -0
  35. package/build/treb-base-types/src/import.d.ts +48 -0
  36. package/build/treb-base-types/src/import.js +22 -0
  37. package/build/treb-base-types/src/import.js.map +1 -0
  38. package/build/treb-base-types/src/index-standalone.d.ts +6 -0
  39. package/build/treb-base-types/src/index-standalone.js +27 -0
  40. package/build/treb-base-types/src/index-standalone.js.map +1 -0
  41. package/build/treb-base-types/src/index.d.ts +22 -0
  42. package/build/treb-base-types/src/index.js +45 -0
  43. package/build/treb-base-types/src/index.js.map +1 -0
  44. package/build/treb-base-types/src/layout.d.ts +22 -0
  45. package/build/treb-base-types/src/layout.js +22 -0
  46. package/build/treb-base-types/src/layout.js.map +1 -0
  47. package/build/treb-base-types/src/localization.d.ts +37 -0
  48. package/build/treb-base-types/src/localization.js +157 -0
  49. package/build/treb-base-types/src/localization.js.map +1 -0
  50. package/build/treb-base-types/src/rectangle.d.ts +51 -0
  51. package/build/treb-base-types/src/rectangle.js +123 -0
  52. package/build/treb-base-types/src/rectangle.js.map +1 -0
  53. package/build/treb-base-types/src/render_text.d.ts +34 -0
  54. package/build/treb-base-types/src/render_text.js +22 -0
  55. package/build/treb-base-types/src/render_text.js.map +1 -0
  56. package/build/treb-base-types/src/style.d.ts +214 -0
  57. package/build/treb-base-types/src/style.js +373 -0
  58. package/build/treb-base-types/src/style.js.map +1 -0
  59. package/build/treb-base-types/src/table.d.ts +58 -0
  60. package/build/treb-base-types/src/table.js +27 -0
  61. package/build/treb-base-types/src/table.js.map +1 -0
  62. package/build/treb-base-types/src/text_part.d.ts +26 -0
  63. package/build/treb-base-types/src/text_part.js +47 -0
  64. package/build/treb-base-types/src/text_part.js.map +1 -0
  65. package/build/treb-base-types/src/theme.d.ts +120 -0
  66. package/build/treb-base-types/src/theme.js +460 -0
  67. package/build/treb-base-types/src/theme.js.map +1 -0
  68. package/build/treb-base-types/src/union.d.ts +73 -0
  69. package/build/treb-base-types/src/union.js +61 -0
  70. package/build/treb-base-types/src/union.js.map +1 -0
  71. package/build/treb-base-types/src/value-type.d.ts +86 -0
  72. package/build/treb-base-types/src/value-type.js +168 -0
  73. package/build/treb-base-types/src/value-type.js.map +1 -0
  74. package/build/treb-base-types/src/worker-proxy.d.ts +95 -0
  75. package/build/treb-base-types/src/worker-proxy.js +221 -0
  76. package/build/treb-base-types/src/worker-proxy.js.map +1 -0
  77. package/build/treb-calculator/src/calculator.d.ts +249 -0
  78. package/build/treb-calculator/src/calculator.js +2755 -0
  79. package/build/treb-calculator/src/calculator.js.map +1 -0
  80. package/build/treb-calculator/src/complex-math.d.ts +75 -0
  81. package/build/treb-calculator/src/complex-math.js +559 -0
  82. package/build/treb-calculator/src/complex-math.js.map +1 -0
  83. package/build/treb-calculator/src/dag/array-vertex.d.ts +71 -0
  84. package/build/treb-calculator/src/dag/array-vertex.js +156 -0
  85. package/build/treb-calculator/src/dag/array-vertex.js.map +1 -0
  86. package/build/treb-calculator/src/dag/calculation_leaf_vertex.d.ts +48 -0
  87. package/build/treb-calculator/src/dag/calculation_leaf_vertex.js +84 -0
  88. package/build/treb-calculator/src/dag/calculation_leaf_vertex.js.map +1 -0
  89. package/build/treb-calculator/src/dag/graph.d.ts +134 -0
  90. package/build/treb-calculator/src/dag/graph.js +842 -0
  91. package/build/treb-calculator/src/dag/graph.js.map +1 -0
  92. package/build/treb-calculator/src/dag/spreadsheet_vertex.d.ts +58 -0
  93. package/build/treb-calculator/src/dag/spreadsheet_vertex.js +232 -0
  94. package/build/treb-calculator/src/dag/spreadsheet_vertex.js.map +1 -0
  95. package/build/treb-calculator/src/dag/spreadsheet_vertex_base.d.ts +20 -0
  96. package/build/treb-calculator/src/dag/spreadsheet_vertex_base.js +25 -0
  97. package/build/treb-calculator/src/dag/spreadsheet_vertex_base.js.map +1 -0
  98. package/build/treb-calculator/src/dag/state_leaf_vertex.d.ts +43 -0
  99. package/build/treb-calculator/src/dag/state_leaf_vertex.js +81 -0
  100. package/build/treb-calculator/src/dag/state_leaf_vertex.js.map +1 -0
  101. package/build/treb-calculator/src/dag/vertex.d.ts +71 -0
  102. package/build/treb-calculator/src/dag/vertex.js +274 -0
  103. package/build/treb-calculator/src/dag/vertex.js.map +1 -0
  104. package/build/treb-calculator/src/descriptors.d.ts +189 -0
  105. package/build/treb-calculator/src/descriptors.js +22 -0
  106. package/build/treb-calculator/src/descriptors.js.map +1 -0
  107. package/build/treb-calculator/src/expression-calculator.d.ts +127 -0
  108. package/build/treb-calculator/src/expression-calculator.js +1033 -0
  109. package/build/treb-calculator/src/expression-calculator.js.map +1 -0
  110. package/build/treb-calculator/src/function-error.d.ts +35 -0
  111. package/build/treb-calculator/src/function-error.js +85 -0
  112. package/build/treb-calculator/src/function-error.js.map +1 -0
  113. package/build/treb-calculator/src/function-library.d.ts +22 -0
  114. package/build/treb-calculator/src/function-library.js +96 -0
  115. package/build/treb-calculator/src/function-library.js.map +1 -0
  116. package/build/treb-calculator/src/functions/base-functions.d.ts +7 -0
  117. package/build/treb-calculator/src/functions/base-functions.js +2611 -0
  118. package/build/treb-calculator/src/functions/base-functions.js.map +1 -0
  119. package/build/treb-calculator/src/functions/beta.d.ts +17 -0
  120. package/build/treb-calculator/src/functions/beta.js +201 -0
  121. package/build/treb-calculator/src/functions/beta.js.map +1 -0
  122. package/build/treb-calculator/src/functions/checkbox.d.ts +3 -0
  123. package/build/treb-calculator/src/functions/checkbox.js +128 -0
  124. package/build/treb-calculator/src/functions/checkbox.js.map +1 -0
  125. package/build/treb-calculator/src/functions/complex-functions.d.ts +2 -0
  126. package/build/treb-calculator/src/functions/complex-functions.js +217 -0
  127. package/build/treb-calculator/src/functions/complex-functions.js.map +1 -0
  128. package/build/treb-calculator/src/functions/date-utils.d.ts +3 -0
  129. package/build/treb-calculator/src/functions/date-utils.js +59 -0
  130. package/build/treb-calculator/src/functions/date-utils.js.map +1 -0
  131. package/build/treb-calculator/src/functions/finance-functions.d.ts +2 -0
  132. package/build/treb-calculator/src/functions/finance-functions.js +547 -0
  133. package/build/treb-calculator/src/functions/finance-functions.js.map +1 -0
  134. package/build/treb-calculator/src/functions/fp.d.ts +2 -0
  135. package/build/treb-calculator/src/functions/fp.js +463 -0
  136. package/build/treb-calculator/src/functions/fp.js.map +1 -0
  137. package/build/treb-calculator/src/functions/function-utilities.d.ts +2 -0
  138. package/build/treb-calculator/src/functions/function-utilities.js +36 -0
  139. package/build/treb-calculator/src/functions/function-utilities.js.map +1 -0
  140. package/build/treb-calculator/src/functions/gamma.d.ts +20 -0
  141. package/build/treb-calculator/src/functions/gamma.js +142 -0
  142. package/build/treb-calculator/src/functions/gamma.js.map +1 -0
  143. package/build/treb-calculator/src/functions/information-functions.d.ts +2 -0
  144. package/build/treb-calculator/src/functions/information-functions.js +71 -0
  145. package/build/treb-calculator/src/functions/information-functions.js.map +1 -0
  146. package/build/treb-calculator/src/functions/lambda-functions.d.ts +2 -0
  147. package/build/treb-calculator/src/functions/lambda-functions.js +85 -0
  148. package/build/treb-calculator/src/functions/lambda-functions.js.map +1 -0
  149. package/build/treb-calculator/src/functions/matrix-functions.d.ts +2 -0
  150. package/build/treb-calculator/src/functions/matrix-functions.js +144 -0
  151. package/build/treb-calculator/src/functions/matrix-functions.js.map +1 -0
  152. package/build/treb-calculator/src/functions/normal.d.ts +2 -0
  153. package/build/treb-calculator/src/functions/normal.js +32 -0
  154. package/build/treb-calculator/src/functions/normal.js.map +1 -0
  155. package/build/treb-calculator/src/functions/regex-functions.d.ts +2 -0
  156. package/build/treb-calculator/src/functions/regex-functions.js +188 -0
  157. package/build/treb-calculator/src/functions/regex-functions.js.map +1 -0
  158. package/build/treb-calculator/src/functions/sparkline.d.ts +37 -0
  159. package/build/treb-calculator/src/functions/sparkline.js +264 -0
  160. package/build/treb-calculator/src/functions/sparkline.js.map +1 -0
  161. package/build/treb-calculator/src/functions/statistics-functions.d.ts +6 -0
  162. package/build/treb-calculator/src/functions/statistics-functions.js +989 -0
  163. package/build/treb-calculator/src/functions/statistics-functions.js.map +1 -0
  164. package/build/treb-calculator/src/functions/students-t.d.ts +3 -0
  165. package/build/treb-calculator/src/functions/students-t.js +64 -0
  166. package/build/treb-calculator/src/functions/students-t.js.map +1 -0
  167. package/build/treb-calculator/src/functions/text-functions.d.ts +3 -0
  168. package/build/treb-calculator/src/functions/text-functions.js +320 -0
  169. package/build/treb-calculator/src/functions/text-functions.js.map +1 -0
  170. package/build/treb-calculator/src/index.d.ts +2 -0
  171. package/build/treb-calculator/src/index.js +22 -0
  172. package/build/treb-calculator/src/index.js.map +1 -0
  173. package/build/treb-calculator/src/notifier-types.d.ts +26 -0
  174. package/build/treb-calculator/src/notifier-types.js +22 -0
  175. package/build/treb-calculator/src/notifier-types.js.map +1 -0
  176. package/build/treb-calculator/src/primitives.d.ts +15 -0
  177. package/build/treb-calculator/src/primitives.js +398 -0
  178. package/build/treb-calculator/src/primitives.js.map +1 -0
  179. package/build/treb-calculator/src/utilities.d.ts +68 -0
  180. package/build/treb-calculator/src/utilities.js +324 -0
  181. package/build/treb-calculator/src/utilities.js.map +1 -0
  182. package/build/treb-charts/src/chart-functions.d.ts +8 -0
  183. package/build/treb-charts/src/chart-functions.js +209 -0
  184. package/build/treb-charts/src/chart-functions.js.map +1 -0
  185. package/build/treb-charts/src/chart-types.d.ts +233 -0
  186. package/build/treb-charts/src/chart-types.js +57 -0
  187. package/build/treb-charts/src/chart-types.js.map +1 -0
  188. package/build/treb-charts/src/chart-utils.d.ts +106 -0
  189. package/build/treb-charts/src/chart-utils.js +1060 -0
  190. package/build/treb-charts/src/chart-utils.js.map +1 -0
  191. package/build/treb-charts/src/chart.d.ts +23 -0
  192. package/build/treb-charts/src/chart.js +94 -0
  193. package/build/treb-charts/src/chart.js.map +1 -0
  194. package/build/treb-charts/src/default-chart-renderer.d.ts +16 -0
  195. package/build/treb-charts/src/default-chart-renderer.js +533 -0
  196. package/build/treb-charts/src/default-chart-renderer.js.map +1 -0
  197. package/build/treb-charts/src/index.d.ts +5 -0
  198. package/build/treb-charts/src/index.js +24 -0
  199. package/build/treb-charts/src/index.js.map +1 -0
  200. package/build/treb-charts/src/main.d.ts +1 -0
  201. package/build/treb-charts/src/main.js +34 -0
  202. package/build/treb-charts/src/main.js.map +1 -0
  203. package/build/treb-charts/src/quicksort.d.ts +1 -0
  204. package/build/treb-charts/src/quicksort.js +49 -0
  205. package/build/treb-charts/src/quicksort.js.map +1 -0
  206. package/build/treb-charts/src/rectangle.d.ts +18 -0
  207. package/build/treb-charts/src/rectangle.js +41 -0
  208. package/build/treb-charts/src/rectangle.js.map +1 -0
  209. package/build/treb-charts/src/renderer-type.d.ts +24 -0
  210. package/build/treb-charts/src/renderer-type.js +22 -0
  211. package/build/treb-charts/src/renderer-type.js.map +1 -0
  212. package/build/treb-charts/src/renderer.d.ts +127 -0
  213. package/build/treb-charts/src/renderer.js +1518 -0
  214. package/build/treb-charts/src/renderer.js.map +1 -0
  215. package/build/treb-charts/src/util.d.ts +18 -0
  216. package/build/treb-charts/src/util.js +71 -0
  217. package/build/treb-charts/src/util.js.map +1 -0
  218. package/build/treb-data-model/src/annotation.d.ts +167 -0
  219. package/build/treb-data-model/src/annotation.js +120 -0
  220. package/build/treb-data-model/src/annotation.js.map +1 -0
  221. package/build/treb-data-model/src/conditional_format.d.ts +155 -0
  222. package/build/treb-data-model/src/conditional_format.js +62 -0
  223. package/build/treb-data-model/src/conditional_format.js.map +1 -0
  224. package/build/treb-data-model/src/data-validation.d.ts +28 -0
  225. package/build/treb-data-model/src/data-validation.js +22 -0
  226. package/build/treb-data-model/src/data-validation.js.map +1 -0
  227. package/build/treb-data-model/src/data_model.d.ts +173 -0
  228. package/build/treb-data-model/src/data_model.js +637 -0
  229. package/build/treb-data-model/src/data_model.js.map +1 -0
  230. package/build/treb-data-model/src/index.d.ts +13 -0
  231. package/build/treb-data-model/src/index.js +28 -0
  232. package/build/treb-data-model/src/index.js.map +1 -0
  233. package/build/treb-data-model/src/language-model.d.ts +22 -0
  234. package/build/treb-data-model/src/language-model.js +22 -0
  235. package/build/treb-data-model/src/language-model.js.map +1 -0
  236. package/build/treb-data-model/src/named.d.ts +124 -0
  237. package/build/treb-data-model/src/named.js +372 -0
  238. package/build/treb-data-model/src/named.js.map +1 -0
  239. package/build/treb-data-model/src/serialize_options.d.ts +49 -0
  240. package/build/treb-data-model/src/serialize_options.js +22 -0
  241. package/build/treb-data-model/src/serialize_options.js.map +1 -0
  242. package/build/treb-data-model/src/sheet.d.ts +499 -0
  243. package/build/treb-data-model/src/sheet.js +2904 -0
  244. package/build/treb-data-model/src/sheet.js.map +1 -0
  245. package/build/treb-data-model/src/sheet_collection.d.ts +58 -0
  246. package/build/treb-data-model/src/sheet_collection.js +112 -0
  247. package/build/treb-data-model/src/sheet_collection.js.map +1 -0
  248. package/build/treb-data-model/src/sheet_selection.d.ts +42 -0
  249. package/build/treb-data-model/src/sheet_selection.js +39 -0
  250. package/build/treb-data-model/src/sheet_selection.js.map +1 -0
  251. package/build/treb-data-model/src/sheet_types.d.ts +104 -0
  252. package/build/treb-data-model/src/sheet_types.js +22 -0
  253. package/build/treb-data-model/src/sheet_types.js.map +1 -0
  254. package/build/treb-data-model/src/types.d.ts +59 -0
  255. package/build/treb-data-model/src/types.js +22 -0
  256. package/build/treb-data-model/src/types.js.map +1 -0
  257. package/build/treb-embed/src/custom-element/spreadsheet-constructor.d.ts +75 -0
  258. package/build/treb-embed/src/custom-element/spreadsheet-constructor.js +1144 -0
  259. package/build/treb-embed/src/custom-element/spreadsheet-constructor.js.map +1 -0
  260. package/build/treb-embed/src/custom-element/treb-global.d.ts +36 -0
  261. package/build/treb-embed/src/custom-element/treb-global.js +64 -0
  262. package/build/treb-embed/src/custom-element/treb-global.js.map +1 -0
  263. package/build/treb-embed/src/custom-element/treb-spreadsheet-element.d.ts +1 -0
  264. package/build/treb-embed/src/custom-element/treb-spreadsheet-element.js +61 -0
  265. package/build/treb-embed/src/custom-element/treb-spreadsheet-element.js.map +1 -0
  266. package/build/treb-embed/src/embedded-spreadsheet.d.ts +1358 -0
  267. package/build/treb-embed/src/embedded-spreadsheet.js +5205 -0
  268. package/build/treb-embed/src/embedded-spreadsheet.js.map +1 -0
  269. package/build/treb-embed/src/index.d.ts +12 -0
  270. package/build/treb-embed/src/index.js +34 -0
  271. package/build/treb-embed/src/index.js.map +1 -0
  272. package/build/treb-embed/src/options.d.ts +266 -0
  273. package/build/treb-embed/src/options.js +56 -0
  274. package/build/treb-embed/src/options.js.map +1 -0
  275. package/build/treb-embed/src/plugin.d.ts +9 -0
  276. package/build/treb-embed/src/plugin.js +22 -0
  277. package/build/treb-embed/src/plugin.js.map +1 -0
  278. package/build/treb-embed/src/progress-dialog.d.ts +49 -0
  279. package/build/treb-embed/src/progress-dialog.js +178 -0
  280. package/build/treb-embed/src/progress-dialog.js.map +1 -0
  281. package/build/treb-embed/src/selection-state.d.ts +15 -0
  282. package/build/treb-embed/src/selection-state.js +22 -0
  283. package/build/treb-embed/src/selection-state.js.map +1 -0
  284. package/build/treb-embed/src/spinner.d.ts +8 -0
  285. package/build/treb-embed/src/spinner.js +40 -0
  286. package/build/treb-embed/src/spinner.js.map +1 -0
  287. package/build/treb-embed/src/toolbar-message.d.ts +72 -0
  288. package/build/treb-embed/src/toolbar-message.js +22 -0
  289. package/build/treb-embed/src/toolbar-message.js.map +1 -0
  290. package/build/treb-embed/src/types.d.ts +185 -0
  291. package/build/treb-embed/src/types.js +45 -0
  292. package/build/treb-embed/src/types.js.map +1 -0
  293. package/build/treb-embed/tsconfig.tsbuildinfo +1 -0
  294. package/build/treb-export/src/address-type.d.ts +34 -0
  295. package/build/treb-export/src/address-type.js +53 -0
  296. package/build/treb-export/src/address-type.js.map +1 -0
  297. package/build/treb-export/src/base-template.d.ts +1 -0
  298. package/build/treb-export/src/base-template.js +22 -0
  299. package/build/treb-export/src/base-template.js.map +1 -0
  300. package/build/treb-export/src/column-width.d.ts +2 -0
  301. package/build/treb-export/src/column-width.js +80 -0
  302. package/build/treb-export/src/column-width.js.map +1 -0
  303. package/build/treb-export/src/drawing/bubble-chart-template.d.ts +514 -0
  304. package/build/treb-export/src/drawing/bubble-chart-template.js +544 -0
  305. package/build/treb-export/src/drawing/bubble-chart-template.js.map +1 -0
  306. package/build/treb-export/src/drawing/chart-template-components2.d.ts +365 -0
  307. package/build/treb-export/src/drawing/chart-template-components2.js +386 -0
  308. package/build/treb-export/src/drawing/chart-template-components2.js.map +1 -0
  309. package/build/treb-export/src/drawing/chart.d.ts +26 -0
  310. package/build/treb-export/src/drawing/chart.js +247 -0
  311. package/build/treb-export/src/drawing/chart.js.map +1 -0
  312. package/build/treb-export/src/drawing/column-chart-template2.d.ts +490 -0
  313. package/build/treb-export/src/drawing/column-chart-template2.js +518 -0
  314. package/build/treb-export/src/drawing/column-chart-template2.js.map +1 -0
  315. package/build/treb-export/src/drawing/donut-chart-template2.d.ts +272 -0
  316. package/build/treb-export/src/drawing/donut-chart-template2.js +293 -0
  317. package/build/treb-export/src/drawing/donut-chart-template2.js.map +1 -0
  318. package/build/treb-export/src/drawing/drawing.d.ts +49 -0
  319. package/build/treb-export/src/drawing/drawing.js +193 -0
  320. package/build/treb-export/src/drawing/drawing.js.map +1 -0
  321. package/build/treb-export/src/drawing/embedded-image.d.ts +12 -0
  322. package/build/treb-export/src/drawing/embedded-image.js +54 -0
  323. package/build/treb-export/src/drawing/embedded-image.js.map +1 -0
  324. package/build/treb-export/src/drawing/scatter-chart-template2.d.ts +520 -0
  325. package/build/treb-export/src/drawing/scatter-chart-template2.js +551 -0
  326. package/build/treb-export/src/drawing/scatter-chart-template2.js.map +1 -0
  327. package/build/treb-export/src/export.d.ts +72 -0
  328. package/build/treb-export/src/export.js +2039 -0
  329. package/build/treb-export/src/export.js.map +1 -0
  330. package/build/treb-export/src/import-export-messages.d.ts +31 -0
  331. package/build/treb-export/src/import-export-messages.js +22 -0
  332. package/build/treb-export/src/import-export-messages.js.map +1 -0
  333. package/build/treb-export/src/import.d.ts +33 -0
  334. package/build/treb-export/src/import.js +1258 -0
  335. package/build/treb-export/src/import.js.map +1 -0
  336. package/build/treb-export/src/index.worker.d.ts +1 -0
  337. package/build/treb-export/src/index.worker.js +93 -0
  338. package/build/treb-export/src/index.worker.js.map +1 -0
  339. package/build/treb-export/src/metadata.d.ts +51 -0
  340. package/build/treb-export/src/metadata.js +153 -0
  341. package/build/treb-export/src/metadata.js.map +1 -0
  342. package/build/treb-export/src/ooxml.d.ts +7 -0
  343. package/build/treb-export/src/ooxml.js +41 -0
  344. package/build/treb-export/src/ooxml.js.map +1 -0
  345. package/build/treb-export/src/relationship.d.ts +8 -0
  346. package/build/treb-export/src/relationship.js +27 -0
  347. package/build/treb-export/src/relationship.js.map +1 -0
  348. package/build/treb-export/src/shared-strings.d.ts +11 -0
  349. package/build/treb-export/src/shared-strings.js +105 -0
  350. package/build/treb-export/src/shared-strings.js.map +1 -0
  351. package/build/treb-export/src/template-2.d.ts +1 -0
  352. package/build/treb-export/src/template-2.js +22 -0
  353. package/build/treb-export/src/template-2.js.map +1 -0
  354. package/build/treb-export/src/unescape_xml.d.ts +1 -0
  355. package/build/treb-export/src/unescape_xml.js +61 -0
  356. package/build/treb-export/src/unescape_xml.js.map +1 -0
  357. package/build/treb-export/src/workbook-sheet.d.ts +75 -0
  358. package/build/treb-export/src/workbook-sheet.js +128 -0
  359. package/build/treb-export/src/workbook-sheet.js.map +1 -0
  360. package/build/treb-export/src/workbook-style.d.ts +110 -0
  361. package/build/treb-export/src/workbook-style.js +1134 -0
  362. package/build/treb-export/src/workbook-style.js.map +1 -0
  363. package/build/treb-export/src/workbook-theme.d.ts +13 -0
  364. package/build/treb-export/src/workbook-theme.js +85 -0
  365. package/build/treb-export/src/workbook-theme.js.map +1 -0
  366. package/build/treb-export/src/workbook.d.ts +123 -0
  367. package/build/treb-export/src/workbook.js +644 -0
  368. package/build/treb-export/src/workbook.js.map +1 -0
  369. package/build/treb-export/src/xml-test.d.ts +9 -0
  370. package/build/treb-export/src/xml-test.js +52 -0
  371. package/build/treb-export/src/xml-test.js.map +1 -0
  372. package/build/treb-export/src/xml-utils.d.ts +76 -0
  373. package/build/treb-export/src/xml-utils.js +223 -0
  374. package/build/treb-export/src/xml-utils.js.map +1 -0
  375. package/build/treb-export/src/zip-wrapper.d.ts +22 -0
  376. package/build/treb-export/src/zip-wrapper.js +93 -0
  377. package/build/treb-export/src/zip-wrapper.js.map +1 -0
  378. package/build/treb-format/src/format.d.ts +130 -0
  379. package/build/treb-format/src/format.js +805 -0
  380. package/build/treb-format/src/format.js.map +1 -0
  381. package/build/treb-format/src/format_cache.d.ts +55 -0
  382. package/build/treb-format/src/format_cache.js +166 -0
  383. package/build/treb-format/src/format_cache.js.map +1 -0
  384. package/build/treb-format/src/format_parser.d.ts +70 -0
  385. package/build/treb-format/src/format_parser.js +618 -0
  386. package/build/treb-format/src/format_parser.js.map +1 -0
  387. package/build/treb-format/src/index.d.ts +4 -0
  388. package/build/treb-format/src/index.js +25 -0
  389. package/build/treb-format/src/index.js.map +1 -0
  390. package/build/treb-format/src/number_format_section.d.ts +58 -0
  391. package/build/treb-format/src/number_format_section.js +78 -0
  392. package/build/treb-format/src/number_format_section.js.map +1 -0
  393. package/build/treb-format/src/value_parser.d.ts +48 -0
  394. package/build/treb-format/src/value_parser.js +244 -0
  395. package/build/treb-format/src/value_parser.js.map +1 -0
  396. package/build/treb-grid/src/editors/autocomplete.d.ts +39 -0
  397. package/build/treb-grid/src/editors/autocomplete.js +316 -0
  398. package/build/treb-grid/src/editors/autocomplete.js.map +1 -0
  399. package/build/treb-grid/src/editors/autocomplete_matcher.d.ts +74 -0
  400. package/build/treb-grid/src/editors/autocomplete_matcher.js +212 -0
  401. package/build/treb-grid/src/editors/autocomplete_matcher.js.map +1 -0
  402. package/build/treb-grid/src/editors/editor.d.ts +214 -0
  403. package/build/treb-grid/src/editors/editor.js +879 -0
  404. package/build/treb-grid/src/editors/editor.js.map +1 -0
  405. package/build/treb-grid/src/editors/external_editor.d.ts +11 -0
  406. package/build/treb-grid/src/editors/external_editor.js +118 -0
  407. package/build/treb-grid/src/editors/external_editor.js.map +1 -0
  408. package/build/treb-grid/src/editors/formula_bar.d.ts +85 -0
  409. package/build/treb-grid/src/editors/formula_bar.js +444 -0
  410. package/build/treb-grid/src/editors/formula_bar.js.map +1 -0
  411. package/build/treb-grid/src/editors/overlay_editor.d.ts +85 -0
  412. package/build/treb-grid/src/editors/overlay_editor.js +353 -0
  413. package/build/treb-grid/src/editors/overlay_editor.js.map +1 -0
  414. package/build/treb-grid/src/index.d.ts +12 -0
  415. package/build/treb-grid/src/index.js +28 -0
  416. package/build/treb-grid/src/index.js.map +1 -0
  417. package/build/treb-grid/src/layout/base_layout.d.ts +346 -0
  418. package/build/treb-grid/src/layout/base_layout.js +2050 -0
  419. package/build/treb-grid/src/layout/base_layout.js.map +1 -0
  420. package/build/treb-grid/src/layout/grid_layout.d.ts +19 -0
  421. package/build/treb-grid/src/layout/grid_layout.js +235 -0
  422. package/build/treb-grid/src/layout/grid_layout.js.map +1 -0
  423. package/build/treb-grid/src/layout/mock-layout.d.ts +10 -0
  424. package/build/treb-grid/src/layout/mock-layout.js +37 -0
  425. package/build/treb-grid/src/layout/mock-layout.js.map +1 -0
  426. package/build/treb-grid/src/render/selection-renderer.d.ts +97 -0
  427. package/build/treb-grid/src/render/selection-renderer.js +315 -0
  428. package/build/treb-grid/src/render/selection-renderer.js.map +1 -0
  429. package/build/treb-grid/src/render/svg_header_overlay.d.ts +20 -0
  430. package/build/treb-grid/src/render/svg_header_overlay.js +76 -0
  431. package/build/treb-grid/src/render/svg_header_overlay.js.map +1 -0
  432. package/build/treb-grid/src/render/svg_selection_block.d.ts +27 -0
  433. package/build/treb-grid/src/render/svg_selection_block.js +106 -0
  434. package/build/treb-grid/src/render/svg_selection_block.js.map +1 -0
  435. package/build/treb-grid/src/render/tile_renderer.d.ts +121 -0
  436. package/build/treb-grid/src/render/tile_renderer.js +1609 -0
  437. package/build/treb-grid/src/render/tile_renderer.js.map +1 -0
  438. package/build/treb-grid/src/types/border_constants.d.ts +9 -0
  439. package/build/treb-grid/src/types/border_constants.js +34 -0
  440. package/build/treb-grid/src/types/border_constants.js.map +1 -0
  441. package/build/treb-grid/src/types/clipboard_data.d.ts +11 -0
  442. package/build/treb-grid/src/types/clipboard_data.js +22 -0
  443. package/build/treb-grid/src/types/clipboard_data.js.map +1 -0
  444. package/build/treb-grid/src/types/clipboard_data2.d.ts +46 -0
  445. package/build/treb-grid/src/types/clipboard_data2.js +22 -0
  446. package/build/treb-grid/src/types/clipboard_data2.js.map +1 -0
  447. package/build/treb-grid/src/types/drag_mask.d.ts +10 -0
  448. package/build/treb-grid/src/types/drag_mask.js +78 -0
  449. package/build/treb-grid/src/types/drag_mask.js.map +1 -0
  450. package/build/treb-grid/src/types/external_editor_config.d.ts +33 -0
  451. package/build/treb-grid/src/types/external_editor_config.js +22 -0
  452. package/build/treb-grid/src/types/external_editor_config.js.map +1 -0
  453. package/build/treb-grid/src/types/grid.d.ts +806 -0
  454. package/build/treb-grid/src/types/grid.js +6410 -0
  455. package/build/treb-grid/src/types/grid.js.map +1 -0
  456. package/build/treb-grid/src/types/grid_base.d.ts +442 -0
  457. package/build/treb-grid/src/types/grid_base.js +3523 -0
  458. package/build/treb-grid/src/types/grid_base.js.map +1 -0
  459. package/build/treb-grid/src/types/grid_command.d.ts +408 -0
  460. package/build/treb-grid/src/types/grid_command.js +75 -0
  461. package/build/treb-grid/src/types/grid_command.js.map +1 -0
  462. package/build/treb-grid/src/types/grid_events.d.ts +93 -0
  463. package/build/treb-grid/src/types/grid_events.js +36 -0
  464. package/build/treb-grid/src/types/grid_events.js.map +1 -0
  465. package/build/treb-grid/src/types/grid_options.d.ts +50 -0
  466. package/build/treb-grid/src/types/grid_options.js +34 -0
  467. package/build/treb-grid/src/types/grid_options.js.map +1 -0
  468. package/build/treb-grid/src/types/scale-control.d.ts +21 -0
  469. package/build/treb-grid/src/types/scale-control.js +148 -0
  470. package/build/treb-grid/src/types/scale-control.js.map +1 -0
  471. package/build/treb-grid/src/types/set_range_options.d.ts +24 -0
  472. package/build/treb-grid/src/types/set_range_options.js +22 -0
  473. package/build/treb-grid/src/types/set_range_options.js.map +1 -0
  474. package/build/treb-grid/src/types/tab_bar.d.ts +84 -0
  475. package/build/treb-grid/src/types/tab_bar.js +426 -0
  476. package/build/treb-grid/src/types/tab_bar.js.map +1 -0
  477. package/build/treb-grid/src/types/tile.d.ts +29 -0
  478. package/build/treb-grid/src/types/tile.js +22 -0
  479. package/build/treb-grid/src/types/tile.js.map +1 -0
  480. package/build/treb-grid/src/types/update_flags.d.ts +48 -0
  481. package/build/treb-grid/src/types/update_flags.js +22 -0
  482. package/build/treb-grid/src/types/update_flags.js.map +1 -0
  483. package/build/treb-grid/src/util/fontmetrics.d.ts +21 -0
  484. package/build/treb-grid/src/util/fontmetrics.js +82 -0
  485. package/build/treb-grid/src/util/fontmetrics.js.map +1 -0
  486. package/build/treb-grid/src/util/ua.d.ts +33 -0
  487. package/build/treb-grid/src/util/ua.js +86 -0
  488. package/build/treb-grid/src/util/ua.js.map +1 -0
  489. package/build/treb-parser/src/csv-parser.d.ts +13 -0
  490. package/build/treb-parser/src/csv-parser.js +107 -0
  491. package/build/treb-parser/src/csv-parser.js.map +1 -0
  492. package/build/treb-parser/src/index.d.ts +4 -0
  493. package/build/treb-parser/src/index.js +25 -0
  494. package/build/treb-parser/src/index.js.map +1 -0
  495. package/build/treb-parser/src/md-parser.d.ts +97 -0
  496. package/build/treb-parser/src/md-parser.js +403 -0
  497. package/build/treb-parser/src/md-parser.js.map +1 -0
  498. package/build/treb-parser/src/parser-types.d.ts +345 -0
  499. package/build/treb-parser/src/parser-types.js +53 -0
  500. package/build/treb-parser/src/parser-types.js.map +1 -0
  501. package/build/treb-parser/src/parser.d.ts +422 -0
  502. package/build/treb-parser/src/parser.js +2418 -0
  503. package/build/treb-parser/src/parser.js.map +1 -0
  504. package/build/treb-utils/src/event_source.d.ts +34 -0
  505. package/build/treb-utils/src/event_source.js +110 -0
  506. package/build/treb-utils/src/event_source.js.map +1 -0
  507. package/build/treb-utils/src/ievent_source.d.ts +9 -0
  508. package/build/treb-utils/src/ievent_source.js +22 -0
  509. package/build/treb-utils/src/ievent_source.js.map +1 -0
  510. package/build/treb-utils/src/index.d.ts +6 -0
  511. package/build/treb-utils/src/index.js +30 -0
  512. package/build/treb-utils/src/index.js.map +1 -0
  513. package/build/treb-utils/src/measurement.d.ts +42 -0
  514. package/build/treb-utils/src/measurement.js +145 -0
  515. package/build/treb-utils/src/measurement.js.map +1 -0
  516. package/build/treb-utils/src/scale.d.ts +16 -0
  517. package/build/treb-utils/src/scale.js +106 -0
  518. package/build/treb-utils/src/scale.js.map +1 -0
  519. package/build/treb-utils/src/serialize_html.d.ts +5 -0
  520. package/build/treb-utils/src/serialize_html.js +128 -0
  521. package/build/treb-utils/src/serialize_html.js.map +1 -0
  522. package/build/treb-utils/src/validate_uri.d.ts +20 -0
  523. package/build/treb-utils/src/validate_uri.js +55 -0
  524. package/build/treb-utils/src/validate_uri.js.map +1 -0
  525. package/dist/{chunk-XD5PEZBZ.mjs → chunk-E35ONJUS.mjs} +1 -1
  526. package/dist/treb-export-worker.mjs +2 -2
  527. package/dist/treb-spreadsheet.mjs +4 -4
  528. package/package.json +1 -1
@@ -0,0 +1,1060 @@
1
+ /*
2
+ * This file is part of TREB.
3
+ *
4
+ * TREB is free software: you can redistribute it and/or modify it under the
5
+ * terms of the GNU General Public License as published by the Free Software
6
+ * Foundation, either version 3 of the License, or (at your option) any
7
+ * later version.
8
+ *
9
+ * TREB is distributed in the hope that it will be useful, but WITHOUT ANY
10
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12
+ * details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License along
15
+ * with TREB. If not, see <https://www.gnu.org/licenses/>.
16
+ *
17
+ * Copyright 2022-2026 trebco, llc.
18
+ * info@treb.app
19
+ *
20
+ */
21
+ import { ValueType, IsComplex } from 'treb-base-types';
22
+ import { IsArrayUnion, IsMetadata, IsSeries, LegendStyle } from './chart-types';
23
+ import { NumberFormatCache } from 'treb-format';
24
+ import { Util } from './util';
25
+ import { QuickSort } from './quicksort';
26
+ /**
27
+ * this file is the concrete translation from function arguments
28
+ * to chart data. chart data is a (somewhat complicated) type with
29
+ * specializations for various chart types. we're splitting the
30
+ * generation of that data from the actual layout/rendering with
31
+ * a view towards building a new (or several new) renderers.
32
+ */
33
+ const DEFAULT_FORMAT = '#,##0.00'; // why not use "general", or whatever the usual default is?
34
+ export const ArrayMinMax = (data) => {
35
+ let min = data[0];
36
+ let max = data[0];
37
+ for (const entry of data) {
38
+ if (entry < min) {
39
+ min = entry;
40
+ }
41
+ if (entry > max) {
42
+ max = entry;
43
+ }
44
+ }
45
+ return { min, max };
46
+ /*
47
+ const copy = data.slice(0);
48
+ copy.sort((a, b) => a - b);
49
+ return {min: copy[0], max: copy[copy.length - 1]};
50
+ */
51
+ };
52
+ export const ReadSeries = (data) => {
53
+ // const label, x, y, z, index, subtype, data_labels] = data;
54
+ const { label, x, y, z, index, subtype, data_labels, axis } = data;
55
+ // series type is (now)
56
+ //
57
+ // [0] label, string
58
+ // [1] X, array, metadata [* could be single value?]
59
+ // [2] Y, array, metadata [* could be single value?]
60
+ // [3] Z, array, metadata [* could be single value?]
61
+ // [4] index, number
62
+ // [5] subtype, string
63
+ //
64
+ // in this case it's (label, X, Y)
65
+ const series = {
66
+ x: { data: [] },
67
+ y: { data: [] },
68
+ };
69
+ if (typeof axis === 'number') {
70
+ series.axis = axis;
71
+ }
72
+ if (typeof index === 'number') {
73
+ series.index = index;
74
+ }
75
+ if (subtype) {
76
+ series.subtype = subtype.toString();
77
+ }
78
+ if (data_labels) {
79
+ const labels = Util.Flatten(Array.isArray(data_labels) ? data_labels : [data_labels]);
80
+ series.labels = labels.map(value => (typeof value === 'undefined') ? '' : value.toString());
81
+ }
82
+ if (label) {
83
+ series.label = label.toString();
84
+ }
85
+ const ParseSubseries = (source, apply_labels = false) => {
86
+ let subseries;
87
+ // convert single values -> array (is this still necessary?)
88
+ if (IsMetadata(source)) {
89
+ source = {
90
+ type: ValueType.array,
91
+ value: [[source]],
92
+ };
93
+ }
94
+ if (IsArrayUnion(source)) {
95
+ subseries = { data: [] };
96
+ const flat = Util.Flatten(source.value);
97
+ subseries.data = flat.map(item => {
98
+ if (IsMetadata(item)) {
99
+ if (typeof item.value.value === 'number') {
100
+ return item.value.value;
101
+ }
102
+ }
103
+ else if (item.type === ValueType.number) {
104
+ return item.value;
105
+ }
106
+ return undefined;
107
+ });
108
+ if (IsMetadata(flat[0]) && flat[0].value?.format) {
109
+ subseries.format = (flat[0].value.format);
110
+ if (apply_labels) {
111
+ const format = NumberFormatCache.Get(subseries.format);
112
+ subseries.labels = subseries.data.map(value => (value === undefined) ? undefined : format.Format(value));
113
+ }
114
+ }
115
+ }
116
+ return subseries;
117
+ };
118
+ // read [2] first, so we can default for [1] if necessary
119
+ series.y = ParseSubseries(y, true) || { data: [] };
120
+ series.x = ParseSubseries(x) || { data: [] };
121
+ series.z = ParseSubseries(z);
122
+ const entries = [series.x, series.y];
123
+ for (const subseries of entries) {
124
+ // in case of no values
125
+ if (subseries.data.length) {
126
+ const values = subseries.data.filter(value => value || value === 0);
127
+ subseries.range = ArrayMinMax(values);
128
+ }
129
+ }
130
+ return series;
131
+ };
132
+ export const ArrayToSeries = (array_data) => {
133
+ // this is an array of Y, X not provided
134
+ const series = { x: { data: [] }, y: { data: [] }, };
135
+ const flat = Util.Flatten(array_data.value);
136
+ // series.y.data = flat.map(item => typeof item.value === 'number' ? item.value : undefined);
137
+ // console.trace();
138
+ const values = []; // filter any undefineds
139
+ for (const [index, item] of flat.entries()) {
140
+ let value = 0;
141
+ // why is this testing type instead of using the union type?
142
+ if (typeof item.value === 'number') {
143
+ value = item.value;
144
+ // series.y.data[index] = item.value;
145
+ values.push(item.value);
146
+ }
147
+ else if (IsMetadata(item)) {
148
+ if (IsComplex(item.value.value)) {
149
+ series.x.data[index] = item.value.value.real;
150
+ // series.y.data[index] = item.value.value.imaginary;
151
+ // values.push(item.value.value.imaginary);
152
+ value = item.value.value.imaginary;
153
+ }
154
+ else if (typeof item.value.value === 'number') {
155
+ // series.y.data[index] = item.value.value;
156
+ // values.push(item.value.value);
157
+ value = item.value.value;
158
+ }
159
+ else {
160
+ continue;
161
+ }
162
+ }
163
+ else {
164
+ // series.y.data[index] = undefined;
165
+ continue;
166
+ }
167
+ series.y.data[index] = value;
168
+ values.push(value);
169
+ }
170
+ /*
171
+ series.y.data = flat.map((item, index) => {
172
+
173
+ // if the data is passed in from the output of a function, it will not
174
+ // be inside a metadata structure
175
+
176
+ if (typeof item.value === 'number') { return item.value; }
177
+
178
+ // ... ok, it's metadata (why not just test?) ...
179
+
180
+ if (IsMetadata(item)) {
181
+
182
+ // experimenting with complex... put real in X axis and imaginary in Y axis
183
+ // note should also function w/ complex not in a metadata structure
184
+
185
+ // if (typeof item.value.value?.real === 'number') {
186
+ if (IsComplex(item.value.value)) {
187
+ series.x.data[index] = item.value.value.real;
188
+ return item.value.value.imaginary;
189
+ }
190
+ if (typeof item.value.value === 'number') {
191
+ return item.value.value;
192
+ }
193
+
194
+ }
195
+
196
+ // return typeof item.value.value === 'number' ? item.value.value : undefined;
197
+
198
+ return undefined;
199
+
200
+ });
201
+ */
202
+ let first_format = '';
203
+ if (IsMetadata(flat[0])) {
204
+ first_format = flat[0].value.format || '';
205
+ }
206
+ if (first_format) {
207
+ series.y.format = first_format;
208
+ const format = NumberFormatCache.Get(series.y.format || '');
209
+ series.y.labels = series.y.data.map(value => (value === undefined) ? undefined : format.Format(value));
210
+ }
211
+ // moved up, integrated loops
212
+ // const values = series.y.data.filter(value => value || value === 0) as number[];
213
+ series.y.range = ArrayMinMax(values);
214
+ // experimenting with complex... this should only be set if we populated
215
+ // it from complex values
216
+ if (series.x.data.length) {
217
+ const filtered = series.x.data.filter(test => typeof test === 'number');
218
+ series.x.range = ArrayMinMax(filtered);
219
+ if (first_format) {
220
+ series.x.format = first_format;
221
+ const format = NumberFormatCache.Get(series.x.format || '');
222
+ series.x.labels = series.x.data.map(value => (value === undefined) ? undefined : format.Format(value));
223
+ }
224
+ }
225
+ return series;
226
+ };
227
+ /**
228
+ * composite data -> series. composite data can be
229
+ *
230
+ * (1) set of Y values, with X not provided;
231
+ * (2) SERIES(label, X, Y) with Y required, others optional
232
+ * (3) GROUP(a, b, ...), where entries are either arrays as (1) or SERIES as (2)
233
+ *
234
+ * FIXME: consider supporting GROUP(SERIES, [y], ...)
235
+ *
236
+ * NOTE: (1) could be an array of boxed (union) values...
237
+ *
238
+ */
239
+ export const TransformSeriesData = (raw_data, default_x) => {
240
+ if (!raw_data) {
241
+ return [];
242
+ }
243
+ const list = [];
244
+ if (raw_data.type === ValueType.object) {
245
+ if (raw_data.key === 'group') {
246
+ if (Array.isArray(raw_data.value)) {
247
+ for (const [series_index, entry] of raw_data.value.entries()) {
248
+ if (!!entry && (typeof entry === 'object')) {
249
+ if (IsSeries(entry)) {
250
+ const series = ReadSeries(entry.value);
251
+ if (typeof series.index === 'undefined') {
252
+ series.index = series_index + 1;
253
+ }
254
+ list.push(series);
255
+ }
256
+ else if (entry.type === ValueType.array) {
257
+ list.push(ArrayToSeries(entry));
258
+ }
259
+ }
260
+ }
261
+ }
262
+ }
263
+ else if (IsSeries(raw_data)) {
264
+ const series = ReadSeries(raw_data.value);
265
+ list.push(series);
266
+ }
267
+ }
268
+ else if (raw_data.type === ValueType.array) {
269
+ list.push(ArrayToSeries(raw_data));
270
+ }
271
+ // now we may or may not have X for each series, so we need
272
+ // to patch. it's also possible (as with older chart functions)
273
+ // that there's a common X -- not sure if we want to continue
274
+ // to support that or not...
275
+ let baseline_x;
276
+ let max_y_length = 0;
277
+ // if we have a default, use that (and range it)
278
+ if (default_x?.type === ValueType.array) {
279
+ const values = Util.Flatten(default_x.value);
280
+ let format = '0.00###';
281
+ if (IsMetadata(values[0]) && values[0].value.format) {
282
+ format = values[0].value.format;
283
+ }
284
+ const data = values.map(x => {
285
+ if (x.type === ValueType.number) {
286
+ return x.value;
287
+ }
288
+ if (IsMetadata(x) && typeof x.value.value === 'number') {
289
+ return x.value.value;
290
+ }
291
+ return undefined;
292
+ });
293
+ const filtered = data.filter(x => typeof x === 'number');
294
+ baseline_x = {
295
+ data,
296
+ format,
297
+ range: ArrayMinMax(filtered),
298
+ };
299
+ }
300
+ // look for the first set that has values. at the same time, get max len
301
+ for (const entry of list) {
302
+ max_y_length = Math.max(max_y_length, entry.y.data.length);
303
+ if (entry.x.data.length) {
304
+ if (!baseline_x) {
305
+ baseline_x = entry.x;
306
+ }
307
+ }
308
+ }
309
+ // now default for any series missing X
310
+ if (!baseline_x) {
311
+ baseline_x = {
312
+ data: [],
313
+ range: {
314
+ min: 0,
315
+ max: Math.max(0, max_y_length - 1),
316
+ }
317
+ };
318
+ for (let i = 0; i < max_y_length; i++) {
319
+ baseline_x.data.push(i);
320
+ }
321
+ }
322
+ for (const entry of list) {
323
+ if (!entry.x.data.length) {
324
+ entry.x = baseline_x;
325
+ }
326
+ }
327
+ return list;
328
+ };
329
+ const AutoFormat = (scale) => {
330
+ const zep = Math.abs(scale.step) % 1;
331
+ if (!zep) {
332
+ const log10 = Math.log10(Math.abs(scale.step));
333
+ if (log10 >= 5) {
334
+ return 'Scientific';
335
+ }
336
+ return '#,##0';
337
+ }
338
+ else {
339
+ const log10 = Math.log10(Math.abs(zep));
340
+ if (log10 < -4) {
341
+ return 'Scientific';
342
+ }
343
+ let count = 0;
344
+ for (let i = 0; i < scale.count; i++) {
345
+ const value = ((scale.min + scale.step * i) % 1).toFixed(6).replace(/0+$/, '');
346
+ count = Math.max(count, value.length - 2);
347
+ }
348
+ let format = '#,##0.';
349
+ for (let i = 0; i < count; i++) {
350
+ format += '0';
351
+ }
352
+ return format;
353
+ }
354
+ };
355
+ /** get a unified scale, and formats */
356
+ export const CommonData = (series, y_floor, y_ceiling, x_floor, x_ceiling, auto_number_format) => {
357
+ let x_format = '';
358
+ let y_format = '';
359
+ let y2_format = '';
360
+ for (const entry of series) {
361
+ if (entry.axis) {
362
+ if (entry.y.format && !y2_format) {
363
+ y2_format = entry.y.format;
364
+ }
365
+ }
366
+ else {
367
+ if (entry.y.format && !y_format) {
368
+ y_format = entry.y.format;
369
+ }
370
+ }
371
+ if (entry.x.format && !x_format) {
372
+ x_format = entry.x.format;
373
+ }
374
+ }
375
+ let legend; // string[]|undefined;
376
+ if (series.some(test => test.label && (test.label.length > 0))) {
377
+ legend = series.map((entry, i) => ({
378
+ label: entry.label || `Series ${i + 1}`,
379
+ index: typeof entry.index === 'number' ? entry.index : i + 1,
380
+ }));
381
+ }
382
+ const x = series.filter(test => test.x.range);
383
+ let x_min = Math.min.apply(0, x.map(test => test.x.range?.min || 0));
384
+ let x_max = Math.max.apply(0, x.map(test => test.x.range?.max || 0));
385
+ const x1 = x.filter(test => !test.axis);
386
+ const x2 = x.filter(test => test.axis);
387
+ let y_min = Math.min.apply(0, x1.map(test => test.y.range?.min || 0));
388
+ let y_max = Math.max.apply(0, x1.map(test => test.y.range?.max || 0));
389
+ let y2_min = -1;
390
+ let y2_max = -1;
391
+ if (x2.length) {
392
+ y2_min = Math.min.apply(0, x2.map(test => test.y.range?.min || 0));
393
+ y2_max = Math.max.apply(0, x2.map(test => test.y.range?.max || 0));
394
+ }
395
+ // if there's z data (used for bubble size), adjust x/y min/max to
396
+ // account for the z size so bubbles are contained within the grid
397
+ // this can't be used with axis (atm)
398
+ for (const subseries of series) {
399
+ if (subseries.z) {
400
+ for (const [index, z] of subseries.z.data.entries()) {
401
+ if (typeof z !== 'undefined') {
402
+ const x = subseries.x.data[index];
403
+ const half = Math.max(0, z / 2); // accounting for negative values (which we don't use)
404
+ if (typeof x !== 'undefined') {
405
+ x_min = Math.min(x_min, x - half);
406
+ x_max = Math.max(x_max, x + half);
407
+ }
408
+ const y = subseries.y.data[index];
409
+ if (typeof y !== 'undefined') {
410
+ y_min = Math.min(y_min, y - half);
411
+ y_max = Math.max(y_max, y + half);
412
+ }
413
+ }
414
+ }
415
+ }
416
+ }
417
+ if (typeof x_floor !== 'undefined') {
418
+ x_min = Math.min(x_min, x_floor);
419
+ }
420
+ if (typeof x_ceiling !== 'undefined') {
421
+ x_min = Math.max(x_min, x_ceiling);
422
+ }
423
+ if (typeof y_floor !== 'undefined') {
424
+ y_min = Math.min(y_min, y_floor);
425
+ }
426
+ if (typeof y_ceiling !== 'undefined') {
427
+ y_max = Math.max(y_max, y_ceiling);
428
+ }
429
+ const x_scale = Util.Scale(x_min, x_max, 7);
430
+ const y_scale = Util.Scale(y_min, y_max, 7);
431
+ const y2_scale = Util.Scale(y2_min, y2_max, 7);
432
+ if (y2_min !== y2_max && y_scale && y2_scale) {
433
+ if (y_scale.count !== y2_scale.count) {
434
+ const max = Math.max(y_scale.count, y2_scale.count);
435
+ const target = y_scale.count < max ? y_scale : y2_scale;
436
+ for (let i = target.count; i < max; i += 2) {
437
+ // add high
438
+ target.max += target.step;
439
+ target.count++;
440
+ if (target.count < max) {
441
+ // add low
442
+ target.min -= target.step;
443
+ target.count++;
444
+ }
445
+ }
446
+ }
447
+ }
448
+ let x_labels;
449
+ let y_labels;
450
+ let y2_labels;
451
+ if (x_format) {
452
+ x_labels = [];
453
+ const format = NumberFormatCache.Get(x_format);
454
+ for (let i = 0; i <= x_scale.count; i++) {
455
+ x_labels.push(format.Format(x_scale.min + i * x_scale.step));
456
+ }
457
+ }
458
+ if (!y_format && auto_number_format) {
459
+ y_format = AutoFormat(y_scale);
460
+ }
461
+ if (!y2_format && auto_number_format) {
462
+ y2_format = AutoFormat(y2_scale);
463
+ }
464
+ if (y_format) {
465
+ y_labels = [];
466
+ const format = NumberFormatCache.Get(y_format);
467
+ for (let i = 0; i <= y_scale.count; i++) {
468
+ y_labels.push(format.Format(y_scale.min + i * y_scale.step));
469
+ }
470
+ }
471
+ if (y2_format) {
472
+ y2_labels = [];
473
+ const format = NumberFormatCache.Get(y2_format);
474
+ for (let i = 0; i <= y2_scale.count; i++) {
475
+ y2_labels.push(format.Format(y2_scale.min + i * y2_scale.step));
476
+ }
477
+ }
478
+ const result = {
479
+ x: {
480
+ format: x_format,
481
+ scale: x_scale,
482
+ labels: x_labels,
483
+ },
484
+ y: {
485
+ format: y_format,
486
+ scale: y_scale,
487
+ labels: y_labels,
488
+ },
489
+ legend,
490
+ };
491
+ if (y2_min !== y2_max) {
492
+ result.y2 = {
493
+ format: y2_format,
494
+ scale: y2_scale,
495
+ labels: y2_labels,
496
+ };
497
+ }
498
+ return result;
499
+ };
500
+ const ApplyLabels = (series_list, pattern, category_labels) => {
501
+ for (const series of series_list) {
502
+ const format = {
503
+ x: NumberFormatCache.Get(series.x.format || ''),
504
+ y: NumberFormatCache.Get(series.y.format || ''),
505
+ };
506
+ series.y.labels = [];
507
+ for (let i = 0; i < series.y.data.length; i++) {
508
+ const x = category_labels ? category_labels[i] :
509
+ (typeof series.x.data[i] === 'number' ? format.x.Format(series.x.data[i]) : '');
510
+ const y = typeof series.y.data[i] === 'number' ? format.y.Format(series.y.data[i]) : '';
511
+ series.y.labels[i] = pattern.replace(/\bx\b/g, x).replace(/\by\b/g, y);
512
+ }
513
+ }
514
+ };
515
+ /**
516
+ * return quartiles. we use the Tukey hinge-style. See
517
+ *
518
+ * https://en.wikipedia.org/wiki/Quartile
519
+ *
520
+ * Specifically,
521
+ *
522
+ * - Use the median to divide the ordered data set into two halves. The median
523
+ * becomes the second quartiles.
524
+ *
525
+ * - If there are an odd number of data points in the original ordered data
526
+ * set, include the median (the central value in the ordered list) in both
527
+ * halves.
528
+ *
529
+ * - If there are an even number of data points in the original ordered data
530
+ * set, split this data set exactly in half.
531
+ *
532
+ * - The lower quartile value is the median of the lower half of the data. The
533
+ * upper quartile value is the median of the upper half of the data.
534
+ *
535
+ * @param data - must be sorted with no holes
536
+ */
537
+ export const BoxStats = (data) => {
538
+ // removed copying. still has 3 loops though.
539
+ const median = (data, start = 0, n = data.length) => {
540
+ if (n % 2) {
541
+ return data[Math.floor(n / 2) + start];
542
+ }
543
+ else {
544
+ return (data[n / 2 + start] + data[n / 2 - 1 + start]) / 2;
545
+ }
546
+ };
547
+ const n = data.length;
548
+ const quartiles = [0, median(data), 0];
549
+ if (n % 2) {
550
+ const floor = Math.floor(n / 2);
551
+ quartiles[0] = median(data, 0, Math.ceil(n / 2));
552
+ quartiles[2] = median(data, floor, data.length - floor);
553
+ }
554
+ else {
555
+ quartiles[0] = median(data, 0, n / 2);
556
+ quartiles[2] = median(data, n / 2, data.length - n / 2);
557
+ }
558
+ const iqr = quartiles[2] - quartiles[0];
559
+ const whiskers = [0, 0];
560
+ let sum = 0;
561
+ for (let i = 0; i < n; i++) {
562
+ sum += data[i];
563
+ }
564
+ for (let i = 0; i < n; i++) {
565
+ const pt = data[i];
566
+ if (pt >= quartiles[0] - iqr * 1.5) {
567
+ whiskers[0] = pt;
568
+ break;
569
+ }
570
+ }
571
+ for (let i = n - 1; i >= 0; i--) {
572
+ const pt = data[i];
573
+ if (pt <= quartiles[2] + iqr * 1.5) {
574
+ whiskers[1] = pt;
575
+ break;
576
+ }
577
+ }
578
+ return {
579
+ data,
580
+ quartiles,
581
+ whiskers,
582
+ iqr,
583
+ n,
584
+ mean: n ? sum / n : 0,
585
+ min: data[0],
586
+ max: data[n - 1],
587
+ };
588
+ };
589
+ //------------------------------------------------------------------------------
590
+ export const CreateBoxPlot = (args) => {
591
+ const series = TransformSeriesData(args[0]);
592
+ const common = CommonData(series, undefined, undefined, undefined, undefined, true);
593
+ let max_n = 0;
594
+ // change to min-max style
595
+ const minmax = !!args[2];
596
+ const stats = series.map(series => {
597
+ // const data = series.y.data.slice(0).filter((test): test is number => test !== undefined).sort((a, b) => a - b);
598
+ const data = [];
599
+ for (const entry of series.y.data) {
600
+ if (entry !== undefined) {
601
+ data.push(entry);
602
+ }
603
+ }
604
+ // data.sort((a, b) => a - b);
605
+ QuickSort(data);
606
+ const result = BoxStats(data);
607
+ max_n = Math.max(max_n, result.n);
608
+ if (minmax) {
609
+ result.whiskers[0] = result.min;
610
+ result.whiskers[1] = result.max;
611
+ }
612
+ return result;
613
+ });
614
+ const title = args[1]?.toString() || undefined;
615
+ const x_labels = [];
616
+ const series_names = [];
617
+ const format = NumberFormatCache.Get('#,##0');
618
+ for (const [index, entry] of stats.entries()) {
619
+ x_labels.push(format.Format(entry.n));
620
+ const s = series[index];
621
+ series_names.push(s.label || `Series ${index + 1}`);
622
+ }
623
+ const chart_data = {
624
+ type: 'box',
625
+ series,
626
+ title,
627
+ max_n,
628
+ data: stats,
629
+ x_labels,
630
+ series_names: series.some(test => !!test.label) ? series_names : undefined,
631
+ scale: common.y.scale,
632
+ y_labels: common.y.labels,
633
+ };
634
+ return chart_data;
635
+ };
636
+ //------------------------------------------------------------------------------
637
+ export const CreateBubbleChart = (args) => {
638
+ const series = TransformSeriesData(args[0]);
639
+ let y_floor = undefined;
640
+ let x_floor = undefined;
641
+ for (const entry of series) {
642
+ if (typeof entry.x.range?.min === 'number' && entry.x.range.min > 0 && entry.x.range.min < 50) {
643
+ x_floor = 0;
644
+ }
645
+ if (typeof entry.y.range?.min === 'number' && entry.y.range.min > 0 && entry.y.range.min < 50) {
646
+ y_floor = 0;
647
+ }
648
+ }
649
+ const common = CommonData(series, y_floor, undefined, x_floor);
650
+ const title = args[1]?.toString() || undefined;
651
+ // const options = args[2]?.toString() || undefined;
652
+ // console.info({ series, common, title, options });
653
+ const chart_data = {
654
+ legend: common.legend,
655
+ legend_style: LegendStyle.bubble,
656
+ type: 'bubble',
657
+ series,
658
+ title,
659
+ x_scale: common.x.scale,
660
+ x_labels: common.x.labels,
661
+ y_scale: common.y.scale,
662
+ y_labels: common.y.labels,
663
+ };
664
+ return chart_data;
665
+ /*
666
+ const [x, y, z] = [0,1,2].map(index => {
667
+ const arg = args[index];
668
+ if (arg.type === ValueType.array) {
669
+ return ArrayToSeries(arg).y;
670
+ }
671
+ return undefined;
672
+ });
673
+
674
+ let c: string[]|undefined = undefined;
675
+ if (Array.isArray(args[3])) {
676
+ c = Util.Flatten(args[3]).map(value => (value||'').toString());
677
+ }
678
+
679
+ const title = args[4]?.toString() || undefined;
680
+
681
+ // FIXME: need to pad out the axes by the values at the edges,
682
+ // so the whole circle is included in the chart area.
683
+
684
+ const [x_scale, y_scale] = [x, y].map(subseries => {
685
+
686
+ let series_min = 0;
687
+ let series_max = 1;
688
+ let first = false;
689
+
690
+ if (subseries?.data) {
691
+
692
+ for (const [index, value] of subseries.data.entries()) {
693
+ if (typeof value === 'number') {
694
+
695
+ if (!first) {
696
+ first = true;
697
+ series_min = value;
698
+ series_max = value;
699
+ }
700
+
701
+ const size = (z?.data?.[index]) || 0;
702
+ series_min = Math.min(series_min, value - size / 2);
703
+ series_max = Math.max(series_max, value + size / 2);
704
+ }
705
+ }
706
+ }
707
+
708
+ return Util.Scale(series_min, series_max, 7);
709
+
710
+ });
711
+
712
+ let x_labels: string[] | undefined;
713
+ let y_labels: string[] | undefined;
714
+
715
+ if (x?.format) {
716
+ x_labels = [];
717
+ const format = NumberFormatCache.Get(x.format);
718
+ for (let i = 0; i <= x_scale.count; i++) {
719
+ x_labels.push(format.Format(x_scale.min + i * x_scale.step));
720
+ }
721
+ }
722
+
723
+ if (y?.format) {
724
+ y_labels = [];
725
+ const format = NumberFormatCache.Get(y.format);
726
+ for (let i = 0; i <= y_scale.count; i++) {
727
+ y_labels.push(format.Format(y_scale.min + i * y_scale.step));
728
+ }
729
+ }
730
+
731
+ return {
732
+
733
+ type: 'bubble',
734
+
735
+ title,
736
+
737
+ x,
738
+ y,
739
+ z,
740
+ c,
741
+
742
+ x_scale,
743
+ y_scale,
744
+
745
+ x_labels,
746
+ y_labels,
747
+
748
+ };
749
+
750
+ */
751
+ };
752
+ /**
753
+ * args is [data, title, options]
754
+ *
755
+ * args[0] is the scatter data. this can be
756
+ *
757
+ * (1) set of Y values, with X not provided;
758
+ * (2) SERIES(label, X, Y) with Y required, others optional
759
+ * (3) GROUP(SERIES(label, X, Y), SERIES(label, X, Y), ...), with same rule for each series
760
+ *
761
+ * @param args
762
+ */
763
+ export const CreateScatterChart = (args, style = 'plot') => {
764
+ // FIXME: transform the data, then have this function
765
+ // operate on clean data. that way the transform can
766
+ // be reused (and the function can be reused without the
767
+ // transform).
768
+ const series = TransformSeriesData(args[0]);
769
+ const common = CommonData(series);
770
+ const title = args[1]?.toString() || undefined;
771
+ const options = args[2]?.toString() || undefined;
772
+ const chart_data = {
773
+ legend: common.legend,
774
+ style,
775
+ type: 'scatter2',
776
+ series, // : [{x, y}],
777
+ title,
778
+ x_scale: common.x.scale,
779
+ x_labels: common.x.labels,
780
+ y_scale: common.y.scale,
781
+ y_labels: common.y.labels,
782
+ y2_scale: common.y2?.scale,
783
+ y2_labels: common.y2?.labels,
784
+ lines: style === 'line', // true,
785
+ points: style === 'plot',
786
+ };
787
+ if (options) {
788
+ chart_data.markers = /marker/i.test(options);
789
+ chart_data.smooth = /smooth/i.test(options);
790
+ chart_data.data_labels = /labels/i.test(options);
791
+ let match = options.match(/labels="(.*?)"/);
792
+ if (match && chart_data.series) {
793
+ ApplyLabels(chart_data.series, match[1]);
794
+ }
795
+ else {
796
+ match = options.match(/labels=([^\s\r\n,]+)(?:\W|$)/);
797
+ if (match && chart_data.series) {
798
+ ApplyLabels(chart_data.series, match[1]);
799
+ }
800
+ }
801
+ match = options.match(/class=([\w_-]+)(?:\W|$)/);
802
+ if (match) {
803
+ chart_data.class_name = match[1];
804
+ }
805
+ }
806
+ return chart_data;
807
+ };
808
+ /**
809
+ * column/bar chart, now using common Series data and routines
810
+ *
811
+ * @param args arguments: data, categories, title, options
812
+ * @param type
813
+ */
814
+ export const CreateColumnChart = (args, type) => {
815
+ const [data, labels, args_title, args_options] = args;
816
+ const options = args_options?.toString() || undefined;
817
+ const stacked = /stacked/i.test(options || '');
818
+ let series = TransformSeriesData(data);
819
+ let common = CommonData(series);
820
+ let category_labels;
821
+ if (labels) {
822
+ const values = labels.type === ValueType.array ? Util.Flatten(labels.value) : Util.Flatten(labels);
823
+ category_labels = values.map((cell) => {
824
+ if (!cell || !cell.value) {
825
+ return '';
826
+ }
827
+ if (IsMetadata(cell)) {
828
+ if (typeof cell.value.value === 'number') {
829
+ const format = NumberFormatCache.Get(cell.value.format || DEFAULT_FORMAT);
830
+ return format.Format(cell.value.value);
831
+ }
832
+ return cell.value.value?.toString() || '';
833
+ }
834
+ if (typeof cell.value === 'number') {
835
+ const format = NumberFormatCache.Get(DEFAULT_FORMAT);
836
+ return format.Format(cell.value);
837
+ }
838
+ return cell.value.toString();
839
+ });
840
+ const count = series.reduce((a, entry) => Math.max(a, entry.y.data.length), 0);
841
+ if (count < category_labels.length) {
842
+ category_labels = category_labels.slice(0, count);
843
+ }
844
+ while (count > category_labels.length) {
845
+ category_labels.push('');
846
+ }
847
+ }
848
+ let stacked_series = undefined;
849
+ const legend = common.legend; // in case we munge it
850
+ if (stacked) {
851
+ stacked_series = series;
852
+ const map = new Map();
853
+ // const label_map: Map<number, string> = new Map();
854
+ for (const entry of series) {
855
+ for (const [index, key] of entry.x.data.entries()) {
856
+ if (key !== undefined) {
857
+ const value = entry.y.data[index] || 0;
858
+ map.set(key, value + (map.get(key) || 0));
859
+ }
860
+ }
861
+ }
862
+ const x_data = Array.from(map.keys()).sort((a, b) => a - b);
863
+ const y_data = x_data.map(key => map.get(key) || 0);
864
+ // console.info({stacked_series, map, x_data, y_data});
865
+ series = [{
866
+ x: { data: x_data, format: stacked_series[0]?.x?.format },
867
+ y: { data: y_data, format: stacked_series[0]?.y?.format },
868
+ }];
869
+ series[0].x.range = ArrayMinMax(x_data);
870
+ series[0].y.range = ArrayMinMax(y_data);
871
+ common = CommonData(series, Math.min(0, ...y_data));
872
+ }
873
+ const title = args_title?.toString() || undefined;
874
+ const chart_data = {
875
+ type,
876
+ legend, // legend: common.legend,
877
+ // legend_position: LegendPosition.right,
878
+ legend_style: LegendStyle.marker,
879
+ series2: series,
880
+ stacked_series,
881
+ scale: common.y.scale,
882
+ title,
883
+ y_labels: type === 'bar' ? category_labels : common.y.labels, // swapped
884
+ x_labels: type === 'bar' ? common.y.labels : category_labels, // swapped
885
+ };
886
+ if (options) {
887
+ chart_data.stacked = stacked;
888
+ chart_data.round = /round/i.test(options);
889
+ chart_data.data_labels = /labels/i.test(options);
890
+ let match = options.match(/labels="(.*?)"/);
891
+ if (match && series) {
892
+ ApplyLabels(series, match[1], category_labels);
893
+ }
894
+ else {
895
+ match = options.match(/labels=([^\s\r\n,]+)(?:\W|$)/);
896
+ if (match && series) {
897
+ ApplyLabels(series, match[1], category_labels);
898
+ }
899
+ }
900
+ match = options.match(/class=([\w_-]+)(?:\W|$)/);
901
+ if (match) {
902
+ chart_data.class_name = match[1];
903
+ }
904
+ }
905
+ return chart_data;
906
+ };
907
+ /**
908
+ * args: data, labels, title, callouts, "smooth"
909
+ */
910
+ export const CreateLineChart = (args, type) => {
911
+ const series = TransformSeriesData(args[0], args[1]);
912
+ const common = CommonData(series, 0, 0);
913
+ const title = args[2]?.toString() || undefined;
914
+ const options = args[3]?.toString() || undefined;
915
+ const chart_data = {
916
+ legend: common.legend,
917
+ // style: type, // 'line',
918
+ type: 'scatter2',
919
+ series, // : [{x, y}],
920
+ title,
921
+ x_scale: common.x.scale,
922
+ x_labels: common.x.labels,
923
+ y_scale: common.y.scale,
924
+ y_labels: common.y.labels,
925
+ lines: true,
926
+ filled: type === 'area',
927
+ };
928
+ if (options) {
929
+ // this.chart_data.markers = /marker/i.test(options);
930
+ chart_data.smooth = /smooth/i.test(options);
931
+ // this.chart_data.data_labels = /labels/i.test(options);
932
+ const match = options.match(/class=([\w_-]+)(?:\W|$)/);
933
+ if (match) {
934
+ chart_data.class_name = match[1];
935
+ }
936
+ }
937
+ return chart_data;
938
+ };
939
+ /**
940
+ * arguments are values, labels, title, sort, label option, ...
941
+ */
942
+ export const CreateDonut = (args, pie_chart = false) => {
943
+ const [_a, _c, title, _options, _slice_title] = args;
944
+ const raw_data = args[0]?.type === ValueType.array ? args[0].value : args[0];
945
+ const flat = raw_data ? Util.Flatten(raw_data) : [];
946
+ // we still need the aggregate for range, scale
947
+ // let data = flat.map((x) => (typeof x.value.value === 'number') ? x.value.value : undefined) as number[];
948
+ let data = flat.map(cell => {
949
+ if (IsMetadata(cell)) {
950
+ if (typeof cell.value.value === 'number') {
951
+ return cell.value.value;
952
+ }
953
+ }
954
+ return undefined;
955
+ });
956
+ // if labels are strings, just pass them in. if they're numbers then
957
+ // use the format (we're collecting metadata for this field now)
958
+ const raw_labels = args[1]?.type === ValueType.array ? args[1].value : args[1];
959
+ const labels = Util.Flatten(raw_labels || []).map(label => {
960
+ if (IsMetadata(label)) {
961
+ if (typeof label.value.value === 'number' && label.value.format) {
962
+ return NumberFormatCache.Get(label.value.format).Format(label.value.value);
963
+ }
964
+ else
965
+ return label.value.value?.toString() || '';
966
+ }
967
+ return label.value?.toString() || '';
968
+ });
969
+ // no negative numbers
970
+ let warned = false;
971
+ data = data.map((check) => {
972
+ if (check && check < 0) {
973
+ if (!warned) {
974
+ console.warn('pie/donut chart does not support negative values (omitted)');
975
+ warned = true;
976
+ }
977
+ return 0;
978
+ }
979
+ return check;
980
+ });
981
+ let sum = 0;
982
+ const slices = data.map((value, i) => {
983
+ if (typeof value !== 'undefined')
984
+ sum += value;
985
+ return {
986
+ value: value || 0,
987
+ label: labels[i] || '',
988
+ index: i + 1,
989
+ percent: 0,
990
+ };
991
+ });
992
+ if (sum) {
993
+ for (const slice of slices) {
994
+ slice.percent = (slice.value || 0) / sum;
995
+ }
996
+ }
997
+ // titles? label/value/percent
998
+ // FIXME: number format(s)
999
+ let format_pattern = '';
1000
+ for (const value of flat) {
1001
+ if (IsMetadata(value)) {
1002
+ format_pattern = value.value.format || '';
1003
+ break;
1004
+ }
1005
+ }
1006
+ // const format_pattern = (flat.length && flat[0].value?.format) ? flat[0].value.format : '';
1007
+ const format = NumberFormatCache.Get(format_pattern || DEFAULT_FORMAT);
1008
+ const percent_format = NumberFormatCache.Get('percent');
1009
+ // ensure label if we have labels array but no label format string
1010
+ if (typeof args[4] === 'undefined' && args[1]) {
1011
+ args[4] = 'label';
1012
+ }
1013
+ const slice_title = (args[4] || '');
1014
+ if (slice_title) {
1015
+ for (const slice of slices) {
1016
+ const value = /*NumberFormatCache.Get('general')*/ format.Format(slice.value || 0);
1017
+ const percent = percent_format.Format(slice.percent);
1018
+ slice.title = slice_title
1019
+ .replace(/value%/ig, percent_format.Format(slice.value || 0))
1020
+ .replace(/value/ig, value)
1021
+ .replace(/percent/ig, percent)
1022
+ .replace(/label/ig, slice.label || '')
1023
+ .trim();
1024
+ }
1025
+ }
1026
+ // optionally sort...
1027
+ // old-style...
1028
+ let sort = (_options || '').toUpperCase();
1029
+ if (sort === 'ASC' || sort === 'ASCENDING' || sort === 'INC') {
1030
+ slices.sort((a, b) => { return (a.value || 0) - (b.value || 0); });
1031
+ }
1032
+ else if (sort === 'DESC' || sort === 'DESCENDING' || sort === 'DEC') {
1033
+ slices.sort((a, b) => { return (b.value || 0) - (a.value || 0); });
1034
+ }
1035
+ else {
1036
+ const match = (_options || '').match(/sort=([\w]+)(?:\W|$)/i);
1037
+ if (match) {
1038
+ sort = match[1];
1039
+ if (/^(asc|inc)/i.test(sort)) {
1040
+ slices.sort((a, b) => { return (a.value || 0) - (b.value || 0); });
1041
+ }
1042
+ else if (/^(desc|dec)/i.test(sort)) {
1043
+ slices.sort((a, b) => { return (b.value || 0) - (a.value || 0); });
1044
+ }
1045
+ }
1046
+ }
1047
+ const chart_data = {
1048
+ type: pie_chart ? 'pie' : 'donut',
1049
+ slices,
1050
+ title: title || '',
1051
+ };
1052
+ if (_options) {
1053
+ const match = _options.match(/class=([_-\w]+)(?:\W|$)/);
1054
+ if (match) {
1055
+ chart_data.class_name = match[1];
1056
+ }
1057
+ }
1058
+ return chart_data;
1059
+ };
1060
+ //# sourceMappingURL=chart-utils.js.map