@formant/ava 3.4.1-formant

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 (534) hide show
  1. package/README.md +72 -0
  2. package/dist/ava.min.js +1 -0
  3. package/esm/advisor/advise-pipeline/advicesForChart.js +68 -0
  4. package/esm/advisor/advise-pipeline/data-to-advices.js +241 -0
  5. package/esm/advisor/advise-pipeline/index.js +1 -0
  6. package/esm/advisor/advise-pipeline/spec-mapping.js +500 -0
  7. package/esm/advisor/advisor.js +35 -0
  8. package/esm/advisor/constants.js +13 -0
  9. package/esm/advisor/index.js +2 -0
  10. package/esm/advisor/lint-pipeline/check-rules.js +43 -0
  11. package/esm/advisor/lint-pipeline/getChartType.js +109 -0
  12. package/esm/advisor/lint-pipeline/index.js +0 -0
  13. package/esm/advisor/lint-pipeline/lintRules.js +32 -0
  14. package/esm/advisor/ruler/index.js +74 -0
  15. package/esm/advisor/ruler/rules/aggregation-single-row.js +21 -0
  16. package/esm/advisor/ruler/rules/all-can-be-table.js +17 -0
  17. package/esm/advisor/ruler/rules/bar-series-qty.js +36 -0
  18. package/esm/advisor/ruler/rules/bar-without-axis-min.js +41 -0
  19. package/esm/advisor/ruler/rules/constants.js +6 -0
  20. package/esm/advisor/ruler/rules/data-check.js +40 -0
  21. package/esm/advisor/ruler/rules/data-field-qty.js +26 -0
  22. package/esm/advisor/ruler/rules/diff-pie-sector.js +33 -0
  23. package/esm/advisor/ruler/rules/index.js +68 -0
  24. package/esm/advisor/ruler/rules/landscape-or-portrait.js +40 -0
  25. package/esm/advisor/ruler/rules/limit-series.js +47 -0
  26. package/esm/advisor/ruler/rules/line-field-time-ordinal.js +25 -0
  27. package/esm/advisor/ruler/rules/no-redundant-field.js +32 -0
  28. package/esm/advisor/ruler/rules/nominal-enum-combinatorial.js +54 -0
  29. package/esm/advisor/ruler/rules/purpose-check.js +27 -0
  30. package/esm/advisor/ruler/rules/series-qty-limit.js +34 -0
  31. package/esm/advisor/ruler/rules/x-axis-line-fading.js +41 -0
  32. package/esm/advisor/ruler/types.js +1 -0
  33. package/esm/advisor/ruler/utils.js +54 -0
  34. package/esm/advisor/types.js +1 -0
  35. package/esm/advisor/utils/clone.js +32 -0
  36. package/esm/advisor/utils/compare.js +14 -0
  37. package/esm/advisor/utils/computeScore.js +25 -0
  38. package/esm/advisor/utils/deep-mix.js +76 -0
  39. package/esm/advisor/utils/hasSubset.js +3 -0
  40. package/esm/advisor/utils/index.js +8 -0
  41. package/esm/advisor/utils/inferDataType.js +70 -0
  42. package/esm/advisor/utils/intersects.js +3 -0
  43. package/esm/advisor/utils/isNil.js +4 -0
  44. package/esm/ckb/base.js +1310 -0
  45. package/esm/ckb/ckb.js +55 -0
  46. package/esm/ckb/constants.js +197 -0
  47. package/esm/ckb/i18n/index.js +23 -0
  48. package/esm/ckb/i18n/types.js +1 -0
  49. package/esm/ckb/i18n/zh-CN.js +525 -0
  50. package/esm/ckb/index.js +14 -0
  51. package/esm/ckb/types.js +1 -0
  52. package/esm/common/types.js +1 -0
  53. package/esm/data/analysis/field/index.js +336 -0
  54. package/esm/data/analysis/field/types.js +1 -0
  55. package/esm/data/analysis/graph/index.js +170 -0
  56. package/esm/data/analysis/graph/types.js +1 -0
  57. package/esm/data/analysis/index.js +1 -0
  58. package/esm/data/analysis/types.js +1 -0
  59. package/esm/data/dataset/field/baseFrame.js +76 -0
  60. package/esm/data/dataset/field/dataFrame.js +556 -0
  61. package/esm/data/dataset/field/index.js +3 -0
  62. package/esm/data/dataset/field/series.js +149 -0
  63. package/esm/data/dataset/field/types.js +1 -0
  64. package/esm/data/dataset/field/utils.js +58 -0
  65. package/esm/data/dataset/graph/index.js +186 -0
  66. package/esm/data/dataset/graph/types.js +1 -0
  67. package/esm/data/dataset/graph/utils.js +15 -0
  68. package/esm/data/dataset/index.js +1 -0
  69. package/esm/data/dataset/types.js +1 -0
  70. package/esm/data/index.js +5 -0
  71. package/esm/data/statistics/IQR.js +49 -0
  72. package/esm/data/statistics/base.js +248 -0
  73. package/esm/data/statistics/bayesian.js +25 -0
  74. package/esm/data/statistics/buishand-u.js +19 -0
  75. package/esm/data/statistics/caches.js +28 -0
  76. package/esm/data/statistics/cdf.js +25 -0
  77. package/esm/data/statistics/constants.js +12 -0
  78. package/esm/data/statistics/index.js +7 -0
  79. package/esm/data/statistics/lowess.js +80 -0
  80. package/esm/data/statistics/mannkendall-test.js +50 -0
  81. package/esm/data/statistics/maxabs.js +9 -0
  82. package/esm/data/statistics/pcorrtest.js +76 -0
  83. package/esm/data/statistics/pettitt-test.js +33 -0
  84. package/esm/data/statistics/quantile.js +56 -0
  85. package/esm/data/statistics/types.js +1 -0
  86. package/esm/data/statistics/vector.js +67 -0
  87. package/esm/data/statistics/window.js +55 -0
  88. package/esm/data/types.js +2 -0
  89. package/esm/data/utils/common.js +58 -0
  90. package/esm/data/utils/index.js +5 -0
  91. package/esm/data/utils/isType/constants.js +24 -0
  92. package/esm/data/utils/isType/index.js +2 -0
  93. package/esm/data/utils/isType/isDateString.js +104 -0
  94. package/esm/data/utils/isType/isType.js +78 -0
  95. package/esm/index.js +11 -0
  96. package/esm/insight/algorithms/base/compare.js +40 -0
  97. package/esm/insight/algorithms/categoryOutlier.js +4 -0
  98. package/esm/insight/algorithms/changePoint.js +10 -0
  99. package/esm/insight/algorithms/index.js +3 -0
  100. package/esm/insight/algorithms/trendDirection.js +4 -0
  101. package/esm/insight/chart/constants.js +25 -0
  102. package/esm/insight/chart/generator/homogeneous.js +70 -0
  103. package/esm/insight/chart/generator/index.js +2 -0
  104. package/esm/insight/chart/generator/insights.js +16 -0
  105. package/esm/insight/chart/index.js +4 -0
  106. package/esm/insight/chart/strategy/augmentedMarks/categoryOutlier.js +30 -0
  107. package/esm/insight/chart/strategy/augmentedMarks/changePoint.js +42 -0
  108. package/esm/insight/chart/strategy/augmentedMarks/correlation.js +6 -0
  109. package/esm/insight/chart/strategy/augmentedMarks/homogeneous.js +5 -0
  110. package/esm/insight/chart/strategy/augmentedMarks/index.js +8 -0
  111. package/esm/insight/chart/strategy/augmentedMarks/lowVariance.js +23 -0
  112. package/esm/insight/chart/strategy/augmentedMarks/majority.js +5 -0
  113. package/esm/insight/chart/strategy/augmentedMarks/timeSeriesOutlier.js +82 -0
  114. package/esm/insight/chart/strategy/augmentedMarks/trend.js +26 -0
  115. package/esm/insight/chart/strategy/chart.js +45 -0
  116. package/esm/insight/chart/strategy/commonMarks/areaMark.js +12 -0
  117. package/esm/insight/chart/strategy/commonMarks/index.js +5 -0
  118. package/esm/insight/chart/strategy/commonMarks/intervalMark.js +14 -0
  119. package/esm/insight/chart/strategy/commonMarks/lineMark.js +34 -0
  120. package/esm/insight/chart/strategy/commonMarks/pointMark.js +17 -0
  121. package/esm/insight/chart/strategy/commonMarks/textMark.js +28 -0
  122. package/esm/insight/chart/strategy/index.js +4 -0
  123. package/esm/insight/chart/strategy/viewSpec.js +16 -0
  124. package/esm/insight/chart/types.js +1 -0
  125. package/esm/insight/chart/utils.js +4 -0
  126. package/esm/insight/constant.js +21 -0
  127. package/esm/insight/index.js +5 -0
  128. package/esm/insight/insights/checkers.js +97 -0
  129. package/esm/insight/insights/extractors/categoryOutlier.js +90 -0
  130. package/esm/insight/insights/extractors/changePoint.js +55 -0
  131. package/esm/insight/insights/extractors/correlation.js +38 -0
  132. package/esm/insight/insights/extractors/homogeneous.js +98 -0
  133. package/esm/insight/insights/extractors/lowVariance.js +49 -0
  134. package/esm/insight/insights/extractors/majority.js +66 -0
  135. package/esm/insight/insights/extractors/timeSeriesOutlier.js +61 -0
  136. package/esm/insight/insights/extractors/trend.js +49 -0
  137. package/esm/insight/insights/index.js +28 -0
  138. package/esm/insight/insights/util.js +77 -0
  139. package/esm/insight/narrative/factory.js +22 -0
  140. package/esm/insight/narrative/index.js +14 -0
  141. package/esm/insight/narrative/strategy/base.js +6 -0
  142. package/esm/insight/narrative/strategy/categoryOutlier.js +74 -0
  143. package/esm/insight/narrative/strategy/changePoint.js +52 -0
  144. package/esm/insight/narrative/strategy/commonness.js +45 -0
  145. package/esm/insight/narrative/strategy/correlation.js +51 -0
  146. package/esm/insight/narrative/strategy/exception.js +70 -0
  147. package/esm/insight/narrative/strategy/helpers.js +25 -0
  148. package/esm/insight/narrative/strategy/index.js +13 -0
  149. package/esm/insight/narrative/strategy/lowVariance.js +48 -0
  150. package/esm/insight/narrative/strategy/majority.js +62 -0
  151. package/esm/insight/narrative/strategy/timeSeriesOutlier.js +92 -0
  152. package/esm/insight/narrative/strategy/trend.js +57 -0
  153. package/esm/insight/pipeline/extract.js +236 -0
  154. package/esm/insight/pipeline/index.js +11 -0
  155. package/esm/insight/pipeline/insight.js +81 -0
  156. package/esm/insight/pipeline/preprocess.js +33 -0
  157. package/esm/insight/pipeline/specificInsight.js +71 -0
  158. package/esm/insight/pipeline/util.js +14 -0
  159. package/esm/insight/pipeline/visualize.js +41 -0
  160. package/esm/insight/types.js +1 -0
  161. package/esm/insight/utils/aggregate.js +87 -0
  162. package/esm/insight/utils/common.js +35 -0
  163. package/esm/ntv/generate/generateTextSpec.js +157 -0
  164. package/esm/ntv/generate/index.js +5 -0
  165. package/esm/ntv/generate/types.js +1 -0
  166. package/esm/ntv/generate/utils.js +86 -0
  167. package/esm/ntv/index.js +4 -0
  168. package/esm/ntv/schema/common.js +1 -0
  169. package/esm/ntv/schema/index.js +4 -0
  170. package/esm/ntv/schema/paragraph.js +1 -0
  171. package/esm/ntv/schema/phrase.js +52 -0
  172. package/esm/ntv/schema/structure.js +1 -0
  173. package/esm/ntv/types.js +1 -0
  174. package/esm/ntv/utils/index.js +1 -0
  175. package/esm/ntv/utils/isSpecType.js +58 -0
  176. package/esm/utils/arr2map.js +7 -0
  177. package/esm/utils/dataFormat.js +32 -0
  178. package/esm/utils/index.js +3 -0
  179. package/esm/utils/isType.js +14 -0
  180. package/lib/advisor/advise-pipeline/advicesForChart.d.ts +13 -0
  181. package/lib/advisor/advise-pipeline/advicesForChart.js +73 -0
  182. package/lib/advisor/advise-pipeline/data-to-advices.d.ts +22 -0
  183. package/lib/advisor/advise-pipeline/data-to-advices.js +245 -0
  184. package/lib/advisor/advise-pipeline/index.d.ts +1 -0
  185. package/lib/advisor/advise-pipeline/index.js +5 -0
  186. package/lib/advisor/advise-pipeline/spec-mapping.d.ts +14 -0
  187. package/lib/advisor/advise-pipeline/spec-mapping.js +504 -0
  188. package/lib/advisor/advisor.d.ts +18 -0
  189. package/lib/advisor/advisor.js +38 -0
  190. package/lib/advisor/constants.d.ts +1 -0
  191. package/lib/advisor/constants.js +16 -0
  192. package/lib/advisor/index.d.ts +2 -0
  193. package/lib/advisor/index.js +7 -0
  194. package/lib/advisor/lint-pipeline/check-rules.d.ts +4 -0
  195. package/lib/advisor/lint-pipeline/check-rules.js +47 -0
  196. package/lib/advisor/lint-pipeline/getChartType.d.ts +7 -0
  197. package/lib/advisor/lint-pipeline/getChartType.js +113 -0
  198. package/lib/advisor/lint-pipeline/index.d.ts +0 -0
  199. package/lib/advisor/lint-pipeline/index.js +0 -0
  200. package/lib/advisor/lint-pipeline/lintRules.d.ts +5 -0
  201. package/lib/advisor/lint-pipeline/lintRules.js +36 -0
  202. package/lib/advisor/ruler/index.d.ts +21 -0
  203. package/lib/advisor/ruler/index.js +80 -0
  204. package/lib/advisor/ruler/rules/aggregation-single-row.d.ts +2 -0
  205. package/lib/advisor/ruler/rules/aggregation-single-row.js +24 -0
  206. package/lib/advisor/ruler/rules/all-can-be-table.d.ts +2 -0
  207. package/lib/advisor/ruler/rules/all-can-be-table.js +20 -0
  208. package/lib/advisor/ruler/rules/bar-series-qty.d.ts +2 -0
  209. package/lib/advisor/ruler/rules/bar-series-qty.js +39 -0
  210. package/lib/advisor/ruler/rules/bar-without-axis-min.d.ts +2 -0
  211. package/lib/advisor/ruler/rules/bar-without-axis-min.js +44 -0
  212. package/lib/advisor/ruler/rules/constants.d.ts +6 -0
  213. package/lib/advisor/ruler/rules/constants.js +9 -0
  214. package/lib/advisor/ruler/rules/data-check.d.ts +2 -0
  215. package/lib/advisor/ruler/rules/data-check.js +43 -0
  216. package/lib/advisor/ruler/rules/data-field-qty.d.ts +2 -0
  217. package/lib/advisor/ruler/rules/data-field-qty.js +29 -0
  218. package/lib/advisor/ruler/rules/diff-pie-sector.d.ts +2 -0
  219. package/lib/advisor/ruler/rules/diff-pie-sector.js +36 -0
  220. package/lib/advisor/ruler/rules/index.d.ts +19 -0
  221. package/lib/advisor/ruler/rules/index.js +71 -0
  222. package/lib/advisor/ruler/rules/landscape-or-portrait.d.ts +2 -0
  223. package/lib/advisor/ruler/rules/landscape-or-portrait.js +43 -0
  224. package/lib/advisor/ruler/rules/limit-series.d.ts +2 -0
  225. package/lib/advisor/ruler/rules/limit-series.js +50 -0
  226. package/lib/advisor/ruler/rules/line-field-time-ordinal.d.ts +2 -0
  227. package/lib/advisor/ruler/rules/line-field-time-ordinal.js +28 -0
  228. package/lib/advisor/ruler/rules/no-redundant-field.d.ts +2 -0
  229. package/lib/advisor/ruler/rules/no-redundant-field.js +35 -0
  230. package/lib/advisor/ruler/rules/nominal-enum-combinatorial.d.ts +2 -0
  231. package/lib/advisor/ruler/rules/nominal-enum-combinatorial.js +57 -0
  232. package/lib/advisor/ruler/rules/purpose-check.d.ts +2 -0
  233. package/lib/advisor/ruler/rules/purpose-check.js +30 -0
  234. package/lib/advisor/ruler/rules/series-qty-limit.d.ts +2 -0
  235. package/lib/advisor/ruler/rules/series-qty-limit.js +37 -0
  236. package/lib/advisor/ruler/rules/x-axis-line-fading.d.ts +2 -0
  237. package/lib/advisor/ruler/rules/x-axis-line-fading.js +44 -0
  238. package/lib/advisor/ruler/types.d.ts +125 -0
  239. package/lib/advisor/ruler/types.js +2 -0
  240. package/lib/advisor/ruler/utils.d.ts +10 -0
  241. package/lib/advisor/ruler/utils.js +61 -0
  242. package/lib/advisor/types.d.ts +218 -0
  243. package/lib/advisor/types.js +4 -0
  244. package/lib/advisor/utils/clone.d.ts +2 -0
  245. package/lib/advisor/utils/clone.js +34 -0
  246. package/lib/advisor/utils/compare.d.ts +3 -0
  247. package/lib/advisor/utils/compare.js +17 -0
  248. package/lib/advisor/utils/computeScore.d.ts +7 -0
  249. package/lib/advisor/utils/computeScore.js +27 -0
  250. package/lib/advisor/utils/deep-mix.d.ts +2 -0
  251. package/lib/advisor/utils/deep-mix.js +78 -0
  252. package/lib/advisor/utils/hasSubset.d.ts +1 -0
  253. package/lib/advisor/utils/hasSubset.js +7 -0
  254. package/lib/advisor/utils/index.d.ts +5 -0
  255. package/lib/advisor/utils/index.js +19 -0
  256. package/lib/advisor/utils/inferDataType.d.ts +6 -0
  257. package/lib/advisor/utils/inferDataType.js +75 -0
  258. package/lib/advisor/utils/intersects.d.ts +1 -0
  259. package/lib/advisor/utils/intersects.js +7 -0
  260. package/lib/advisor/utils/isNil.d.ts +2 -0
  261. package/lib/advisor/utils/isNil.js +6 -0
  262. package/lib/ckb/base.d.ts +2 -0
  263. package/lib/ckb/base.js +1313 -0
  264. package/lib/ckb/ckb.d.ts +8 -0
  265. package/lib/ckb/ckb.js +59 -0
  266. package/lib/ckb/constants.d.ts +79 -0
  267. package/lib/ckb/constants.js +200 -0
  268. package/lib/ckb/i18n/index.d.ts +10 -0
  269. package/lib/ckb/i18n/index.js +27 -0
  270. package/lib/ckb/i18n/types.d.ts +52 -0
  271. package/lib/ckb/i18n/types.js +2 -0
  272. package/lib/ckb/i18n/zh-CN.d.ts +7 -0
  273. package/lib/ckb/i18n/zh-CN.js +528 -0
  274. package/lib/ckb/index.d.ts +4 -0
  275. package/lib/ckb/index.js +20 -0
  276. package/lib/ckb/types.d.ts +185 -0
  277. package/lib/ckb/types.js +2 -0
  278. package/lib/common/types.d.ts +14 -0
  279. package/lib/common/types.js +2 -0
  280. package/lib/data/analysis/field/index.d.ts +79 -0
  281. package/lib/data/analysis/field/index.js +355 -0
  282. package/lib/data/analysis/field/types.d.ts +99 -0
  283. package/lib/data/analysis/field/types.js +2 -0
  284. package/lib/data/analysis/graph/index.d.ts +28 -0
  285. package/lib/data/analysis/graph/index.js +178 -0
  286. package/lib/data/analysis/graph/types.d.ts +62 -0
  287. package/lib/data/analysis/graph/types.js +2 -0
  288. package/lib/data/analysis/index.d.ts +1 -0
  289. package/lib/data/analysis/index.js +5 -0
  290. package/lib/data/analysis/types.d.ts +1 -0
  291. package/lib/data/analysis/types.js +2 -0
  292. package/lib/data/dataset/field/baseFrame.d.ts +30 -0
  293. package/lib/data/dataset/field/baseFrame.js +78 -0
  294. package/lib/data/dataset/field/dataFrame.d.ts +35 -0
  295. package/lib/data/dataset/field/dataFrame.js +558 -0
  296. package/lib/data/dataset/field/index.d.ts +3 -0
  297. package/lib/data/dataset/field/index.js +8 -0
  298. package/lib/data/dataset/field/series.d.ts +18 -0
  299. package/lib/data/dataset/field/series.js +151 -0
  300. package/lib/data/dataset/field/types.d.ts +54 -0
  301. package/lib/data/dataset/field/types.js +2 -0
  302. package/lib/data/dataset/field/utils.d.ts +13 -0
  303. package/lib/data/dataset/field/utils.js +68 -0
  304. package/lib/data/dataset/graph/index.d.ts +18 -0
  305. package/lib/data/dataset/graph/index.js +188 -0
  306. package/lib/data/dataset/graph/types.d.ts +35 -0
  307. package/lib/data/dataset/graph/types.js +2 -0
  308. package/lib/data/dataset/graph/utils.d.ts +1 -0
  309. package/lib/data/dataset/graph/utils.js +19 -0
  310. package/lib/data/dataset/index.d.ts +1 -0
  311. package/lib/data/dataset/index.js +4 -0
  312. package/lib/data/dataset/types.d.ts +1 -0
  313. package/lib/data/dataset/types.js +4 -0
  314. package/lib/data/index.d.ts +5 -0
  315. package/lib/data/index.js +8 -0
  316. package/lib/data/statistics/IQR.d.ts +21 -0
  317. package/lib/data/statistics/IQR.js +53 -0
  318. package/lib/data/statistics/base.d.ts +106 -0
  319. package/lib/data/statistics/base.js +271 -0
  320. package/lib/data/statistics/bayesian.d.ts +5 -0
  321. package/lib/data/statistics/bayesian.js +30 -0
  322. package/lib/data/statistics/buishand-u.d.ts +7 -0
  323. package/lib/data/statistics/buishand-u.js +23 -0
  324. package/lib/data/statistics/caches.d.ts +13 -0
  325. package/lib/data/statistics/caches.js +33 -0
  326. package/lib/data/statistics/cdf.d.ts +7 -0
  327. package/lib/data/statistics/cdf.js +29 -0
  328. package/lib/data/statistics/constants.d.ts +5 -0
  329. package/lib/data/statistics/constants.js +15 -0
  330. package/lib/data/statistics/index.d.ts +7 -0
  331. package/lib/data/statistics/index.js +14 -0
  332. package/lib/data/statistics/lowess.d.ts +10 -0
  333. package/lib/data/statistics/lowess.js +87 -0
  334. package/lib/data/statistics/mannkendall-test.d.ts +15 -0
  335. package/lib/data/statistics/mannkendall-test.js +54 -0
  336. package/lib/data/statistics/maxabs.d.ts +5 -0
  337. package/lib/data/statistics/maxabs.js +13 -0
  338. package/lib/data/statistics/pcorrtest.d.ts +3 -0
  339. package/lib/data/statistics/pcorrtest.js +80 -0
  340. package/lib/data/statistics/pettitt-test.d.ts +9 -0
  341. package/lib/data/statistics/pettitt-test.js +38 -0
  342. package/lib/data/statistics/quantile.d.ts +16 -0
  343. package/lib/data/statistics/quantile.js +61 -0
  344. package/lib/data/statistics/types.d.ts +70 -0
  345. package/lib/data/statistics/types.js +2 -0
  346. package/lib/data/statistics/vector.d.ts +15 -0
  347. package/lib/data/statistics/vector.js +78 -0
  348. package/lib/data/statistics/window.d.ts +12 -0
  349. package/lib/data/statistics/window.js +60 -0
  350. package/lib/data/types.d.ts +2 -0
  351. package/lib/data/types.js +5 -0
  352. package/lib/data/utils/common.d.ts +26 -0
  353. package/lib/data/utils/common.js +67 -0
  354. package/lib/data/utils/index.d.ts +2 -0
  355. package/lib/data/utils/index.js +8 -0
  356. package/lib/data/utils/isType/constants.d.ts +15 -0
  357. package/lib/data/utils/isType/constants.js +27 -0
  358. package/lib/data/utils/isType/index.d.ts +2 -0
  359. package/lib/data/utils/isType/index.js +5 -0
  360. package/lib/data/utils/isType/isDateString.d.ts +18 -0
  361. package/lib/data/utils/isType/isDateString.js +111 -0
  362. package/lib/data/utils/isType/isType.d.ts +13 -0
  363. package/lib/data/utils/isType/isType.js +94 -0
  364. package/lib/index.d.ts +10 -0
  365. package/lib/index.js +75 -0
  366. package/lib/insight/algorithms/base/compare.d.ts +14 -0
  367. package/lib/insight/algorithms/base/compare.js +45 -0
  368. package/lib/insight/algorithms/categoryOutlier.d.ts +4 -0
  369. package/lib/insight/algorithms/categoryOutlier.js +7 -0
  370. package/lib/insight/algorithms/changePoint.d.ts +10 -0
  371. package/lib/insight/algorithms/changePoint.js +13 -0
  372. package/lib/insight/algorithms/index.d.ts +3 -0
  373. package/lib/insight/algorithms/index.js +6 -0
  374. package/lib/insight/algorithms/trendDirection.d.ts +4 -0
  375. package/lib/insight/algorithms/trendDirection.js +7 -0
  376. package/lib/insight/chart/constants.d.ts +13 -0
  377. package/lib/insight/chart/constants.js +28 -0
  378. package/lib/insight/chart/generator/homogeneous.d.ts +3 -0
  379. package/lib/insight/chart/generator/homogeneous.js +75 -0
  380. package/lib/insight/chart/generator/index.d.ts +2 -0
  381. package/lib/insight/chart/generator/index.js +5 -0
  382. package/lib/insight/chart/generator/insights.d.ts +3 -0
  383. package/lib/insight/chart/generator/insights.js +20 -0
  384. package/lib/insight/chart/index.d.ts +4 -0
  385. package/lib/insight/chart/index.js +7 -0
  386. package/lib/insight/chart/strategy/augmentedMarks/categoryOutlier.d.ts +5 -0
  387. package/lib/insight/chart/strategy/augmentedMarks/categoryOutlier.js +35 -0
  388. package/lib/insight/chart/strategy/augmentedMarks/changePoint.d.ts +5 -0
  389. package/lib/insight/chart/strategy/augmentedMarks/changePoint.js +47 -0
  390. package/lib/insight/chart/strategy/augmentedMarks/correlation.d.ts +3 -0
  391. package/lib/insight/chart/strategy/augmentedMarks/correlation.js +10 -0
  392. package/lib/insight/chart/strategy/augmentedMarks/homogeneous.d.ts +3 -0
  393. package/lib/insight/chart/strategy/augmentedMarks/homogeneous.js +9 -0
  394. package/lib/insight/chart/strategy/augmentedMarks/index.d.ts +8 -0
  395. package/lib/insight/chart/strategy/augmentedMarks/index.js +24 -0
  396. package/lib/insight/chart/strategy/augmentedMarks/lowVariance.d.ts +5 -0
  397. package/lib/insight/chart/strategy/augmentedMarks/lowVariance.js +28 -0
  398. package/lib/insight/chart/strategy/augmentedMarks/majority.d.ts +3 -0
  399. package/lib/insight/chart/strategy/augmentedMarks/majority.js +9 -0
  400. package/lib/insight/chart/strategy/augmentedMarks/timeSeriesOutlier.d.ts +5 -0
  401. package/lib/insight/chart/strategy/augmentedMarks/timeSeriesOutlier.js +87 -0
  402. package/lib/insight/chart/strategy/augmentedMarks/trend.d.ts +5 -0
  403. package/lib/insight/chart/strategy/augmentedMarks/trend.js +31 -0
  404. package/lib/insight/chart/strategy/chart.d.ts +7 -0
  405. package/lib/insight/chart/strategy/chart.js +49 -0
  406. package/lib/insight/chart/strategy/commonMarks/areaMark.d.ts +3 -0
  407. package/lib/insight/chart/strategy/commonMarks/areaMark.js +16 -0
  408. package/lib/insight/chart/strategy/commonMarks/index.d.ts +5 -0
  409. package/lib/insight/chart/strategy/commonMarks/index.js +13 -0
  410. package/lib/insight/chart/strategy/commonMarks/intervalMark.d.ts +5 -0
  411. package/lib/insight/chart/strategy/commonMarks/intervalMark.js +18 -0
  412. package/lib/insight/chart/strategy/commonMarks/lineMark.d.ts +3 -0
  413. package/lib/insight/chart/strategy/commonMarks/lineMark.js +38 -0
  414. package/lib/insight/chart/strategy/commonMarks/pointMark.d.ts +5 -0
  415. package/lib/insight/chart/strategy/commonMarks/pointMark.js +21 -0
  416. package/lib/insight/chart/strategy/commonMarks/textMark.d.ts +5 -0
  417. package/lib/insight/chart/strategy/commonMarks/textMark.js +32 -0
  418. package/lib/insight/chart/strategy/index.d.ts +4 -0
  419. package/lib/insight/chart/strategy/index.js +10 -0
  420. package/lib/insight/chart/strategy/viewSpec.d.ts +3 -0
  421. package/lib/insight/chart/strategy/viewSpec.js +20 -0
  422. package/lib/insight/chart/types.d.ts +60 -0
  423. package/lib/insight/chart/types.js +2 -0
  424. package/lib/insight/chart/utils.d.ts +3 -0
  425. package/lib/insight/chart/utils.js +8 -0
  426. package/lib/insight/constant.d.ts +12 -0
  427. package/lib/insight/constant.js +24 -0
  428. package/lib/insight/index.d.ts +6 -0
  429. package/lib/insight/index.js +13 -0
  430. package/lib/insight/insights/checkers.d.ts +16 -0
  431. package/lib/insight/insights/checkers.js +107 -0
  432. package/lib/insight/insights/extractors/categoryOutlier.d.ts +12 -0
  433. package/lib/insight/insights/extractors/categoryOutlier.js +95 -0
  434. package/lib/insight/insights/extractors/changePoint.d.ts +8 -0
  435. package/lib/insight/insights/extractors/changePoint.js +60 -0
  436. package/lib/insight/insights/extractors/correlation.d.ts +9 -0
  437. package/lib/insight/insights/extractors/correlation.js +43 -0
  438. package/lib/insight/insights/extractors/homogeneous.d.ts +4 -0
  439. package/lib/insight/insights/extractors/homogeneous.js +103 -0
  440. package/lib/insight/insights/extractors/lowVariance.d.ts +8 -0
  441. package/lib/insight/insights/extractors/lowVariance.js +54 -0
  442. package/lib/insight/insights/extractors/majority.d.ts +10 -0
  443. package/lib/insight/insights/extractors/majority.js +71 -0
  444. package/lib/insight/insights/extractors/timeSeriesOutlier.d.ts +2 -0
  445. package/lib/insight/insights/extractors/timeSeriesOutlier.js +65 -0
  446. package/lib/insight/insights/extractors/trend.d.ts +9 -0
  447. package/lib/insight/insights/extractors/trend.js +54 -0
  448. package/lib/insight/insights/index.d.ts +12 -0
  449. package/lib/insight/insights/index.js +32 -0
  450. package/lib/insight/insights/util.d.ts +13 -0
  451. package/lib/insight/insights/util.js +87 -0
  452. package/lib/insight/narrative/factory.d.ts +6 -0
  453. package/lib/insight/narrative/factory.js +25 -0
  454. package/lib/insight/narrative/index.d.ts +3 -0
  455. package/lib/insight/narrative/index.js +18 -0
  456. package/lib/insight/narrative/strategy/base.d.ts +9 -0
  457. package/lib/insight/narrative/strategy/base.js +9 -0
  458. package/lib/insight/narrative/strategy/categoryOutlier.d.ts +9 -0
  459. package/lib/insight/narrative/strategy/categoryOutlier.js +76 -0
  460. package/lib/insight/narrative/strategy/changePoint.d.ts +8 -0
  461. package/lib/insight/narrative/strategy/changePoint.js +54 -0
  462. package/lib/insight/narrative/strategy/commonness.d.ts +9 -0
  463. package/lib/insight/narrative/strategy/commonness.js +47 -0
  464. package/lib/insight/narrative/strategy/correlation.d.ts +8 -0
  465. package/lib/insight/narrative/strategy/correlation.js +53 -0
  466. package/lib/insight/narrative/strategy/exception.d.ts +10 -0
  467. package/lib/insight/narrative/strategy/exception.js +72 -0
  468. package/lib/insight/narrative/strategy/helpers.d.ts +5 -0
  469. package/lib/insight/narrative/strategy/helpers.js +31 -0
  470. package/lib/insight/narrative/strategy/index.d.ts +9 -0
  471. package/lib/insight/narrative/strategy/index.js +28 -0
  472. package/lib/insight/narrative/strategy/lowVariance.d.ts +8 -0
  473. package/lib/insight/narrative/strategy/lowVariance.js +50 -0
  474. package/lib/insight/narrative/strategy/majority.d.ts +8 -0
  475. package/lib/insight/narrative/strategy/majority.js +64 -0
  476. package/lib/insight/narrative/strategy/timeSeriesOutlier.d.ts +8 -0
  477. package/lib/insight/narrative/strategy/timeSeriesOutlier.js +94 -0
  478. package/lib/insight/narrative/strategy/trend.d.ts +8 -0
  479. package/lib/insight/narrative/strategy/trend.js +59 -0
  480. package/lib/insight/pipeline/extract.d.ts +13 -0
  481. package/lib/insight/pipeline/extract.js +243 -0
  482. package/lib/insight/pipeline/index.d.ts +2 -0
  483. package/lib/insight/pipeline/index.js +15 -0
  484. package/lib/insight/pipeline/insight.d.ts +10 -0
  485. package/lib/insight/pipeline/insight.js +86 -0
  486. package/lib/insight/pipeline/preprocess.d.ts +6 -0
  487. package/lib/insight/pipeline/preprocess.js +39 -0
  488. package/lib/insight/pipeline/specificInsight.d.ts +11 -0
  489. package/lib/insight/pipeline/specificInsight.js +79 -0
  490. package/lib/insight/pipeline/util.d.ts +5 -0
  491. package/lib/insight/pipeline/util.js +20 -0
  492. package/lib/insight/pipeline/visualize.d.ts +3 -0
  493. package/lib/insight/pipeline/visualize.js +46 -0
  494. package/lib/insight/types.d.ts +238 -0
  495. package/lib/insight/types.js +2 -0
  496. package/lib/insight/utils/aggregate.d.ts +7 -0
  497. package/lib/insight/utils/aggregate.js +93 -0
  498. package/lib/insight/utils/common.d.ts +3 -0
  499. package/lib/insight/utils/common.js +41 -0
  500. package/lib/ntv/generate/generateTextSpec.d.ts +9 -0
  501. package/lib/ntv/generate/generateTextSpec.js +160 -0
  502. package/lib/ntv/generate/index.d.ts +2 -0
  503. package/lib/ntv/generate/index.js +12 -0
  504. package/lib/ntv/generate/types.d.ts +58 -0
  505. package/lib/ntv/generate/types.js +2 -0
  506. package/lib/ntv/generate/utils.d.ts +29 -0
  507. package/lib/ntv/generate/utils.js +96 -0
  508. package/lib/ntv/index.d.ts +4 -0
  509. package/lib/ntv/index.js +10 -0
  510. package/lib/ntv/schema/common.d.ts +17 -0
  511. package/lib/ntv/schema/common.js +2 -0
  512. package/lib/ntv/schema/index.d.ts +4 -0
  513. package/lib/ntv/schema/index.js +7 -0
  514. package/lib/ntv/schema/paragraph.d.ts +34 -0
  515. package/lib/ntv/schema/paragraph.js +2 -0
  516. package/lib/ntv/schema/phrase.d.ts +70 -0
  517. package/lib/ntv/schema/phrase.js +55 -0
  518. package/lib/ntv/schema/structure.d.ts +18 -0
  519. package/lib/ntv/schema/structure.js +2 -0
  520. package/lib/ntv/types.d.ts +2 -0
  521. package/lib/ntv/types.js +2 -0
  522. package/lib/ntv/utils/index.d.ts +1 -0
  523. package/lib/ntv/utils/index.js +4 -0
  524. package/lib/ntv/utils/isSpecType.d.ts +17 -0
  525. package/lib/ntv/utils/isSpecType.js +76 -0
  526. package/lib/utils/arr2map.d.ts +1 -0
  527. package/lib/utils/arr2map.js +11 -0
  528. package/lib/utils/dataFormat.d.ts +11 -0
  529. package/lib/utils/dataFormat.js +35 -0
  530. package/lib/utils/index.d.ts +3 -0
  531. package/lib/utils/index.js +8 -0
  532. package/lib/utils/isType.d.ts +4 -0
  533. package/lib/utils/isType.js +21 -0
  534. package/package.json +88 -0
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ /* eslint-disable no-console */
5
+ var lodash_1 = require("lodash");
6
+ var utils_1 = require("../../utils");
7
+ var utils_2 = require("../utils");
8
+ var utils_3 = require("./utils");
9
+ var TextSpecGenerator = /** @class */ (function () {
10
+ function TextSpecGenerator(_a) {
11
+ var variable = _a.variable, structures = _a.structures, structureTemps = _a.structureTemps;
12
+ this.variable = variable;
13
+ this.structures = structures;
14
+ this.structureTemps = structureTemps;
15
+ }
16
+ TextSpecGenerator.prototype.generateTextPhrase = function (text) {
17
+ // TODO 是否需要判断 value 为 string ??是否需要默认的数值格式化?—— 暂时先简单 toString 下
18
+ return { type: 'text', value: (0, lodash_1.toString)(text) };
19
+ };
20
+ TextSpecGenerator.prototype.generateVarPhrase = function (scopeVariable, path, value, metadata) {
21
+ // 没有 meta 的一律按普通文本处理
22
+ if (!metadata) {
23
+ return this.generateTextPhrase(value);
24
+ }
25
+ var varType = metadata.varType, formatter = metadata.formatter, extraCustomMeta = metadata.extraCustomMeta;
26
+ var formattedValue = (0, utils_3.getFormattedNumberValue)(varType, value, formatter);
27
+ // 声明 varType 的可能是 entity 也可能是 custom
28
+ if (varType) {
29
+ if ((0, utils_2.isEntityType)(varType)) {
30
+ return {
31
+ type: 'entity',
32
+ value: formattedValue,
33
+ metadata: {
34
+ entityType: varType,
35
+ origin: (0, utils_1.isNumberLike)(value) ? value : undefined,
36
+ assessment: (0, utils_3.getAssessment)(varType, value),
37
+ generateVariableInfo: { scopeVariable: scopeVariable, path: path },
38
+ },
39
+ };
40
+ }
41
+ var extra = extraCustomMeta === null || extraCustomMeta === void 0 ? void 0 : extraCustomMeta(this.variable, scopeVariable);
42
+ return {
43
+ type: 'custom',
44
+ value: formattedValue,
45
+ // TODO 完善自定义短语 metadata
46
+ metadata: tslib_1.__assign({ customType: varType, generateVariableInfo: { scopeVariable: scopeVariable, path: path } }, extra),
47
+ };
48
+ }
49
+ return this.generateTextPhrase((0, lodash_1.toString)(value));
50
+ };
51
+ // 只处理行数据拼接逻辑,表格数据
52
+ TextSpecGenerator.prototype.generateSentence = function (template, variable, variableMetaMap) {
53
+ var _this = this;
54
+ var phrases = [];
55
+ var templateStructure = (0, utils_3.templateStr2Structure)(template);
56
+ var _loop_1 = function (i) {
57
+ var _a = templateStructure[i], tempStrType = _a.type, tempStrValue = _a.value;
58
+ if (tempStrType === 'template') {
59
+ var targetTempId_1 = tempStrValue;
60
+ // get template info by template id
61
+ var templateInfo = this_1.structureTemps.find(function (_a) {
62
+ var templateId = _a.templateId;
63
+ return templateId === targetTempId_1;
64
+ });
65
+ if (templateInfo) {
66
+ var template_1 = templateInfo.template, useVariable = templateInfo.useVariable, variableMetaMap_1 = templateInfo.variableMetaMap, limit = templateInfo.limit, _b = templateInfo.separator, separator_1 = _b === void 0 ? ',' : _b;
67
+ var scopeArrayVariable_1 = (0, utils_3.getScopeVariableArray)(this_1.variable, variable, useVariable, limit);
68
+ var subPhrases = scopeArrayVariable_1
69
+ .map(function (v) { return _this.generateSentence(template_1, v, variableMetaMap_1); })
70
+ .reduce(function (prev, curr, index) {
71
+ var result = tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(prev), false), tslib_1.__read(curr), false);
72
+ if (index !== scopeArrayVariable_1.length - 1)
73
+ result.push(_this.generateTextPhrase(separator_1));
74
+ return result;
75
+ }, []);
76
+ phrases = phrases.concat.apply(phrases, tslib_1.__spreadArray([], tslib_1.__read(subPhrases), false));
77
+ }
78
+ else {
79
+ console.warn("".concat(targetTempId_1, " is not exist"));
80
+ }
81
+ }
82
+ else if (tempStrType === 'variable') {
83
+ var key = tempStrValue;
84
+ var metadata = variableMetaMap === null || variableMetaMap === void 0 ? void 0 : variableMetaMap[key];
85
+ var value = (metadata === null || metadata === void 0 ? void 0 : metadata.getDisplayValue)
86
+ ? (0, utils_3.getDisplayValue)(metadata === null || metadata === void 0 ? void 0 : metadata.getDisplayValue, this_1.variable, variable)
87
+ : (0, utils_3.getByPath)(this_1.variable, variable, key);
88
+ phrases.push(this_1.generateVarPhrase(variable, key, value, tslib_1.__assign({}, metadata)));
89
+ }
90
+ else if (tempStrType === 'text') {
91
+ phrases.push(this_1.generateTextPhrase(tempStrValue));
92
+ }
93
+ };
94
+ var this_1 = this;
95
+ for (var i = 0; i < templateStructure.length; i += 1) {
96
+ _loop_1(i);
97
+ }
98
+ return phrases;
99
+ };
100
+ /**
101
+ * 生成段落
102
+ * 1. 当前支持段落类型 heading normal bullet
103
+ * 2. 生成段落个数取决于 variable 的类型:
104
+ * 2.1 非自带循环属性的段落(heading normal)遇到数组数据时自动循环多段;
105
+ * 2.2 自身循环段落(bullet)遇到非数组时只生成一个
106
+ * */
107
+ TextSpecGenerator.prototype.generateParagraphs = function (structure, variable) {
108
+ var _this = this;
109
+ if (variable === void 0) { variable = this.variable; }
110
+ var variableMetaMap = structure.variableMetaMap, template = structure.template, _a = structure.displayType, displayType = _a === void 0 ? 'paragraph' : _a, _b = structure.useVariable, useVariable = _b === void 0 ? '' : _b, limit = structure.limit,
111
+ // 段落级别暂时用不到 separator
112
+ // separator,
113
+ bulletOrder = structure.bulletOrder, children = structure.children, className = structure.className;
114
+ var scopeArrayVariable = (0, utils_3.getScopeVariableArray)(this.variable, variable, useVariable, limit);
115
+ // TODO 接入更多类型
116
+ if (displayType === 'paragraph') {
117
+ return scopeArrayVariable.map(function (v) { return ({
118
+ type: 'normal',
119
+ phrases: _this.generateSentence(template, v, variableMetaMap),
120
+ className: className,
121
+ }); });
122
+ }
123
+ if (displayType === 'bullet') {
124
+ return [
125
+ {
126
+ type: 'bullets',
127
+ className: className,
128
+ isOrder: bulletOrder,
129
+ bullets: scopeArrayVariable.map(function (v) { return ({
130
+ type: 'bullet-item',
131
+ phrases: _this.generateSentence(template, v, variableMetaMap),
132
+ subBullet: children
133
+ ? _this.generateParagraphs(tslib_1.__assign(tslib_1.__assign({}, children), { displayType: 'bullet' }), v)[0]
134
+ : undefined,
135
+ }); }),
136
+ },
137
+ ];
138
+ }
139
+ return null;
140
+ };
141
+ TextSpecGenerator.prototype.generateSection = function () {
142
+ var _this = this;
143
+ return {
144
+ paragraphs: this.structures.reduce(function (prev, curr) {
145
+ return tslib_1.__spreadArray(tslib_1.__spreadArray([], tslib_1.__read(prev), false), tslib_1.__read(_this.generateParagraphs(curr)), false);
146
+ }, []),
147
+ };
148
+ };
149
+ TextSpecGenerator.prototype.generateNarrative = function () {
150
+ return {
151
+ // 当前只可能构建出一个 section
152
+ sections: [this.generateSection()],
153
+ };
154
+ };
155
+ return TextSpecGenerator;
156
+ }());
157
+ function generateTextSpec(params) {
158
+ return new TextSpecGenerator(params).generateNarrative();
159
+ }
160
+ exports.default = generateTextSpec;
@@ -0,0 +1,2 @@
1
+ export { default as generateTextSpec } from './generateTextSpec';
2
+ export type { Structure, StructureTemp, Variable } from './types';
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ /*
3
+ * generate text spec by structure and variable
4
+ * thx @Lobster377
5
+ */
6
+ var __importDefault = (this && this.__importDefault) || function (mod) {
7
+ return (mod && mod.__esModule) ? mod : { "default": mod };
8
+ };
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.generateTextSpec = void 0;
11
+ var generateTextSpec_1 = require("./generateTextSpec");
12
+ Object.defineProperty(exports, "generateTextSpec", { enumerable: true, get: function () { return __importDefault(generateTextSpec_1).default; } });
@@ -0,0 +1,58 @@
1
+ type StructureDisplayType = 'heading' | 'paragraph' | 'bullet';
2
+ export type VariableMeta = Partial<{
3
+ /** 可能是 entityType 或者是 customType */
4
+ varType: string;
5
+ formatter: (value: any) => string;
6
+ /** 类似计算字段,行级别拼接 value 变量 */
7
+ getDisplayValue: string | ((globalVar: Variable, scopeVar: Variable) => string);
8
+ /** 其他自定义属性 */
9
+ extraCustomMeta: (globalVar: Variable, scopeVar: Variable) => Record<string, any>;
10
+ }>;
11
+ export type VariableMetaMap = Record<string, VariableMeta>;
12
+ export type TemplateBase = {
13
+ /**
14
+ * template string
15
+ * -- use ${} 表示应用哪个变量
16
+ * -- use &{} 表示应用哪个模版,即 structureTemp 中的 templateId
17
+ */
18
+ template: string;
19
+ /** 分隔符,如果数据是数组,自动循环 */
20
+ separator?: string;
21
+ /** 列表循环 limit */
22
+ limit?: number;
23
+ /** 变量附加信息 */
24
+ variableMetaMap?: VariableMetaMap;
25
+ /** 通过类似 lodash get 变量路径访问变量 */
26
+ useVariable?: string;
27
+ };
28
+ /**
29
+ * @description narrative structure,会按顺序执行
30
+ * @example Structure[] like bellow:
31
+ * [
32
+ * { template: "system &{s1}, includes &{s2} .", displayType: "paragraph" },
33
+ * ]
34
+ */
35
+ export type Structure = TemplateBase & {
36
+ /**
37
+ * 展示段落类型
38
+ */
39
+ displayType?: StructureDisplayType;
40
+ /** 列表是否有序 */
41
+ bulletOrder?: boolean;
42
+ /** 用于嵌套列表 */
43
+ children?: Structure;
44
+ className?: string;
45
+ };
46
+ /**
47
+ * @description structure template,只有引用到才会按执行
48
+ * @example StructureTemp[] like bellow:
49
+ * [
50
+ * { templateId: s1, template: "&{s1}", variableId: "var2" },
51
+ * { templateId: s2, template: 'user ${name}, ${age[metric_name]} is ${age}', variableId: 'var1', displayType: 'phrase', separator: ', ' }
52
+ * ]
53
+ */
54
+ export type StructureTemp = TemplateBase & {
55
+ templateId: string;
56
+ };
57
+ export type Variable = Record<string, any>;
58
+ export {};
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,29 @@
1
+ import type { Variable, VariableMeta } from './types';
2
+ import type { EntityType } from '../schema';
3
+ export type TemplateStructure = {
4
+ type: 'text' | 'variable' | 'template';
5
+ value: string;
6
+ };
7
+ /**
8
+ * simple path system
9
+ * if starts with '.', it's relative path
10
+ * // TODO 支持相对路径找到上级
11
+ * if starts with '..', it's can get prev level variable
12
+ * otherwise, it's absolute path
13
+ */
14
+ export declare function getByPath(globalVar: Variable, scopeVar: Variable, path?: string): any;
15
+ /**
16
+ * parse template string
17
+ * Use $ for variable
18
+ * Use & for template
19
+ * @example 'aaa ${key} &{temp1}'
20
+ * => [{ type: 'text', value: 'aaa ' }, { type: 'variable', value: 'key' }, { type: 'template', value: 'temp1' }]
21
+ */
22
+ export declare function templateStr2Structure(templateStr: string): TemplateStructure[];
23
+ /** format any to array, and filter nil */
24
+ export declare function formattedAsArray(variable: Variable): any[];
25
+ export declare function getScopeVariableArray(globalVar: Variable, scopeVar: Variable, path: string, limit?: number): any[];
26
+ export declare function getAssessment(entityType: EntityType, value: any): "positive" | "negative";
27
+ export declare function getFormattedNumberValue(varType: string, value: any, formatter?: VariableMeta['formatter']): any;
28
+ /** get phrase text */
29
+ export declare function getDisplayValue(getDisplayValuePattern: VariableMeta['getDisplayValue'], globalVar: Variable, scopeVar: Variable): string;
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDisplayValue = exports.getFormattedNumberValue = exports.getAssessment = exports.getScopeVariableArray = exports.formattedAsArray = exports.templateStr2Structure = exports.getByPath = void 0;
4
+ var lodash_1 = require("lodash");
5
+ var utils_1 = require("../../utils");
6
+ /**
7
+ * simple path system
8
+ * if starts with '.', it's relative path
9
+ * // TODO 支持相对路径找到上级
10
+ * if starts with '..', it's can get prev level variable
11
+ * otherwise, it's absolute path
12
+ */
13
+ function getByPath(globalVar, scopeVar, path) {
14
+ if (!path)
15
+ return scopeVar;
16
+ if ((0, lodash_1.startsWith)(path, '.'))
17
+ return (0, lodash_1.get)(scopeVar, path.slice(1));
18
+ return (0, lodash_1.get)(globalVar, path);
19
+ }
20
+ exports.getByPath = getByPath;
21
+ /**
22
+ * parse template string
23
+ * Use $ for variable
24
+ * Use & for template
25
+ * @example 'aaa ${key} &{temp1}'
26
+ * => [{ type: 'text', value: 'aaa ' }, { type: 'variable', value: 'key' }, { type: 'template', value: 'temp1' }]
27
+ */
28
+ function templateStr2Structure(templateStr) {
29
+ // eslint-disable-next-line no-useless-escape
30
+ var splitReg = /([\$|&]{.*?})/;
31
+ var varReg = /\${(.*?)}/;
32
+ var tempReg = /&{(.*?)}/;
33
+ return templateStr
34
+ .split(splitReg)
35
+ .filter(function (str) { return str; })
36
+ .map(function (str) {
37
+ var _a, _b;
38
+ var templateId = (_a = tempReg.exec(str)) === null || _a === void 0 ? void 0 : _a[1];
39
+ if (templateId)
40
+ return { value: templateId, type: 'template' };
41
+ var varName = (_b = varReg.exec(str)) === null || _b === void 0 ? void 0 : _b[1];
42
+ if (varName)
43
+ return { value: varName, type: 'variable' };
44
+ return { value: str, type: 'text' };
45
+ });
46
+ }
47
+ exports.templateStr2Structure = templateStr2Structure;
48
+ /** format any to array, and filter nil */
49
+ function formattedAsArray(variable) {
50
+ if ((0, lodash_1.isUndefined)(variable))
51
+ return [];
52
+ return (0, lodash_1.isArray)(variable) ? variable : [variable];
53
+ }
54
+ exports.formattedAsArray = formattedAsArray;
55
+ function getScopeVariableArray(globalVar, scopeVar, path, limit) {
56
+ return (0, lodash_1.slice)(formattedAsArray(getByPath(globalVar, scopeVar, path)), 0, limit);
57
+ }
58
+ exports.getScopeVariableArray = getScopeVariableArray;
59
+ function getAssessment(entityType, value) {
60
+ if (!(0, utils_1.isNumberLike)(value))
61
+ return undefined;
62
+ if (entityType === 'delta_value' || entityType === 'ratio_value') {
63
+ if (value > 0)
64
+ return 'positive';
65
+ if (value < 0)
66
+ return 'negative';
67
+ }
68
+ return undefined;
69
+ }
70
+ exports.getAssessment = getAssessment;
71
+ function getFormattedNumberValue(varType, value, formatter) {
72
+ if (!(0, utils_1.isNumberLike)(value))
73
+ return value;
74
+ if (varType === 'delta_value' || varType === 'ratio_value') {
75
+ return formatter ? formatter(Math.abs(value)) : (0, utils_1.dataFormat)(Math.abs(value));
76
+ }
77
+ if (varType === 'proportion') {
78
+ return formatter ? formatter(Math.abs(value)) : "".concat((0, utils_1.dataFormat)(value * 100), "%");
79
+ }
80
+ return formatter ? formatter(value) : (0, utils_1.dataFormat)(value);
81
+ }
82
+ exports.getFormattedNumberValue = getFormattedNumberValue;
83
+ /** get phrase text */
84
+ function getDisplayValue(getDisplayValuePattern, globalVar, scopeVar) {
85
+ if ((0, lodash_1.isString)(getDisplayValuePattern)) {
86
+ // 用字符串表示使用变量拼接短语文字内容,这里进行变量替换,eg '${city} = ${value}' => '北京 = 1000'
87
+ // Use a string to represent the text content of the phrase using variables to splice,eg '${city} = ${value}' => 'Beijing = 1000'
88
+ return (0, lodash_1.replace)(getDisplayValuePattern, /\${(.*?)}/g, function (match) {
89
+ var _a;
90
+ var varName = (_a = /\${(.*?)}/.exec(match)) === null || _a === void 0 ? void 0 : _a[1];
91
+ return varName ? getByPath(globalVar, scopeVar, varName) : '';
92
+ });
93
+ }
94
+ return getDisplayValuePattern(globalVar, scopeVar);
95
+ }
96
+ exports.getDisplayValue = getDisplayValue;
@@ -0,0 +1,4 @@
1
+ export * from './types';
2
+ export { ENTITY_TYPES } from './schema';
3
+ export * from './utils';
4
+ export { generateTextSpec } from './generate';
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateTextSpec = exports.ENTITY_TYPES = void 0;
4
+ var tslib_1 = require("tslib");
5
+ tslib_1.__exportStar(require("./types"), exports);
6
+ var schema_1 = require("./schema");
7
+ Object.defineProperty(exports, "ENTITY_TYPES", { enumerable: true, get: function () { return schema_1.ENTITY_TYPES; } });
8
+ tslib_1.__exportStar(require("./utils"), exports);
9
+ var generate_1 = require("./generate");
10
+ Object.defineProperty(exports, "generateTextSpec", { enumerable: true, get: function () { return generate_1.generateTextSpec; } });
@@ -0,0 +1,17 @@
1
+ import type { Properties } from 'csstype';
2
+ /** common props for block ele and inline ele */
3
+ export type CommonProps = {
4
+ styles?: Properties;
5
+ className?: string;
6
+ key?: string;
7
+ };
8
+ /** basic block element structure, used for extends */
9
+ export type CustomBlockElement = CommonProps & {
10
+ customType: string;
11
+ [key: string]: unknown;
12
+ };
13
+ /** custom phrase metadata */
14
+ export type CustomMetaData = {
15
+ customType: string;
16
+ [key: string]: unknown;
17
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ export * from './common';
2
+ export * from './structure';
3
+ export * from './paragraph';
4
+ export * from './phrase';
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./common"), exports);
5
+ tslib_1.__exportStar(require("./structure"), exports);
6
+ tslib_1.__exportStar(require("./paragraph"), exports);
7
+ tslib_1.__exportStar(require("./phrase"), exports);
@@ -0,0 +1,34 @@
1
+ import type { PhraseSpec } from './phrase';
2
+ import type { CommonProps, CustomBlockElement } from './common';
3
+ export type ParagraphSpec = HeadingParagraphSpec | TextParagraphSpec | BulletsParagraphSpec | DividerParagraphSpec | CustomBlockElement;
4
+ export type HeadingParagraphSpec = CommonProps & {
5
+ type: 'heading1' | 'heading2' | 'heading3' | 'heading4' | 'heading5' | 'heading6';
6
+ phrases: PhraseSpec[];
7
+ };
8
+ /**
9
+ * indents 段落缩紧
10
+ */
11
+ export type ParagraphIndent = {
12
+ /** 缩进类型:参考 word 排版,包括:首行缩紧、左缩进、右缩进、 悬挂缩进(情况较少,暂不支持) */
13
+ type: 'first-line' | 'left' | 'right';
14
+ /** 缩进值,支持 css text-indent 值,比如 12px 20% 2em */
15
+ length: string;
16
+ };
17
+ export type TextParagraphSpec = CommonProps & {
18
+ type: 'normal';
19
+ phrases: PhraseSpec[];
20
+ indents?: ParagraphIndent[];
21
+ };
22
+ export type DividerParagraphSpec = CommonProps & {
23
+ type: 'divider';
24
+ };
25
+ export type BulletsParagraphSpec = CommonProps & {
26
+ type: 'bullets';
27
+ isOrder: boolean;
28
+ bullets: BulletItemSpec[];
29
+ };
30
+ export type BulletItemSpec = CommonProps & {
31
+ type: 'bullet-item';
32
+ phrases: PhraseSpec[];
33
+ subBullet?: BulletsParagraphSpec;
34
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,70 @@
1
+ import { Variable } from '../generate/types';
2
+ import { CustomMetaData, CommonProps } from './common';
3
+ export type PhraseSpec = TextPhraseSpec | EntityPhraseSpec | EscapePhraseSpec | FormulaPhraseSpec | ImagePhraseSpec | CustomPhraseSpec<CustomMetaData>;
4
+ export type TextPhraseSpec = CommonProps & {
5
+ type: 'text';
6
+ value: string;
7
+ bold?: boolean;
8
+ italic?: boolean;
9
+ underline?: boolean;
10
+ url?: string;
11
+ };
12
+ export type ImagePhraseSpec = CommonProps & {
13
+ type: 'image';
14
+ value: string;
15
+ alt?: string;
16
+ };
17
+ /**
18
+ * escape character 支持转义字符
19
+ */
20
+ export type EscapePhraseSpec = CommonProps & {
21
+ type: 'escape';
22
+ value: string;
23
+ };
24
+ /**
25
+ * math formula
26
+ */
27
+ export type FormulaPhraseSpec = CommonProps & {
28
+ type: 'formula';
29
+ value: string;
30
+ };
31
+ export type EntityPhraseSpec = CommonProps & {
32
+ type: 'entity';
33
+ value?: string;
34
+ metadata?: EntityMetaData;
35
+ };
36
+ export type CustomPhraseSpec<P extends CustomMetaData = CustomMetaData> = CommonProps & {
37
+ type: 'custom';
38
+ value?: string;
39
+ metadata?: P;
40
+ };
41
+ export type ValueAssessment = 'positive' | 'negative' | 'equal';
42
+ export declare const ENTITY_TYPES: readonly ["metric_name", "metric_value", "other_metric_value", "contribute_ratio", "delta_value", "ratio_value", "trend_desc", "dim_value", "time_desc", "proportion"];
43
+ export type EntityType = (typeof ENTITY_TYPES)[number];
44
+ export type EntityMetaData = {
45
+ /**
46
+ * entity type, 实体类型标记
47
+ * */
48
+ entityType: EntityType;
49
+ /**
50
+ * assessment up or down, used for derived value
51
+ * 衍生指标评估参数,指定上涨或者下跌
52
+ * */
53
+ assessment?: ValueAssessment;
54
+ /**
55
+ * original data, 原始数据
56
+ * */
57
+ origin?: number;
58
+ /**
59
+ * detail data, 明细数据,用于弹框展示
60
+ */
61
+ detail?: unknown;
62
+ /** source id of the variable, to access the variable info from variableSourceMap */
63
+ /**
64
+ * generate variable info, 通过模版拼接工具函数生成过程中得到的变量信息
65
+ */
66
+ generateVariableInfo?: {
67
+ scopeVariable: Variable;
68
+ path: string;
69
+ };
70
+ };
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ENTITY_TYPES = void 0;
4
+ exports.ENTITY_TYPES = [
5
+ /**
6
+ * @description main indicator value 主指标名
7
+ * @example DAU
8
+ * */
9
+ 'metric_name',
10
+ /**
11
+ * @description main indicator name 主指标值
12
+ * @example 1.23 million
13
+ * */
14
+ 'metric_value',
15
+ /**
16
+ * @description other indicator value 其他指标值
17
+ * @example
18
+ * */
19
+ 'other_metric_value',
20
+ /**
21
+ * @description contribution ratio 贡献度
22
+ * @example 23%
23
+ * */
24
+ 'contribute_ratio',
25
+ /**
26
+ * @description delate value 变化值
27
+ * @example -1.2
28
+ * */
29
+ 'delta_value',
30
+ /**
31
+ * @description ratio value 变化率
32
+ * @example +23%
33
+ * */
34
+ 'ratio_value',
35
+ /**
36
+ * @description trend description 趋势描述
37
+ * @example up/down
38
+ * */
39
+ 'trend_desc',
40
+ /**
41
+ * @description dimension value 维值
42
+ * @example sex = man
43
+ * */
44
+ 'dim_value',
45
+ /**
46
+ * @description time description 时间描述
47
+ * @example 2021-11-19
48
+ * */
49
+ 'time_desc',
50
+ /**
51
+ * @description proportion 占比
52
+ * @example 20%
53
+ * */
54
+ 'proportion',
55
+ ];
@@ -0,0 +1,18 @@
1
+ import type { CommonProps, CustomBlockElement } from './common';
2
+ import type { PhraseSpec } from './phrase';
3
+ import type { ParagraphSpec } from './paragraph';
4
+ export type NarrativeTextSpec = CommonProps & {
5
+ headline?: HeadlineSpec;
6
+ sections?: SectionSpec[];
7
+ };
8
+ export type HeadlineSpec = CommonProps & {
9
+ type: 'headline';
10
+ phrases: PhraseSpec[];
11
+ };
12
+ export type StandardSectionSpec = {
13
+ paragraphs?: ParagraphSpec[];
14
+ };
15
+ export type SectionSpec = (StandardSectionSpec | CustomBlockElement) & CommonProps;
16
+ export type NestedParagraphSpec = CommonProps & {
17
+ children: (ParagraphSpec | NestedParagraphSpec)[];
18
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ export type { NarrativeTextSpec, HeadlineSpec, SectionSpec, StandardSectionSpec, ParagraphSpec, HeadingParagraphSpec, TextParagraphSpec, BulletsParagraphSpec, BulletItemSpec, CustomBlockElement, NestedParagraphSpec, PhraseSpec, TextPhraseSpec, EntityPhraseSpec, EscapePhraseSpec, FormulaPhraseSpec, CustomPhraseSpec, ValueAssessment, EntityType, EntityMetaData, CustomMetaData, } from './schema';
2
+ export type { Structure, StructureTemp, Variable } from './generate';
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export * from './isSpecType';
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./isSpecType"), exports);
@@ -0,0 +1,17 @@
1
+ import { EntityType } from '../schema';
2
+ import type { SectionSpec, ParagraphSpec, CustomBlockElement, StandardSectionSpec, TextParagraphSpec, BulletsParagraphSpec, HeadingParagraphSpec, PhraseSpec, CustomPhraseSpec, EntityPhraseSpec, TextPhraseSpec, EscapePhraseSpec, FormulaPhraseSpec, DividerParagraphSpec, ImagePhraseSpec } from '../schema';
3
+ export declare function isCustomSection(spec: SectionSpec): spec is CustomBlockElement;
4
+ export declare function isCustomParagraph(spec: ParagraphSpec): spec is CustomBlockElement;
5
+ export declare function isStandardSection(spec: SectionSpec): spec is StandardSectionSpec;
6
+ export declare function isTextParagraph(spec: ParagraphSpec): spec is TextParagraphSpec;
7
+ export declare function isBulletParagraph(spec: ParagraphSpec): spec is BulletsParagraphSpec;
8
+ export declare function isDividerParagraph(spec: ParagraphSpec): spec is DividerParagraphSpec;
9
+ export declare function getHeadingWeight(pType: string): number;
10
+ export declare function isHeadingParagraph(spec: ParagraphSpec): spec is HeadingParagraphSpec;
11
+ export declare function isCustomPhrase(spec: PhraseSpec): spec is CustomPhraseSpec;
12
+ export declare function isEntityType(type: any): type is EntityType;
13
+ export declare function isEntityPhrase(spec: PhraseSpec): spec is EntityPhraseSpec;
14
+ export declare function isTextPhrase(spec: PhraseSpec): spec is TextPhraseSpec;
15
+ export declare function isEscapePhrase(spec: PhraseSpec): spec is EscapePhraseSpec;
16
+ export declare function isFormulaPhrase(spec: PhraseSpec): spec is FormulaPhraseSpec;
17
+ export declare function isImagePhrase(spec: PhraseSpec): spec is ImagePhraseSpec;