@graphenedata/cli 0.0.15 → 0.0.17

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 (117) hide show
  1. package/README.md +174 -0
  2. package/dist/cli/bigQuery-OQUNH3VT.js +75 -0
  3. package/dist/cli/bigQuery-OQUNH3VT.js.map +7 -0
  4. package/dist/cli/chunk-56K2FF57.js +53 -0
  5. package/dist/cli/chunk-56K2FF57.js.map +7 -0
  6. package/dist/cli/chunk-TZTTALAV.js +12868 -0
  7. package/dist/cli/chunk-TZTTALAV.js.map +7 -0
  8. package/dist/cli/cli.js +260 -11196
  9. package/dist/cli/clickhouse-S3BJSKND.js +65 -0
  10. package/dist/cli/clickhouse-S3BJSKND.js.map +7 -0
  11. package/dist/cli/duckdb-TKVMONRK.js +87 -0
  12. package/dist/cli/duckdb-TKVMONRK.js.map +7 -0
  13. package/dist/cli/serve2-S2LL4D4D.js +448 -0
  14. package/dist/cli/serve2-S2LL4D4D.js.map +7 -0
  15. package/dist/cli/snowflake-3VPDEYYP.js +128 -0
  16. package/dist/cli/snowflake-3VPDEYYP.js.map +7 -0
  17. package/dist/index.d.ts +63 -0
  18. package/dist/lang/index.d.ts +63 -0
  19. package/dist/skills/graphene/SKILL.md +156 -95
  20. package/dist/skills/graphene/references/big-value.md +6 -41
  21. package/dist/skills/graphene/references/date-range.md +64 -0
  22. package/dist/skills/graphene/references/dropdown.md +3 -4
  23. package/dist/skills/graphene/references/echarts.md +162 -0
  24. package/dist/skills/graphene/references/gsql.md +55 -25
  25. package/dist/skills/graphene/references/model-gsql.md +70 -0
  26. package/dist/skills/graphene/references/table.md +13 -14
  27. package/dist/skills/graphene/references/text-input.md +2 -1
  28. package/dist/ui/app.css +239 -340
  29. package/dist/ui/component-utilities/dataShaping.ts +484 -0
  30. package/dist/ui/component-utilities/dataSummary.ts +57 -0
  31. package/dist/ui/component-utilities/enrich.ts +793 -0
  32. package/dist/ui/component-utilities/format.ts +177 -0
  33. package/dist/ui/component-utilities/inputUtils.ts +44 -8
  34. package/dist/ui/component-utilities/theme.ts +200 -0
  35. package/dist/ui/component-utilities/themeStores.ts +21 -8
  36. package/dist/ui/component-utilities/types.ts +70 -0
  37. package/dist/ui/components/AreaChart.svelte +57 -105
  38. package/dist/ui/components/BarChart.svelte +71 -129
  39. package/dist/ui/components/BigValue.svelte +24 -40
  40. package/dist/ui/components/Column.svelte +10 -18
  41. package/dist/ui/components/DateRange.svelte +54 -21
  42. package/dist/ui/components/Dropdown.svelte +47 -26
  43. package/dist/ui/components/DropdownOption.svelte +1 -2
  44. package/dist/ui/components/ECharts.svelte +181 -67
  45. package/dist/ui/components/InlineDelta.svelte +50 -31
  46. package/dist/ui/components/LineChart.svelte +54 -125
  47. package/dist/ui/components/PieChart.svelte +27 -37
  48. package/dist/ui/components/QueryLoad.svelte +77 -45
  49. package/dist/ui/components/Row.svelte +2 -1
  50. package/dist/ui/components/ScatterPlot.svelte +52 -0
  51. package/dist/ui/components/Skeleton.svelte +32 -0
  52. package/dist/ui/components/Table.svelte +3 -2
  53. package/dist/ui/components/TableGroupRow.svelte +28 -36
  54. package/dist/ui/components/TableHarness.svelte +32 -0
  55. package/dist/ui/components/TableHeader.svelte +34 -59
  56. package/dist/ui/components/TableRow.svelte +14 -38
  57. package/dist/ui/components/TableSubtotalRow.svelte +18 -21
  58. package/dist/ui/components/TableTotalRow.svelte +27 -37
  59. package/dist/ui/components/TextInput.svelte +13 -12
  60. package/dist/ui/components/Value.svelte +25 -0
  61. package/dist/ui/components/_Table.svelte +72 -70
  62. package/dist/ui/internal/ChartGallery.svelte +527 -0
  63. package/dist/ui/internal/ErrorDisplay.svelte +22 -97
  64. package/dist/ui/internal/LocalApp.svelte +84 -19
  65. package/dist/ui/internal/PageNavGroup.svelte +269 -0
  66. package/dist/ui/internal/Sidebar.svelte +178 -0
  67. package/dist/ui/internal/SidebarToggle.svelte +47 -0
  68. package/dist/ui/internal/StyleGallery.svelte +244 -0
  69. package/dist/ui/internal/clientCache.ts +2 -2
  70. package/dist/ui/internal/pageInputs.svelte.js +292 -0
  71. package/dist/ui/internal/queryEngine.ts +112 -129
  72. package/dist/ui/internal/runSocket.ts +31 -14
  73. package/dist/ui/internal/sidebar.svelte.js +18 -0
  74. package/dist/ui/internal/telemetry.ts +51 -16
  75. package/dist/ui/internal/types.d.ts +7 -0
  76. package/dist/ui/web.js +30 -11
  77. package/package.json +40 -38
  78. package/dist/skills/graphene/references/area-chart.md +0 -95
  79. package/dist/skills/graphene/references/bar-chart.md +0 -112
  80. package/dist/skills/graphene/references/line-chart.md +0 -108
  81. package/dist/skills/graphene/references/pie-chart.md +0 -29
  82. package/dist/skills/graphene/references/value-formats.md +0 -104
  83. package/dist/ui/component-utilities/autoFormatting.js +0 -280
  84. package/dist/ui/component-utilities/builtInFormats.js +0 -481
  85. package/dist/ui/component-utilities/chartContext.js +0 -12
  86. package/dist/ui/component-utilities/chartWindowDebug.js +0 -21
  87. package/dist/ui/component-utilities/checkInputs.js +0 -84
  88. package/dist/ui/component-utilities/convert.js +0 -15
  89. package/dist/ui/component-utilities/dateParsing.js +0 -56
  90. package/dist/ui/component-utilities/dropdownContext.ts +0 -1
  91. package/dist/ui/component-utilities/echarts.js +0 -252
  92. package/dist/ui/component-utilities/echartsThemes.js +0 -443
  93. package/dist/ui/component-utilities/formatTitle.js +0 -24
  94. package/dist/ui/component-utilities/formatting.js +0 -241
  95. package/dist/ui/component-utilities/getColumnExtents.js +0 -79
  96. package/dist/ui/component-utilities/getColumnSummary.js +0 -62
  97. package/dist/ui/component-utilities/getCompletedData.js +0 -122
  98. package/dist/ui/component-utilities/getDistinctCount.js +0 -7
  99. package/dist/ui/component-utilities/getDistinctValues.js +0 -15
  100. package/dist/ui/component-utilities/getSeriesConfig.js +0 -231
  101. package/dist/ui/component-utilities/getSortedData.js +0 -9
  102. package/dist/ui/component-utilities/getStackPercentages.js +0 -45
  103. package/dist/ui/component-utilities/getStackedData.js +0 -19
  104. package/dist/ui/component-utilities/getYAxisIndex.js +0 -15
  105. package/dist/ui/component-utilities/globalContexts.js +0 -1
  106. package/dist/ui/component-utilities/helpers/getCompletedData.helpers.js +0 -119
  107. package/dist/ui/component-utilities/replaceNulls.js +0 -16
  108. package/dist/ui/component-utilities/tableUtils.ts +0 -107
  109. package/dist/ui/component-utilities/tidyWithTypes.js +0 -9
  110. package/dist/ui/components/Area.svelte +0 -214
  111. package/dist/ui/components/Bar.svelte +0 -347
  112. package/dist/ui/components/Chart.svelte +0 -995
  113. package/dist/ui/components/Line.svelte +0 -227
  114. package/dist/ui/internal/NavSidebar.svelte +0 -396
  115. package/dist/ui/internal/theme.ts +0 -60
  116. package/dist/ui/public/inter-latin-ext.woff2 +0 -0
  117. package/dist/ui/public/inter-latin.woff2 +0 -0
