@graphenedata/cli 0.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 (123) hide show
  1. package/LICENSE.md +100 -0
  2. package/THIRD_PARTY_NOTICES.md +12 -0
  3. package/cli.ts +157 -0
  4. package/dist/cli/cli.js +43 -0
  5. package/dist/docs/data_apps/components/charts/annotations.md +673 -0
  6. package/dist/docs/data_apps/components/charts/area-chart.md +202 -0
  7. package/dist/docs/data_apps/components/charts/bar-chart.md +317 -0
  8. package/dist/docs/data_apps/components/charts/box-plot.md +190 -0
  9. package/dist/docs/data_apps/components/charts/bubble-chart.md +151 -0
  10. package/dist/docs/data_apps/components/charts/calendar-heatmap.md +112 -0
  11. package/dist/docs/data_apps/components/charts/custom-echarts.md +308 -0
  12. package/dist/docs/data_apps/components/charts/echarts-options.md +217 -0
  13. package/dist/docs/data_apps/components/charts/funnel-chart.md +106 -0
  14. package/dist/docs/data_apps/components/charts/heatmap.md +180 -0
  15. package/dist/docs/data_apps/components/charts/histogram.md +107 -0
  16. package/dist/docs/data_apps/components/charts/line-chart.md +265 -0
  17. package/dist/docs/data_apps/components/charts/mixed-type-charts.md +240 -0
  18. package/dist/docs/data_apps/components/charts/sankey-diagram.md +301 -0
  19. package/dist/docs/data_apps/components/charts/scatter-plot.md +134 -0
  20. package/dist/docs/data_apps/components/charts/sparkline.md +68 -0
  21. package/dist/docs/data_apps/components/data/big-value.md +153 -0
  22. package/dist/docs/data_apps/components/data/delta.md +89 -0
  23. package/dist/docs/data_apps/components/data/table.md +470 -0
  24. package/dist/docs/data_apps/components/data/value.md +97 -0
  25. package/dist/docs/data_apps/components/inputs/button-group.md +154 -0
  26. package/dist/docs/data_apps/components/inputs/checkbox.md +52 -0
  27. package/dist/docs/data_apps/components/inputs/date-input.md +131 -0
  28. package/dist/docs/data_apps/components/inputs/date-range.md +124 -0
  29. package/dist/docs/data_apps/components/inputs/dimension-grid.md +67 -0
  30. package/dist/docs/data_apps/components/inputs/dropdown.md +199 -0
  31. package/dist/docs/data_apps/components/inputs/index.md +3 -0
  32. package/dist/docs/data_apps/components/inputs/slider.md +126 -0
  33. package/dist/docs/data_apps/components/inputs/text-input.md +86 -0
  34. package/dist/docs/data_apps/components/maps/area-map.md +397 -0
  35. package/dist/docs/data_apps/components/maps/base-map.md +269 -0
  36. package/dist/docs/data_apps/components/maps/bubble-map.md +361 -0
  37. package/dist/docs/data_apps/components/maps/point-map.md +326 -0
  38. package/dist/docs/data_apps/components/maps/us-map.md +167 -0
  39. package/dist/docs/data_apps/components/ui/accordion.md +116 -0
  40. package/dist/docs/data_apps/components/ui/alert.md +37 -0
  41. package/dist/docs/data_apps/components/ui/big-link.md +19 -0
  42. package/dist/docs/data_apps/components/ui/details.md +58 -0
  43. package/dist/docs/data_apps/components/ui/download-data.md +41 -0
  44. package/dist/docs/data_apps/components/ui/embed.md +47 -0
  45. package/dist/docs/data_apps/components/ui/grid.md +45 -0
  46. package/dist/docs/data_apps/components/ui/image.md +61 -0
  47. package/dist/docs/data_apps/components/ui/info.md +47 -0
  48. package/dist/docs/data_apps/components/ui/last-refreshed.md +28 -0
  49. package/dist/docs/data_apps/components/ui/link-button.md +20 -0
  50. package/dist/docs/data_apps/components/ui/link.md +40 -0
  51. package/dist/docs/data_apps/components/ui/modal.md +57 -0
  52. package/dist/docs/data_apps/components/ui/note.md +32 -0
  53. package/dist/docs/data_apps/components/ui/print-format-components.md +85 -0
  54. package/dist/docs/data_apps/components/ui/tabs.md +122 -0
  55. package/dist/docs/graphene.md +129 -0
  56. package/dist/ui/app.css +332 -0
  57. package/dist/ui/assets/favicon.ico +0 -0
  58. package/dist/ui/component-utilities/autoFormatting.js +301 -0
  59. package/dist/ui/component-utilities/builtInFormats.js +482 -0
  60. package/dist/ui/component-utilities/chartContext.js +12 -0
  61. package/dist/ui/component-utilities/chartWindowDebug.js +21 -0
  62. package/dist/ui/component-utilities/checkInputs.js +95 -0
  63. package/dist/ui/component-utilities/convert.js +15 -0
  64. package/dist/ui/component-utilities/dateParsing.js +57 -0
  65. package/dist/ui/component-utilities/dropdownContext.ts +1 -0
  66. package/dist/ui/component-utilities/echarts.js +262 -0
  67. package/dist/ui/component-utilities/echartsThemes.js +453 -0
  68. package/dist/ui/component-utilities/formatTitle.js +24 -0
  69. package/dist/ui/component-utilities/formatting.js +258 -0
  70. package/dist/ui/component-utilities/getColumnExtents.js +79 -0
  71. package/dist/ui/component-utilities/getColumnSummary.js +67 -0
  72. package/dist/ui/component-utilities/getCompletedData.js +114 -0
  73. package/dist/ui/component-utilities/getDistinctCount.js +7 -0
  74. package/dist/ui/component-utilities/getDistinctValues.js +15 -0
  75. package/dist/ui/component-utilities/getSeriesConfig.js +236 -0
  76. package/dist/ui/component-utilities/getSortedData.js +7 -0
  77. package/dist/ui/component-utilities/getStackPercentages.js +43 -0
  78. package/dist/ui/component-utilities/getStackedData.js +17 -0
  79. package/dist/ui/component-utilities/getYAxisIndex.js +15 -0
  80. package/dist/ui/component-utilities/globalContexts.js +1 -0
  81. package/dist/ui/component-utilities/helpers/getCompletedData.helpers.js +119 -0
  82. package/dist/ui/component-utilities/inputUtils.ts +25 -0
  83. package/dist/ui/component-utilities/replaceNulls.js +14 -0
  84. package/dist/ui/component-utilities/tableUtils.ts +120 -0
  85. package/dist/ui/component-utilities/themeStores.ts +116 -0
  86. package/dist/ui/components/Area.svelte +174 -0
  87. package/dist/ui/components/AreaChart.svelte +150 -0
  88. package/dist/ui/components/Bar.svelte +326 -0
  89. package/dist/ui/components/BarChart.svelte +194 -0
  90. package/dist/ui/components/BigValue.svelte +69 -0
  91. package/dist/ui/components/Chart.svelte +1070 -0
  92. package/dist/ui/components/Column.svelte +172 -0
  93. package/dist/ui/components/DateRange.svelte +324 -0
  94. package/dist/ui/components/Dropdown.svelte +738 -0
  95. package/dist/ui/components/DropdownOption.svelte +21 -0
  96. package/dist/ui/components/ECharts.svelte +77 -0
  97. package/dist/ui/components/ErrorChart.svelte +54 -0
  98. package/dist/ui/components/GrapheneQuery.svelte +12 -0
  99. package/dist/ui/components/InlineDelta.svelte +150 -0
  100. package/dist/ui/components/Line.svelte +210 -0
  101. package/dist/ui/components/LineChart.svelte +178 -0
  102. package/dist/ui/components/PieChart.svelte +36 -0
  103. package/dist/ui/components/QueryLoad.svelte +82 -0
  104. package/dist/ui/components/Row.svelte +14 -0
  105. package/dist/ui/components/SortIcon.svelte +32 -0
  106. package/dist/ui/components/Table.svelte +19 -0
  107. package/dist/ui/components/TableCell.svelte +75 -0
  108. package/dist/ui/components/TableGroupRow.svelte +136 -0
  109. package/dist/ui/components/TableGroupToggle.svelte +42 -0
  110. package/dist/ui/components/TableHeader.svelte +242 -0
  111. package/dist/ui/components/TableRow.svelte +283 -0
  112. package/dist/ui/components/TableSubtotalRow.svelte +62 -0
  113. package/dist/ui/components/TableTotalRow.svelte +88 -0
  114. package/dist/ui/components/TextInput.svelte +92 -0
  115. package/dist/ui/components/_Table.svelte +516 -0
  116. package/dist/ui/internal/clientCache.ts +43 -0
  117. package/dist/ui/internal/queryEngine.ts +169 -0
  118. package/dist/ui/internal/telemetry.ts +28 -0
  119. package/dist/ui/internal/theme.ts +88 -0
  120. package/dist/ui/layout.svelte +3 -0
  121. package/dist/ui/playwright.config.ts +30 -0
  122. package/dist/ui/web.js +106 -0
  123. package/package.json +71 -0