@@ -1,231 +0,0 @@
1
- import {fmt} from './formatting.js'
2
- import getDistinctValues from './getDistinctValues.js'
3
-
4
- export default function getSeriesConfig(
5
- data,
6
- x,
7
- y,
8
- series,
9
- swapXY,
10
- baseConfig,
11
- name,
12
- xMismatch, // this checks for scenarios where xType is string and xDataType is number. When this is the case, we need to inject strings into the x axis, or else it will cause echarts to think there are duplicate x-axis values (e.g., "4" and 4)
13
- columnSummary,
14
- seriesOrder,
15
- size = undefined,
16
- tooltipTitle = undefined,
17
- y2 = undefined,
18
- seriesLabelFmt = undefined,
19
- ) {
20
- function generateTempConfig(seriesData, seriesName, yAxisIndex, baseConfig) {
21
- let tempConfig = {
22
- name: seriesName,
23
- data: seriesData,
24
- yAxisIndex: yAxisIndex,
25
- }
26
- tempConfig = {...baseConfig, ...tempConfig}
27
- return tempConfig
28
- }
29
-
30
- let i
31
- let j
32
- let tempConfig
33
- let seriesConfig = []
34
- let seriesData
35
- let filteredData
36
- let seriesName
37
- let seriesDistinct
38
- let yAxisIndex
39
-
40
- // y = single, y2 = empty
41
- // y = single, y2 = single
42
- // y = single, y2 = array
43
-
44
- // y = array, y2 = empty
45
- // y = array, y2 = single
46
- // y = array, y2 = array
47
-
48
- // y = empty, y2 = empty
49
- // y = empty, y2 = single
50
- // y = empty, y2 = array
51
-
52
- // colname, yAxisIndex
53
-
54
- function combineVariables(variable1, variable2) {
55
- // Returns an array of arrays, where each individual array is [column_name, yAxisIndex], where yAxisIndex is 0 for y and 1 for y2.
56
- // E.g., [ ['sales', 0 ], ['gross_profit', 1]] - sales on primary axis, gross profit on secondary
57
- let array = []
58
-
59
- // Helper function to check if a value is undefined
60
- function isUndefined(value) {
61
- return typeof value === 'undefined'
62
- }
63
-
64
- // Helper function to add non-undefined values to the array with source indicator
65
- function addValuesToArray(value, source) {
66
- if (!isUndefined(value)) {
67
- if (Array.isArray(value)) {
68
- value.forEach(item => array.push([item, source]))
69
- } else {
70
- array.push([value, source])
71
- }
72
- }
73
- }
74
-
75
- addValuesToArray(variable1, 0)
76
- addValuesToArray(variable2, 1)
77
-
78
- return array
79
- }
80
-
81
- let yList = combineVariables(y, y2)
82
-
83
- // 1) Series column with single y column
84
- if (series != null && yList.length === 1) {
85
- seriesDistinct = getDistinctValues(data, series)
86
-
87
- for (i = 0; i < seriesDistinct.length; i++) {
88
- // Filter for specific series:
89
- filteredData = data.filter(d => d[series] === seriesDistinct[i])
90
-
91
- if (swapXY) {
92
- seriesData = filteredData.map(d => [d[yList[0][0]], xMismatch ? d[x].toString() : d[x]])
93
- } else {
94
- seriesData = filteredData.map(d => [xMismatch ? d[x].toString() : d[x], d[yList[0][0]]])
95
- }
96
-
97
- // Append size column if supplied (for bubble chart):
98
- if (size) {
99
- let sizeData = filteredData.map(d => d[size])
100
- seriesData.forEach((item, index) => item.push(sizeData[index]))
101
- }
102
-
103
- // Append tooltip label if supplied:
104
- if (tooltipTitle) {
105
- let tooltipData = filteredData.map(d => d[tooltipTitle])
106
- seriesData.forEach((item, index) => item.push(tooltipData[index]))
107
- }
108
-
109
- // Set series name:
110
- seriesName = seriesDistinct[i] ?? 'null'
111
-
112
- // Set y-axis index (used for multi-y axis charts):
113
- yAxisIndex = yList[0][1]
114
-
115
- tempConfig = generateTempConfig(seriesData, seriesName, yAxisIndex, baseConfig)
116
- seriesConfig.push(tempConfig)
117
- }
118
- }
119
-
120
- // 2) Series column with multiple y columns
121
- if (series != null && yList.length > 1) {
122
- seriesDistinct = getDistinctValues(data, series)
123
- for (i = 0; i < seriesDistinct.length; i++) {
124
- // Filter for specific series:
125
- filteredData = data.filter(d => d[series] === seriesDistinct[i])
126
-
127
- for (j = 0; j < yList.length; j++) {
128
- if (swapXY) {
129
- seriesData = filteredData.map(d => [d[yList[j][0]], xMismatch ? d[x].toString() : d[x]])
130
- } else {
131
- seriesData = filteredData.map(d => [xMismatch ? d[x].toString() : d[x], d[yList[j][0]]])
132
- }
133
-
134
- // Append size column if supplied (for bubble chart):
135
- if (size) {
136
- let sizeData = filteredData.map(d => d[size])
137
- seriesData.forEach((item, index) => item.push(sizeData[index]))
138
- }
139
-
140
- // Append tooltip label if supplied:
141
- if (tooltipTitle) {
142
- let tooltipData = filteredData.map(d => d[tooltipTitle])
143
- seriesData.forEach((item, index) => item.push(tooltipData[index]))
144
- }
145
-
146
- // Set series name:
147
- seriesName = (seriesDistinct[i] ?? 'null') + ' - ' + columnSummary[yList[j][0]].title
148
-
149
- // Set y-axis index (used for multi-y axis charts):
150
- yAxisIndex = yList[j][1]
151
-
152
- tempConfig = generateTempConfig(seriesData, seriesName, yAxisIndex, baseConfig)
153
- seriesConfig.push(tempConfig)
154
- }
155
- }
156
- }
157
-
158
- // 3) Multiple y columns without series column
159
- if (series == null && yList.length > 1) {
160
- for (i = 0; i < yList.length; i++) {
161
- if (swapXY) {
162
- seriesData = data.map(d => [d[yList[i][0]], xMismatch ? d[x].toString() : d[x]])
163
- } else {
164
- seriesData = data.map(d => [xMismatch ? d[x].toString() : d[x], d[yList[i][0]]])
165
- }
166
-
167
- // Append size column if supplied (for bubble chart):
168
- if (size) {
169
- let sizeData = data.map(d => d[size])
170
- seriesData.forEach((item, index) => item.push(sizeData[index]))
171
- }
172
-
173
- // Append tooltip label if supplied:
174
- if (tooltipTitle) {
175
- let tooltipData = data.map(d => d[tooltipTitle])
176
- seriesData.forEach((item, index) => item.push(tooltipData[index]))
177
- }
178
-
179
- seriesName = columnSummary[yList[i][0]].title
180
-
181
- // Set y-axis index (used for multi-y axis charts):
182
- yAxisIndex = yList[i][1]
183
-
184
- tempConfig = generateTempConfig(seriesData, seriesName, yAxisIndex, baseConfig)
185
- seriesConfig.push(tempConfig)
186
- }
187
- }
188
-
189
- // 4) Single y column without series column
190
- if (series == null && yList.length === 1) {
191
- if (swapXY) {
192
- seriesData = data.map(d => [d[yList[0][0]], xMismatch ? d[x].toString() : d[x]])
193
- } else {
194
- seriesData = data.map(d => [xMismatch ? d[x].toString() : d[x], d[yList[0][0]]])
195
- }
196
-
197
- // Append size column if supplied (for bubble chart):
198
- if (size) {
199
- let sizeData = data.map(d => d[size])
200
- seriesData.forEach((item, index) => item.push(sizeData[index]))
201
- }
202
-
203
- // Append tooltip label if supplied:
204
- if (tooltipTitle) {
205
- let tooltipData = data.map(d => d[tooltipTitle])
206
- seriesData.forEach((item, index) => item.push(tooltipData[index]))
207
- }
208
-
209
- seriesName = columnSummary[yList[0][0]].title
210
-
211
- // Set y-axis index (used for multi-y axis charts):
212
- yAxisIndex = yList[0][1]
213
-
214
- tempConfig = generateTempConfig(seriesData, seriesName, yAxisIndex, baseConfig)
215
- seriesConfig.push(tempConfig)
216
- }
217
-
218
- if (seriesOrder) {
219
- seriesConfig.sort((a, b) => seriesOrder.indexOf(a.name) - seriesOrder.indexOf(b.name))
220
- }
221
-
222
- // format series config:
223
- if (seriesLabelFmt) {
224
- let seriesType = series ? columnSummary[series]?.type : undefined
225
- seriesConfig.forEach(item => {
226
- item.name = fmt(item.name, seriesLabelFmt, seriesType)
227
- })
228
- }
229
-
230
- return seriesConfig
231
- }
@@ -1,9 +0,0 @@
1
- export default function getSortedData(data, col, isAsc) {
2
- let res = [...data].sort((a, b) => {
3
- return (a[col] < b[col] ? -1 : 1) * (isAsc ? 1 : -1)
4
- })
5
- if (Array.isArray(data?._evidenceColumnTypes)) {
6
- res._evidenceColumnTypes = data._evidenceColumnTypes
7
- }
8
- return res
9
- }
@@ -1,45 +0,0 @@
1
- import {groupBy, sum, mutateWithSummary, mutate, rate, rename} from '@tidyjs/tidy'
2
-
3
- import {tidyWithTypes} from './tidyWithTypes.js'
4
-
5
- export default function getStackPercentages(data, groupCol, valueCol) {
6
- let pctData
7
- if (typeof valueCol !== 'object') {
8
- pctData = tidyWithTypes(
9
- data,
10
- groupBy(groupCol, mutateWithSummary({xTotal: sum(valueCol)})),
11
- mutate({percentOfX: rate(valueCol, 'xTotal')}),
12
- rename({
13
- percentOfX: valueCol + '_pct',
14
- }),
15
- )
16
- } else {
17
- pctData = tidyWithTypes(
18
- data,
19
- mutate({
20
- valueSum: 0,
21
- }),
22
- )
23
-
24
- for (let i = 0; i < pctData.length; i++) {
25
- pctData[i].valueSum = 0
26
- for (let j = 0; j < valueCol.length; j++) {
27
- pctData[i].valueSum = pctData[i].valueSum + pctData[i][valueCol[j]]
28
- }
29
- }
30
-
31
- pctData = tidyWithTypes(pctData, groupBy(groupCol, mutateWithSummary({xTotal: sum('valueSum')})))
32
-
33
- for (let i = 0; i < valueCol.length; i++) {
34
- pctData = tidyWithTypes(
35
- pctData,
36
- mutate({percentOfX: rate(valueCol[i], 'xTotal')}),
37
- rename({
38
- percentOfX: valueCol[i] + '_pct',
39
- }),
40
- )
41
- }
42
- }
43
-
44
- return pctData
45
- }
@@ -1,19 +0,0 @@
1
- import {groupBy, summarizeAt, sum} from '@tidyjs/tidy'
2
-
3
- import {tidyWithTypes} from './tidyWithTypes.js'
4
-
5
- export default function getStackedData(data, groupCol, valueCol) {
6
- let stackedData = tidyWithTypes(data, groupBy(groupCol, [summarizeAt(valueCol, sum)]))
7
-
8
- // If multiple y columns, iterate through data and add stack total column for sorting:
9
- if (typeof valueCol === 'object') {
10
- for (let i = 0; i < stackedData.length; i++) {
11
- stackedData[i].stackTotal = 0
12
- for (let j = 0; j < valueCol.length; j++) {
13
- stackedData[i].stackTotal = stackedData[i].stackTotal + stackedData[i][valueCol[j]]
14
- }
15
- }
16
- }
17
-
18
- return stackedData
19
- }
@@ -1,15 +0,0 @@
1
- // Helper function for multi-series tooltips:
2
- // Returns the yAxisIndex for a series since we can't currently access that in ECharts' params
3
- export default function getYAxisIndex(componentIndex, yCount, y2Count) {
4
- let totalPatternCount = yCount + y2Count
5
-
6
- // Find the position of the index in the repeating sequence
7
- let positionInPattern = componentIndex % totalPatternCount
8
-
9
- // If the position lies within yCount, return 0, otherwise return 1
10
- if (positionInPattern < yCount) {
11
- return 0
12
- } else {
13
- return 1
14
- }
15
- }
@@ -1 +0,0 @@
1
- export const CUSTOM_FORMATTING_SETTINGS_CONTEXT_KEY = 'customFormattingSettings'
@@ -1,119 +0,0 @@
1
- /**
2
- * This function is used to find difference between consecutive elements in an array.
3
- *
4
- * @param {Array<number>} arr - The array from which differences need to be found.
5
- * @return {Array<number>} An array containing the differences between consecutive elements.
6
- */
7
- export function getDiffs(arr) {
8
- let diffs = []
9
- for (let i = 1; i < arr.length; i++) diffs.push(arr[i] - arr[i - 1])
10
- return diffs
11
- }
12
-
13
- /**
14
- * The function is used to find greatest common divisor (gcd) between two numbers.
15
- *
16
- * @param {number} a - The first number to find gcd.
17
- * @param {number} b - The second number to find gcd.
18
- * @return {number} The greatest common divisor of the input numbers a and b.
19
- */
20
- export function gcd(a, b) {
21
- // Treat non-numeric types as 0
22
- if (typeof a !== 'number' || isNaN(a)) a = 0
23
- if (typeof b !== 'number' || isNaN(b)) b = 0
24
-
25
- // Handle negative numbers properly
26
- // Never reaches base case w/o this
27
- a = Math.abs(a)
28
- b = Math.abs(b)
29
-
30
- // base case
31
- if (b <= 0.01) {
32
- return a
33
- } else {
34
- return gcd(b, a % b)
35
- }
36
- }
37
-
38
- /**
39
- * This function is used to find the minimum and maximum values in an array.
40
- *
41
- * @param {Array} values - An array from which min and max values should be determined.
42
- * @param {Function} [valueof] - An optional function that defines how to obtain the measuring value.
43
- * @return {Array} An array containing the minimum and maximum of numbers, respectively.
44
- */
45
- export function extent(values, valueof) {
46
- if (!Array.isArray(values)) throw new TypeError('Cannot calculate extent of non-array value.')
47
- let min
48
- let max
49
- if (valueof === undefined) {
50
- for (let candidate of values) {
51
- if (typeof candidate !== 'number' || Number.isNaN(candidate)) continue
52
-
53
- if (min === undefined || candidate < min) min = candidate
54
- if (max === undefined || candidate > max) max = candidate
55
- }
56
- return [min, max]
57
- }
58
-
59
- let index = -1
60
- for (let original of values) {
61
- if (typeof original !== 'number') continue
62
- let candidate = valueof(original, ++index, values)
63
- if (candidate == null || Number.isNaN(candidate)) continue
64
-
65
- if (min === undefined || candidate < min) min = candidate
66
- if (max === undefined || candidate > max) max = candidate
67
- }
68
- return [min, max]
69
- }
70
-
71
- /**
72
- * This function generates a sequence of numbers as a vector from minimum to maximum with the given period increment.
73
- *
74
- * @param {Array<number>} values - An array containing the data to be sequenced.
75
- * @param {number} period - The incremental value for each step in the sequence.
76
- * @return {Array<number>} An array containing the sequenced numbers.
77
- */
78
- export function vectorSeq(values, period) {
79
- let [min, max] = extent(values)
80
-
81
- let sequence = []
82
- let value = min
83
- while (value <= max) {
84
- sequence.push(Math.round((value + Number.EPSILON) * 100000000) / 100000000)
85
- value += period
86
- }
87
-
88
- return sequence
89
- }
90
-
91
- /**
92
- * This function is used to find the interval distance among numbers in an array.
93
- *
94
- * @param {Array<number>} arr - An array containing numbers from which interval is calculated.
95
- * @return {number|undefined} The interval between numbers in the sorted array, or undefined if the array has only one element.
96
- */
97
- export function findInterval(arr) {
98
- if (arr.length <= 1) {
99
- return
100
- }
101
-
102
- // Sort array ascending
103
- arr.sort(function (a, b) {
104
- return a - b
105
- })
106
-
107
- // 1. Multiply array by 100
108
- arr = arr.map(function (x) {
109
- return x * 100000000
110
- })
111
-
112
- // 2. Get diffs
113
- arr = getDiffs(arr)
114
-
115
- // 3. Calculate greatest common divisor of diffs and divide by 100
116
- let interval = arr.reduce((a, b) => gcd(a, b)) / 100000000
117
- interval = Math.round((interval + Number.EPSILON) * 100000000) / 100000000
118
- return interval
119
- }
@@ -1,16 +0,0 @@
1
- import {replaceNully} from '@tidyjs/tidy'
2
-
3
- import {tidyWithTypes} from './tidyWithTypes.js'
4
-
5
- export default function replaceNulls(data, columns) {
6
- let colObj = {}
7
- if (typeof columns === 'object') {
8
- for (let i = 0; i < columns.length; i++) {
9
- colObj[columns[i]] = 0
10
- }
11
- } else {
12
- colObj[columns] = 0
13
- }
14
- data = tidyWithTypes(data, replaceNully(colObj))
15
- return data
16
- }
@@ -1,107 +0,0 @@
1
- import {strictBuild} from './chartContext.js'
2
-
3
- type ColumnSummary = {
4
- id: string
5
- type?: string
6
- format?: any
7
- columnUnitSummary?: any
8
- }
9
-
10
- type ColumnOption = {
11
- id: string
12
- }
13
-
14
- type ColumnLike = ColumnOption & Partial<ColumnSummary>
15
-
16
- export const safeExtractColumn = <T extends ColumnLike>(column: T, columnSummary: ColumnSummary[]): ColumnSummary => {
17
- let foundCols = columnSummary.filter(d => d.id === column.id)
18
- if (!foundCols.length) {
19
- let error = column.id === undefined ? new Error('please add an "id" property to all the <Column ... />') : new Error(`column with id: "${column.id}" not found`)
20
- if (strictBuild) throw error
21
- console.warn(error.message)
22
- return {id: column.id ?? ''}
23
- }
24
- return foundCols[0]
25
- }
26
-
27
- export const weightedMean = (data: Record<string, unknown>[], valueCol: string, weightCol?: string | null): number | null => {
28
- if (!weightCol) return null
29
- if (!data.length) return null
30
-
31
- let totalWeightedValue = 0
32
- let totalWeight = 0
33
-
34
- for (let item of data) {
35
- let value = Number(item[valueCol] ?? 0)
36
- let weight = Number(item[weightCol] ?? 0)
37
- totalWeightedValue += value * weight
38
- totalWeight += weight
39
- }
40
-
41
- return totalWeight > 0 ? totalWeightedValue / totalWeight : 0
42
- }
43
-
44
- export const median = (data: Record<string, unknown>[], column: string): number => {
45
- let values = data
46
- .map(item => item[column])
47
- .filter(val => val !== undefined && val !== null && !Number.isNaN(Number(val)))
48
- .map(val => Number(val))
49
- .sort((a, b) => a - b)
50
-
51
- if (!values.length) return 0
52
-
53
- let mid = Math.floor(values.length / 2)
54
- return values.length % 2 !== 0 ? values[mid] : (values[mid - 1] + values[mid]) / 2
55
- }
56
-
57
- export const aggregateColumn = (data: Record<string, unknown>[], columnName: string, aggType: string | undefined, columnType?: string, weightColumnName?: string | null): number | string | null => {
58
- if (!data || !data.length) return null
59
-
60
- if (!aggType && columnType === 'number') aggType = 'sum'
61
-
62
- if (columnType !== 'number' && ['sum', 'min', 'max', 'mean', 'weightedMean', 'median', undefined].includes(aggType as any)) {
63
- return '-'
64
- }
65
-
66
- let columnValues = data
67
- .map(row => row[columnName])
68
- .filter(val => val !== undefined && val !== null)
69
- .map(val => Number(val))
70
-
71
- switch (aggType) {
72
- case 'sum':
73
- return columnValues.reduce((sum, val) => sum + Number(val), 0)
74
- case 'min':
75
- return Math.min(...columnValues)
76
- case 'max':
77
- return Math.max(...columnValues)
78
- case 'mean':
79
- return columnValues.length ? columnValues.reduce((sum, val) => sum + Number(val), 0) / columnValues.length : '-'
80
- case 'count':
81
- return data.length
82
- case 'countDistinct':
83
- return new Set(columnValues).size
84
- case 'weightedMean':
85
- if (!weightColumnName) return 'Weight column name required for weightedMean'
86
- let totalWeight = 0
87
- let weightedSum = 0
88
- for (let row of data) {
89
- let weight = Number(row[weightColumnName] ?? 0)
90
- totalWeight += weight
91
- weightedSum += Number(row[columnName] ?? 0) * weight
92
- }
93
- return totalWeight > 0 ? weightedSum / totalWeight : null
94
- case 'median':
95
- return median(data, columnName)
96
- case undefined:
97
- return '-'
98
- default:
99
- return aggType ?? '-'
100
- }
101
- }
102
-
103
- export const getFinalColumnOrder = (columns: string[], priorityColumns: Array<string | undefined>): string[] => {
104
- let priorities = priorityColumns.filter(Boolean) as string[]
105
- let restColumns = columns.filter(key => !priorities.includes(key))
106
- return [...priorities, ...restColumns]
107
- }
@@ -1,9 +0,0 @@
1
- import {tidy} from '@tidyjs/tidy'
2
-
3
- export function tidyWithTypes(data, ...ops) {
4
- let result = tidy(data, ...ops)
5
- if (Array.isArray(data?._evidenceColumnTypes)) {
6
- result._evidenceColumnTypes = data._evidenceColumnTypes
7
- }
8
- return result
9
- }