@@ -0,0 +1,482 @@
1
+ import {AUTO_FORMAT_CODE, applyColumnUnits, generateImplicitNumberFormat} from './autoFormatting'
2
+ import ssf from 'ssf'
3
+
4
+ export const SUPPORTED_CURRENCIES = [
5
+ {
6
+ primaryCode: 'usd',
7
+ currencySymbol: '$',
8
+ displayName: 'USD - United States Dollar',
9
+ },
10
+ {
11
+ primaryCode: 'aud',
12
+ currencySymbol: 'A$',
13
+ displayName: 'AUD - Australian Dollar',
14
+ escapeCurrencySymbol: true,
15
+ },
16
+ {
17
+ primaryCode: 'brl',
18
+ currencySymbol: 'R$',
19
+ displayName: 'BRL - Brazilian Real',
20
+ escapeCurrencySymbol: true,
21
+ },
22
+ {
23
+ primaryCode: 'cad',
24
+ currencySymbol: 'C$',
25
+ displayName: 'CAD - Canadian Dollar',
26
+ escapeCurrencySymbol: true,
27
+ },
28
+ {
29
+ primaryCode: 'cny',
30
+ currencySymbol: '¥',
31
+ displayName: 'CNY - Renminbi',
32
+ escapeCurrencySymbol: true,
33
+ },
34
+ {primaryCode: 'eur', currencySymbol: '€', displayName: 'EUR - Euro'},
35
+ {
36
+ primaryCode: 'gbp',
37
+ currencySymbol: '£',
38
+ displayName: 'GBP - Pound Sterling',
39
+ escapeCurrencySymbol: true,
40
+ },
41
+ {
42
+ primaryCode: 'jpy',
43
+ currencySymbol: '¥',
44
+ displayName: 'JPY - Japanese Yen',
45
+ escapeCurrencySymbol: true,
46
+ },
47
+ {
48
+ primaryCode: 'inr',
49
+ currencySymbol: '₹',
50
+ displayName: 'INR - Indian Rupee',
51
+ escapeCurrencySymbol: true,
52
+ },
53
+ {
54
+ primaryCode: 'krw',
55
+ currencySymbol: '₩',
56
+ displayName: 'KRW - South Korean won',
57
+ escapeCurrencySymbol: true,
58
+ },
59
+ {
60
+ primaryCode: 'ngn',
61
+ currencySymbol: '₦',
62
+ displayName: 'NGN - Nigerian Naira',
63
+ escapeCurrencySymbol: true,
64
+ },
65
+ {
66
+ primaryCode: 'rub',
67
+ currencySymbol: 'rub',
68
+ displayName: 'RUB - Russian Ruble',
69
+ escapeCurrencySymbol: true,
70
+ },
71
+ {
72
+ primaryCode: 'sek',
73
+ currencySymbol: 'kr',
74
+ displayName: 'SEK - Swedish Krona',
75
+ escapeCurrencySymbol: true,
76
+ },
77
+ ]
78
+
79
+ const DERIVED_CURRENCY_FORMATS = [
80
+ {
81
+ derivedSuffix: '',
82
+ valueFormatCode: '#,##0',
83
+ exampleInput: 412.17,
84
+ auto: true,
85
+ },
86
+ {
87
+ derivedSuffix: '0',
88
+ valueFormatCode: '#,##0',
89
+ exampleInput: 7043.123,
90
+ },
91
+ {
92
+ derivedSuffix: '1',
93
+ valueFormatCode: '#,##0.0',
94
+ exampleInput: 7043.123,
95
+ },
96
+ {
97
+ derivedSuffix: '2',
98
+ valueFormatCode: '#,##0.00',
99
+ exampleInput: 7043.123,
100
+ },
101
+ {
102
+ derivedSuffix: '0k',
103
+ valueFormatCode: '#,##0,"k"',
104
+ exampleInput: 64301.12,
105
+ },
106
+ {
107
+ derivedSuffix: '1k',
108
+ valueFormatCode: '#,##0.0,"k"',
109
+ exampleInput: 64301.12,
110
+ },
111
+ {
112
+ derivedSuffix: '2k',
113
+ valueFormatCode: '#,##0.00,"k"',
114
+ exampleInput: 64301.12,
115
+ },
116
+ {
117
+ derivedSuffix: '0m',
118
+ valueFormatCode: '#,##0,,"M"',
119
+ exampleInput: 4564301.12,
120
+ },
121
+ {
122
+ derivedSuffix: '1m',
123
+ valueFormatCode: '#,##0.0,,"M"',
124
+ exampleInput: 4564301.12,
125
+ },
126
+ {
127
+ derivedSuffix: '2m',
128
+ valueFormatCode: '#,##0.00,,"M"',
129
+ exampleInput: 4564301.12,
130
+ },
131
+ {
132
+ derivedSuffix: '0b',
133
+ valueFormatCode: '#,##0,,,"B"',
134
+ exampleInput: 9784564301.12,
135
+ },
136
+ {
137
+ derivedSuffix: '1b',
138
+ valueFormatCode: '#,##0.0,,,"B"',
139
+ exampleInput: 9784564301.12,
140
+ },
141
+ {
142
+ derivedSuffix: '2b',
143
+ valueFormatCode: '#,##0.00,,,"B"',
144
+ exampleInput: 9784564301.12,
145
+ },
146
+ ]
147
+
148
+ const CURRENCY_FORMATS = SUPPORTED_CURRENCIES.map((currency) => {
149
+ let derivedFormats = []
150
+ DERIVED_CURRENCY_FORMATS.forEach((derivedFormat) => {
151
+ let next = {
152
+ formatTag: currency.primaryCode + derivedFormat.derivedSuffix,
153
+ parentFormat: currency.primaryCode,
154
+ formatCategory: 'currency',
155
+ valueType: 'number',
156
+ exampleInput: derivedFormat.exampleInput,
157
+ titleTagReplacement: ` (${currency.currencySymbol})`,
158
+ }
159
+ let symbolInFormatCode = currency.escapeCurrencySymbol
160
+ ? `"${currency.currencySymbol}"`
161
+ : currency.currencySymbol
162
+ if (derivedFormat.auto || AUTO_FORMAT_CODE === derivedFormat.formatCode) {
163
+ next.formatCode = AUTO_FORMAT_CODE
164
+ //TODO This should be fixed so that 1)the format is NOT recomputed for each value, 2)remove some of magic is done to make it look good.
165
+ next._autoFormat = {
166
+ autoFormatFunction: (typedValue, columnFormat, columnUnitSummary) => {
167
+ let format = generateImplicitNumberFormat(columnUnitSummary, 2)
168
+ let effectiveCode = `${symbolInFormatCode}${format._autoFormat.autoFormatCode}`
169
+ let suffix = ''
170
+ let displayValue = typedValue
171
+ if (format._autoFormat.truncateUnits && format._autoFormat.columnUnits) {
172
+ suffix = format._autoFormat.columnUnits
173
+ displayValue = applyColumnUnits(typedValue, format._autoFormat.columnUnits)
174
+ } else {
175
+ if (effectiveCode.endsWith('.0')) {
176
+ effectiveCode = effectiveCode + '0'
177
+ }
178
+ }
179
+ return ssf.format(effectiveCode, displayValue) + suffix
180
+ },
181
+ }
182
+ } else {
183
+ next.formatCode = `${symbolInFormatCode}${derivedFormat.valueFormatCode}`
184
+ }
185
+ if (derivedFormat.axisValueFormatCode) {
186
+ next.axisFormatCode = derivedFormat.axisValueFormatCode
187
+ }
188
+ derivedFormats.push(next)
189
+ })
190
+ return derivedFormats
191
+ }).flat()
192
+
193
+ export const BUILT_IN_FORMATS = [
194
+ ...CURRENCY_FORMATS,
195
+ //auto formats
196
+ // Date/Time:
197
+ {
198
+ formatTag: 'ddd',
199
+ formatCode: 'ddd',
200
+ formatCategory: 'date',
201
+ valueType: 'date',
202
+ exampleInput: '2022-01-09 12:45',
203
+ },
204
+ {
205
+ formatTag: 'dddd',
206
+ formatCode: 'dddd',
207
+ formatCategory: 'date',
208
+ valueType: 'date',
209
+ exampleInput: '2022-01-09 12:45',
210
+ },
211
+ {
212
+ formatTag: 'mmm',
213
+ formatCode: 'mmm',
214
+ formatCategory: 'date',
215
+ valueType: 'date',
216
+ exampleInput: '2022-01-09 12:45',
217
+ },
218
+ {
219
+ formatTag: 'mmmm',
220
+ formatCode: 'mmmm',
221
+ formatCategory: 'date',
222
+ valueType: 'date',
223
+ exampleInput: '2022-01-09 12:45',
224
+ },
225
+ {
226
+ formatTag: 'yyyy',
227
+ formatCode: 'yyyy',
228
+ formatCategory: 'date',
229
+ valueType: 'date',
230
+ exampleInput: '2022-01-09 12:45',
231
+ },
232
+ {
233
+ formatTag: 'shortdate',
234
+ formatCode: 'mmm d/yy',
235
+ formatCategory: 'date',
236
+ valueType: 'date',
237
+ exampleInput: '2022-01-09 12:45',
238
+ },
239
+ {
240
+ formatTag: 'longdate',
241
+ formatCode: 'mmmm d, yyyy',
242
+ formatCategory: 'date',
243
+ valueType: 'date',
244
+ exampleInput: '2022-01-09 12:45',
245
+ },
246
+ {
247
+ formatTag: 'fulldate',
248
+ formatCode: 'dddd mmmm d, yyyy',
249
+ formatCategory: 'date',
250
+ valueType: 'date',
251
+ exampleInput: '2022-01-09 12:45',
252
+ },
253
+ {
254
+ formatTag: 'mdy',
255
+ formatCode: 'm/d/y',
256
+ formatCategory: 'date',
257
+ valueType: 'date',
258
+ exampleInput: '2022-01-09 12:45',
259
+ },
260
+ {
261
+ formatTag: 'dmy',
262
+ formatCode: 'd/m/y',
263
+ formatCategory: 'date',
264
+ valueType: 'date',
265
+ exampleInput: '2022-01-09 12:45',
266
+ },
267
+ {
268
+ formatTag: 'hms',
269
+ formatCode: 'H:MM:SS AM/PM',
270
+ formatCategory: 'date',
271
+ valueType: 'date',
272
+ exampleInput: '2022-01-09T11:45:03',
273
+ },
274
+ // Numbers:
275
+ {
276
+ formatTag: 'num0',
277
+ formatCode: '#,##0',
278
+ formatCategory: 'number',
279
+ valueType: 'number',
280
+ exampleInput: 11.23168,
281
+ },
282
+ {
283
+ formatTag: 'num1',
284
+ formatCode: '#,##0.0',
285
+ formatCategory: 'number',
286
+ valueType: 'number',
287
+ exampleInput: 11.23168,
288
+ },
289
+ {
290
+ formatTag: 'num2',
291
+ formatCode: '#,##0.00',
292
+ formatCategory: 'number',
293
+ valueType: 'number',
294
+ exampleInput: 11.23168,
295
+ },
296
+ {
297
+ formatTag: 'num3',
298
+ formatCode: '#,##0.000',
299
+ formatCategory: 'number',
300
+ valueType: 'number',
301
+ exampleInput: 11.23168,
302
+ },
303
+ {
304
+ formatTag: 'num4',
305
+ formatCode: '#,##0.0000',
306
+ formatCategory: 'number',
307
+ valueType: 'number',
308
+ exampleInput: 11.23168,
309
+ },
310
+ {
311
+ formatTag: 'num0k',
312
+ formatCode: '#,##0,"k"',
313
+ formatCategory: 'number',
314
+ valueType: 'number',
315
+ exampleInput: 64201,
316
+ },
317
+ {
318
+ formatTag: 'num1k',
319
+ formatCode: '#,##0.0,"k"',
320
+ formatCategory: 'number',
321
+ valueType: 'number',
322
+ exampleInput: 64201,
323
+ },
324
+ {
325
+ formatTag: 'num2k',
326
+ formatCode: '#,##0.00,"k"',
327
+ formatCategory: 'number',
328
+ valueType: 'number',
329
+ exampleInput: 64201,
330
+ },
331
+ {
332
+ formatTag: 'num0m',
333
+ formatCode: '#,##0,,"M"',
334
+ formatCategory: 'number',
335
+ valueType: 'number',
336
+ exampleInput: 42539483,
337
+ },
338
+ {
339
+ formatTag: 'num1m',
340
+ formatCode: '#,##0.0,,"M"',
341
+ formatCategory: 'number',
342
+ valueType: 'number',
343
+ exampleInput: 42539483,
344
+ },
345
+ {
346
+ formatTag: 'num2m',
347
+ formatCode: '#,##0.00,,"M"',
348
+ formatCategory: 'number',
349
+ valueType: 'number',
350
+ exampleInput: 42539483,
351
+ },
352
+ {
353
+ formatTag: 'num0b',
354
+ formatCode: '#,##0,,,"B"',
355
+ formatCategory: 'number',
356
+ valueType: 'number',
357
+ exampleInput: 1384937584,
358
+ },
359
+ {
360
+ formatTag: 'num1b',
361
+ formatCode: '#,##0.0,,,"B"',
362
+ formatCategory: 'number',
363
+ valueType: 'number',
364
+ exampleInput: 1384937584,
365
+ },
366
+ {
367
+ formatTag: 'num2b',
368
+ formatCode: '#,##0.00,,,"B"',
369
+ formatCategory: 'number',
370
+ valueType: 'number',
371
+ exampleInput: 1384937584,
372
+ },
373
+ {
374
+ formatTag: 'id',
375
+ formatCode: '0',
376
+ formatCategory: 'number',
377
+ valueType: 'number',
378
+ exampleInput: '921594675',
379
+ titleTagReplacement: ' id',
380
+ },
381
+ {
382
+ formatTag: 'fract',
383
+ formatCode: '# ?/?',
384
+ formatCategory: 'number',
385
+ valueType: 'number',
386
+ exampleInput: '0.25',
387
+ },
388
+ {
389
+ formatTag: 'mult',
390
+ formatCode: '#,##0.0"x"',
391
+ formatCategory: 'number',
392
+ valueType: 'number',
393
+ exampleInput: '5.32',
394
+ },
395
+ {
396
+ formatTag: 'mult0',
397
+ formatCode: '#,##0"x"',
398
+ formatCategory: 'number',
399
+ valueType: 'number',
400
+ exampleInput: '5.32',
401
+ },
402
+ {
403
+ formatTag: 'mult1',
404
+ formatCode: '#,##0.0"x"',
405
+ formatCategory: 'number',
406
+ valueType: 'number',
407
+ exampleInput: '5.32',
408
+ },
409
+ {
410
+ formatTag: 'mult2',
411
+ formatCode: '#,##0.00"x"',
412
+ formatCategory: 'number',
413
+ valueType: 'number',
414
+ exampleInput: '5.32',
415
+ },
416
+ {
417
+ formatTag: 'sci',
418
+ formatCode: '0.00E+0',
419
+ formatCategory: 'number',
420
+ valueType: 'number',
421
+ exampleInput: '16546.1561',
422
+ },
423
+
424
+ // Percent:
425
+ {
426
+ formatTag: 'pct',
427
+ formatCode: AUTO_FORMAT_CODE,
428
+ formatCategory: 'percent',
429
+ valueType: 'number',
430
+ exampleInput: 0.731,
431
+ titleTagReplacement: '',
432
+ _autoFormat: {
433
+ autoFormatFunction: (typedValue, columnFormat, columnUnitSummary) => {
434
+ if ('number' === columnUnitSummary?.unitType) {
435
+ let adjustedColumnUnitSummary = {
436
+ min: columnUnitSummary.min * 100,
437
+ max: columnUnitSummary.max * 100,
438
+ median: columnUnitSummary.median * 100,
439
+ maxDecimals: Math.max(columnUnitSummary.maxDecimals - 2, 0),
440
+ unitType: columnUnitSummary.unitType,
441
+ }
442
+ let format = generateImplicitNumberFormat(adjustedColumnUnitSummary)
443
+ return ssf.format(format._autoFormat.autoFormatCode, typedValue * 100) + '%'
444
+ } else {
445
+ return ssf.format('#,##0%', typedValue)
446
+ }
447
+ },
448
+ },
449
+ },
450
+ {
451
+ formatTag: 'pct0',
452
+ formatCode: '#,##0%',
453
+ formatCategory: 'percent',
454
+ valueType: 'number',
455
+ exampleInput: 0.731,
456
+ titleTagReplacement: '',
457
+ },
458
+ {
459
+ formatTag: 'pct1',
460
+ formatCode: '#,##0.0%',
461
+ formatCategory: 'percent',
462
+ valueType: 'number',
463
+ exampleInput: 0.731,
464
+ titleTagReplacement: '',
465
+ },
466
+ {
467
+ formatTag: 'pct2',
468
+ formatCode: '#,##0.00%',
469
+ formatCategory: 'percent',
470
+ valueType: 'number',
471
+ exampleInput: 0.731,
472
+ titleTagReplacement: '',
473
+ },
474
+ {
475
+ formatTag: 'pct3',
476
+ formatCode: '#,##0.000%',
477
+ formatCategory: 'percent',
478
+ valueType: 'number',
479
+ exampleInput: 0.731,
480
+ titleTagReplacement: '',
481
+ },
482
+ ]
@@ -0,0 +1,12 @@
1
+ import {getContext, setContext} from 'svelte'
2
+ const configKey = Symbol()
3
+ const propKey = Symbol()
4
+
5
+ export const strictBuild = false
6
+ export {configKey, propKey}
7
+
8
+ export const getConfigContext = () => getContext(configKey)
9
+ export const setConfigContext = (v) => setContext(configKey, v)
10
+
11
+ export const getPropContext = () => getContext(propKey)
12
+ export const setPropContext = (v) => setContext(propKey, v)
@@ -0,0 +1,21 @@
1
+ const s = Symbol.for('__evidence-chart-window-debug__')
2
+ const isBrowser = typeof window !== 'undefined'
3
+
4
+ /**
5
+ * @param {string} key
6
+ * @param {unknown} value
7
+ */
8
+ export const set = (key, value) => {
9
+ if (!isBrowser) return
10
+ if (!window[s]) window[s] = {}
11
+ window[s][key] = value
12
+ }
13
+
14
+ /**
15
+ * @param {string} key
16
+ */
17
+ export const unset = (key) => {
18
+ if (!isBrowser) return
19
+ if (!window[s]) window[s] = {}
20
+ delete window[s][key]
21
+ }
@@ -0,0 +1,95 @@
1
+ export default function checkInputs (data, reqCols, optCols) {
2
+ // reqCols is an array of columns to check in the dataset
3
+ let columns = []
4
+
5
+ // Check if dataset was provided
6
+ if (data === undefined) {
7
+ throw Error('No data provided')
8
+ } else if (typeof data !== 'object') {
9
+ throw Error(
10
+ "'" +
11
+ data +
12
+ "'" +
13
+ ' is not a recognized query result. Data should be provided in the format: data = {' +
14
+ data.replace('data.', '') +
15
+ '}',
16
+ )
17
+ } else if (data[0] === undefined || data.length === 0) {
18
+ throw Error(
19
+ 'Dataset is empty: query ran successfully, but no data was returned from the database',
20
+ )
21
+ }
22
+
23
+ // Check if data warehouse returned an error
24
+ if (data[0]?.error_object?.error != null) {
25
+ throw Error('SQL Error: ' + data[0]?.error_object?.error?.message)
26
+ }
27
+
28
+ if (reqCols != undefined) {
29
+ if (!(reqCols instanceof Array)) {
30
+ throw Error('reqCols must be passed in as an array')
31
+ }
32
+
33
+ // Check if columns were provided
34
+ for (let i = 0; i < reqCols.length; i++) {
35
+ if (reqCols[i] == null) {
36
+ throw Error(`Missing required column(s): ${reqCols[i]} not found in data set.`)
37
+ } else if (reqCols[i] == '') {
38
+ throw Error(
39
+ 'Missing required column(s): A Empty string was provided for one of your props.',
40
+ )
41
+ }
42
+ }
43
+
44
+ // let errorString;
45
+ // if(missingCols.length > 0){
46
+ // errorString = missingCols[0]
47
+ // for(i = 1; i < missingCols.length; i++){
48
+ // errorString = errorString + ", " + missingCols[i];
49
+ // }
50
+ // errorString = errorString + " not provided";
51
+ // throw Error(errorString);
52
+ // }
53
+
54
+ // const dataIsQueryStore = data instanceof QueryStore;
55
+
56
+ // Get list of all columns in dataset
57
+ // we want to handle cases where the columns have not yet been fetched, but the data is avialable
58
+ // this is most likely to happen during pre-rendering, because column metadata is not yet included
59
+ // in the prerendering process
60
+ if (!data.columnsLoaded && data.dataLoaded) {
61
+ let cols = Object.keys(data[0])
62
+ for (let col of cols) {
63
+ columns.push(col)
64
+ }
65
+ } else {
66
+ for (let col of data.columns) {
67
+ columns.push(col.column_name)
68
+ }
69
+ }
70
+
71
+ // Check if provided columns are in the dataset
72
+ let currentCol
73
+ for (let i = 0; i < reqCols.length; i++) {
74
+ currentCol = reqCols[i]
75
+ if (!columns.includes(currentCol)) {
76
+ throw Error("'" + currentCol + "' is not a column in the dataset")
77
+ }
78
+ }
79
+
80
+ if (optCols != undefined && optCols.some((col) => col != null)) {
81
+ for (let i = 0; i < optCols.length; i++) {
82
+ currentCol = optCols[i]
83
+ if (currentCol == null) continue
84
+ if (!columns.includes(currentCol)) {
85
+ throw Error("'" + currentCol + "' is not a column in the dataset")
86
+ }
87
+ }
88
+ }
89
+ }
90
+ // IDEAS:
91
+ // Trigger a function call when error is caught - that function somehow sends us to the Error chart component
92
+ // rather than letting the rest of the current component file continue running?
93
+ // Almost 2 layers of error: (1) up front check errors and (2) actual execution of the chart errors
94
+ // (1) is handled here, (2) may need a wrapper around the main part of the component code
95
+ }
@@ -0,0 +1,15 @@
1
+ export const toBoolean = (value) => {
2
+ if (typeof value === 'undefined' || value === null) return undefined
3
+ if (typeof value === 'string') {
4
+ let normalized = value.trim().toLowerCase()
5
+ if (normalized === 'true') return true
6
+ if (normalized === 'false') return false
7
+ }
8
+ return Boolean(value)
9
+ }
10
+
11
+ export const toNumber = (value) => {
12
+ if (typeof value === 'undefined' || value === null) return undefined
13
+ let num = Number(value)
14
+ return Number.isNaN(num) ? undefined : num
15
+ }
@@ -0,0 +1,57 @@
1
+ import {tidy, mutate} from '@tidyjs/tidy'
2
+
3
+ export function standardizeDateString (date) {
4
+ if (date && typeof date === 'string') {
5
+ // Parses an individual string into a JS date object
6
+
7
+ let dateSplit = date.split(' ')
8
+
9
+ // If date doesn't contain timestamp, add one at midnight (avoids timezone interpretation issue)
10
+ if (!date.includes(':')) {
11
+ date = date + 'T00:00:00'
12
+ }
13
+
14
+ // Remove any character groups beyond 2 (date and time):
15
+ if (dateSplit.length > 2) {
16
+ date = dateSplit[0] + ' ' + dateSplit[1]
17
+ }
18
+
19
+ // Replace microseconds if needed:
20
+ let re = /\.([^\s]+)/
21
+ date = date.replace(re, '')
22
+
23
+ // Remove "Z" to avoid timezone interpretation issue:
24
+ date = date.replace('Z', '')
25
+
26
+ // Replace spaces with "T" to conform to ECMA standard:
27
+ date = date.replace(' ', 'T')
28
+ }
29
+
30
+ return date
31
+ }
32
+
33
+ export function convertColumnToDate (data, column) {
34
+ // Replaces a date column's string values with JS date objects, using the standardizeDateString function
35
+
36
+ let converted = tidy(
37
+ data,
38
+ mutate({[column]: (d) => (d[column] ? new Date(standardizeDateString(d[column])) : null)}),
39
+ )
40
+
41
+ if (data && typeof data === 'object') {
42
+ for (let key of Object.keys(data)) {
43
+ if (!/^\d+$/.test(key)) converted[key] = data[key]
44
+ }
45
+ }
46
+
47
+ return converted
48
+ }
49
+
50
+ export function standardizeDateColumn (data, column) {
51
+ // Replaces a date column's string values with standardized date strings, using the standardizeDateString function
52
+ // Used in Chart.svelte, where using Date objects leads to errors
53
+
54
+ data = tidy(data, mutate({[column]: (d) => standardizeDateString(d[column])}))
55
+
56
+ return data
57
+ }
@@ -0,0 +1 @@
1
+ export const DROPDOWN_CONTEXT = Symbol('DropdownContext')