@quillsql/react 1.7.2 → 1.7.4
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.
- package/lib/AddToDashboardModal.js +249 -369
- package/lib/AddToDashboardModal.js.map +1 -1
- package/lib/BarList.js +92 -109
- package/lib/BarList.js.map +1 -1
- package/lib/Chart.d.ts +0 -1
- package/lib/Chart.js +359 -419
- package/lib/Chart.js.map +1 -1
- package/lib/Context.d.ts +1 -2
- package/lib/Context.js +91 -85
- package/lib/Context.js.map +1 -1
- package/lib/Dashboard.js +181 -209
- package/lib/Dashboard.js.map +1 -1
- package/lib/DateRangePicker/Calendar.js +87 -91
- package/lib/DateRangePicker/Calendar.js.map +1 -1
- package/lib/DateRangePicker/DateRangePicker.js +70 -68
- package/lib/DateRangePicker/DateRangePicker.js.map +1 -1
- package/lib/DateRangePicker/DateRangePickerButton.js +46 -57
- package/lib/DateRangePicker/DateRangePickerButton.js.map +1 -1
- package/lib/DateRangePicker/dateRangePickerUtils.js +105 -99
- package/lib/DateRangePicker/dateRangePickerUtils.js.map +1 -1
- package/lib/DateRangePicker/index.js +8 -1
- package/lib/DateRangePicker/index.js.map +1 -1
- package/lib/PieChart.js +221 -225
- package/lib/PieChart.js.map +1 -1
- package/lib/QuillProvider.d.ts +1 -2
- package/lib/QuillProvider.js +8 -18
- package/lib/QuillProvider.js.map +1 -1
- package/lib/ReportBuilder.js +430 -526
- package/lib/ReportBuilder.js.map +1 -1
- package/lib/SQLEditor.js +182 -268
- package/lib/SQLEditor.js.map +1 -1
- package/lib/Table.js +207 -261
- package/lib/Table.js.map +1 -1
- package/lib/TableChart.js +76 -75
- package/lib/TableChart.js.map +1 -1
- package/lib/assets/ArrowDownHeadIcon.js +5 -28
- package/lib/assets/ArrowDownHeadIcon.js.map +1 -1
- package/lib/assets/ArrowDownIcon.js +5 -28
- package/lib/assets/ArrowDownIcon.js.map +1 -1
- package/lib/assets/ArrowDownRightIcon.js +5 -28
- package/lib/assets/ArrowDownRightIcon.js.map +1 -1
- package/lib/assets/ArrowLeftHeadIcon.js +5 -28
- package/lib/assets/ArrowLeftHeadIcon.js.map +1 -1
- package/lib/assets/ArrowRightHeadIcon.js +5 -28
- package/lib/assets/ArrowRightHeadIcon.js.map +1 -1
- package/lib/assets/ArrowRightIcon.js +5 -28
- package/lib/assets/ArrowRightIcon.js.map +1 -1
- package/lib/assets/ArrowUpHeadIcon.js +5 -28
- package/lib/assets/ArrowUpHeadIcon.js.map +1 -1
- package/lib/assets/ArrowUpIcon.js +5 -28
- package/lib/assets/ArrowUpIcon.js.map +1 -1
- package/lib/assets/ArrowUpRightIcon.js +5 -28
- package/lib/assets/ArrowUpRightIcon.js.map +1 -1
- package/lib/assets/CalendarIcon.js +5 -28
- package/lib/assets/CalendarIcon.js.map +1 -1
- package/lib/assets/DoubleArrowLeftHeadIcon.js +5 -28
- package/lib/assets/DoubleArrowLeftHeadIcon.js.map +1 -1
- package/lib/assets/DoubleArrowRightHeadIcon.js +5 -28
- package/lib/assets/DoubleArrowRightHeadIcon.js.map +1 -1
- package/lib/assets/ExclamationFilledIcon.js +5 -28
- package/lib/assets/ExclamationFilledIcon.js.map +1 -1
- package/lib/assets/LoadingSpinner.js +5 -28
- package/lib/assets/LoadingSpinner.js.map +1 -1
- package/lib/assets/SearchIcon.js +5 -28
- package/lib/assets/SearchIcon.js.map +1 -1
- package/lib/assets/XCircleIcon.js +5 -28
- package/lib/assets/XCircleIcon.js.map +1 -1
- package/lib/assets/index.js +38 -16
- package/lib/assets/index.js.map +1 -1
- package/lib/components/BigModal/BigModal.js +45 -43
- package/lib/components/BigModal/BigModal.js.map +1 -1
- package/lib/components/Dropdown/Dropdown.js +57 -53
- package/lib/components/Dropdown/Dropdown.js.map +1 -1
- package/lib/components/Dropdown/DropdownItem.js +43 -40
- package/lib/components/Dropdown/DropdownItem.js.map +1 -1
- package/lib/components/Dropdown/index.js +10 -2
- package/lib/components/Dropdown/index.js.map +1 -1
- package/lib/components/Modal/Modal.js +45 -43
- package/lib/components/Modal/Modal.js.map +1 -1
- package/lib/components/Modal/index.js +8 -1
- package/lib/components/Modal/index.js.map +1 -1
- package/lib/components/selectUtils.js +20 -15
- package/lib/components/selectUtils.js.map +1 -1
- package/lib/contexts/BaseColorContext.js +5 -3
- package/lib/contexts/BaseColorContext.js.map +1 -1
- package/lib/contexts/HoveredValueContext.js +5 -3
- package/lib/contexts/HoveredValueContext.js.map +1 -1
- package/lib/contexts/RootStylesContext.js +5 -3
- package/lib/contexts/RootStylesContext.js.map +1 -1
- package/lib/contexts/SelectedValueContext.js +5 -3
- package/lib/contexts/SelectedValueContext.js.map +1 -1
- package/lib/contexts/index.js +14 -4
- package/lib/contexts/index.js.map +1 -1
- package/lib/hooks/index.js +14 -4
- package/lib/hooks/index.js.map +1 -1
- package/lib/hooks/useInternalState.js +9 -7
- package/lib/hooks/useInternalState.js.map +1 -1
- package/lib/hooks/useOnClickOutside.js +8 -6
- package/lib/hooks/useOnClickOutside.js.map +1 -1
- package/lib/hooks/useOnWindowResize.js +9 -7
- package/lib/hooks/useOnWindowResize.js.map +1 -1
- package/lib/hooks/useQuill.js +60 -111
- package/lib/hooks/useQuill.js.map +1 -1
- package/lib/hooks/useSelectOnKeyDown.js +17 -15
- package/lib/hooks/useSelectOnKeyDown.js.map +1 -1
- package/lib/index.js +22 -8
- package/lib/index.js.map +1 -1
- package/lib/lib/font.d.ts +13 -0
- package/lib/lib/font.js +17 -0
- package/lib/lib/font.js.map +1 -0
- package/lib/lib/index.d.ts +3 -0
- package/lib/lib/index.js +20 -0
- package/lib/lib/index.js.map +1 -0
- package/lib/lib/inputTypes.d.ts +20 -0
- package/lib/lib/inputTypes.js +57 -0
- package/lib/lib/inputTypes.js.map +1 -0
- package/lib/lib/utils.d.ts +9 -0
- package/lib/lib/utils.js +46 -0
- package/lib/lib/utils.js.map +1 -0
- package/package.json +6 -13
- package/src/AddToDashboardModal.tsx +2 -9
- package/src/Chart.tsx +49 -20
- package/src/Context.tsx +0 -3
- package/src/Dashboard.tsx +2 -3
- package/src/PieChart.tsx +2 -2
- package/src/QuillProvider.tsx +0 -3
- package/src/ReportBuilder.tsx +3 -9
- package/src/SQLEditor.tsx +99 -12
- package/src/Table.tsx +99 -10
- package/src/hooks/useQuill.ts +1 -2
- package/src/lib/font.ts +14 -0
- package/src/lib/index.ts +3 -0
- package/src/lib/inputTypes.ts +81 -0
- package/src/lib/utils.tsx +46 -0
- package/tsconfig.json +3 -3
- package/rollup.config.ts +0 -21
package/lib/Chart.js
CHANGED
|
@@ -1,74 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
46
7
|
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
47
24
|
};
|
|
48
|
-
var
|
|
49
|
-
|
|
50
|
-
if (ar || !(i in from)) {
|
|
51
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
52
|
-
ar[i] = from[i];
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
56
27
|
};
|
|
57
|
-
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.ChartTooltipRow = exports.ChartTooltipFrame = exports.valueFormatter = void 0;
|
|
30
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
58
31
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
59
32
|
// @ts-nocheck
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
import TableChart from './TableChart';
|
|
71
|
-
var colorValues = [
|
|
33
|
+
const react_1 = require("react");
|
|
34
|
+
const recharts_1 = require("recharts");
|
|
35
|
+
const date_fns_1 = require("date-fns");
|
|
36
|
+
const date_fns_tz_1 = require("date-fns-tz");
|
|
37
|
+
const BarList_1 = __importDefault(require("./BarList"));
|
|
38
|
+
const PieChart_1 = __importStar(require("./PieChart"));
|
|
39
|
+
const axios_1 = __importDefault(require("axios"));
|
|
40
|
+
const Context_1 = require("./Context");
|
|
41
|
+
const TableChart_1 = __importDefault(require("./TableChart"));
|
|
42
|
+
const colorValues = [
|
|
72
43
|
'slate',
|
|
73
44
|
'gray',
|
|
74
45
|
'zinc',
|
|
@@ -124,21 +95,20 @@ var colorValues = [
|
|
|
124
95
|
// 'The Pragmatic Engineer': 1726,
|
|
125
96
|
// },
|
|
126
97
|
// ];
|
|
127
|
-
|
|
128
|
-
var value = _a.value, field = _a.field, fields = _a.fields;
|
|
98
|
+
const valueFormatter = ({ value, field, fields }) => {
|
|
129
99
|
if (value === undefined ||
|
|
130
100
|
value === null ||
|
|
131
101
|
field === undefined ||
|
|
132
102
|
field === null) {
|
|
133
103
|
return '';
|
|
134
104
|
}
|
|
135
|
-
|
|
105
|
+
const fieldInfo = fields.find(f => f.field === field);
|
|
136
106
|
if (!fieldInfo) {
|
|
137
107
|
return '';
|
|
138
108
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
109
|
+
const formatType = fieldInfo.format;
|
|
110
|
+
const numValue = Number(value);
|
|
111
|
+
const absNumber = isNaN(numValue) ? 0 : Math.abs(numValue);
|
|
142
112
|
if (formatType === 'percent') {
|
|
143
113
|
if (absNumber < 1) {
|
|
144
114
|
return (absNumber * 100).toFixed(0) + '%';
|
|
@@ -148,7 +118,7 @@ export var valueFormatter = function (_a) {
|
|
|
148
118
|
}
|
|
149
119
|
}
|
|
150
120
|
if (formatType === 'dollar_amount') {
|
|
151
|
-
|
|
121
|
+
const formatter = new Intl.NumberFormat('en-US', {
|
|
152
122
|
style: 'currency',
|
|
153
123
|
currency: 'USD',
|
|
154
124
|
minimumFractionDigits: 0,
|
|
@@ -175,36 +145,36 @@ export var valueFormatter = function (_a) {
|
|
|
175
145
|
formatType === 'hh_ap_pm' ||
|
|
176
146
|
formatType === 'MMM_dd-MMM_dd' ||
|
|
177
147
|
formatType === 'MMM_dd_hh:mm_ap_pm') {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
if (!isValid(utcDate)) {
|
|
148
|
+
const dateValue = new Date(value);
|
|
149
|
+
const utcDate = (0, date_fns_tz_1.utcToZonedTime)(dateValue, 'UTC');
|
|
150
|
+
if (!(0, date_fns_1.isValid)(utcDate)) {
|
|
181
151
|
return 'Invalid date';
|
|
182
152
|
}
|
|
183
153
|
if (formatType === 'MMM_yyyy') {
|
|
184
|
-
return format(utcDate, 'MMM yyyy');
|
|
154
|
+
return (0, date_fns_1.format)(utcDate, 'MMM yyyy');
|
|
185
155
|
}
|
|
186
156
|
if (formatType === 'MMM_dd_yyyy') {
|
|
187
|
-
return format(utcDate, 'dd MMM yyyy');
|
|
157
|
+
return (0, date_fns_1.format)(utcDate, 'dd MMM yyyy');
|
|
188
158
|
}
|
|
189
159
|
if (formatType === 'hh_ap_pm') {
|
|
190
|
-
return format(utcDate, 'hh:mm aa');
|
|
160
|
+
return (0, date_fns_1.format)(utcDate, 'hh:mm aa');
|
|
191
161
|
}
|
|
192
162
|
if (formatType === 'MMM_dd-MMM_dd') {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
163
|
+
const start = (0, date_fns_1.startOfWeek)(utcDate, { weekStartsOn: 1 }); // Monday
|
|
164
|
+
const end = (0, date_fns_1.endOfWeek)(utcDate, { weekStartsOn: 1 }); // Sunday
|
|
165
|
+
let formattedDate = '';
|
|
196
166
|
// Check if start and end are in the same month
|
|
197
|
-
if (format(start, 'MMM') === format(end, 'MMM')) {
|
|
198
|
-
formattedDate =
|
|
167
|
+
if ((0, date_fns_1.format)(start, 'MMM') === (0, date_fns_1.format)(end, 'MMM')) {
|
|
168
|
+
formattedDate = `${(0, date_fns_1.format)(start, 'MMM dd')} - ${(0, date_fns_1.format)(end, 'dd')}`;
|
|
199
169
|
}
|
|
200
170
|
else {
|
|
201
|
-
formattedDate =
|
|
171
|
+
formattedDate = `${(0, date_fns_1.format)(start, 'MMM dd')} - ${(0, date_fns_1.format)(end, 'MMM dd')}`;
|
|
202
172
|
}
|
|
203
173
|
return formattedDate;
|
|
204
174
|
}
|
|
205
175
|
if (formatType === 'MMM_dd_hh:mm_ap_pm') {
|
|
206
|
-
|
|
207
|
-
|
|
176
|
+
const formatStr = utcDate.getMinutes() === 0 ? 'MMM do h a' : 'MMM do h:mm a';
|
|
177
|
+
let formattedTime = (0, date_fns_1.format)(utcDate, formatStr);
|
|
208
178
|
formattedTime =
|
|
209
179
|
formattedTime.slice(0, -2) + formattedTime.slice(-2).toLowerCase();
|
|
210
180
|
return formattedTime;
|
|
@@ -215,85 +185,81 @@ export var valueFormatter = function (_a) {
|
|
|
215
185
|
}
|
|
216
186
|
return value.toString();
|
|
217
187
|
};
|
|
218
|
-
|
|
188
|
+
exports.valueFormatter = valueFormatter;
|
|
189
|
+
const yAxisFields = [
|
|
219
190
|
{ field: 'avg_days', label: 'average days' },
|
|
220
191
|
{ field: 'median_days', label: 'median days' },
|
|
221
192
|
];
|
|
222
|
-
|
|
193
|
+
const labelFormatter = (name) => {
|
|
223
194
|
// return yAxisFields.filter(elem => elem.field === name)[0].label;
|
|
224
195
|
return name;
|
|
225
196
|
};
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
fontWeight: (theme === null || theme === void 0 ? void 0 : theme.fontWeightNormal) || '400',
|
|
288
|
-
} }, { children: name }))] })));
|
|
289
|
-
};
|
|
290
|
-
var ChartTooltip = function (_a) {
|
|
291
|
-
var active = _a.active, payload = _a.payload, label = _a.label, colors = _a.colors, valueFormatter = _a.valueFormatter, dateFormatter = _a.dateFormatter, theme = _a.theme;
|
|
197
|
+
const ChartTooltipFrame = ({ children, theme, }) => ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
198
|
+
borderStyle: 'solid',
|
|
199
|
+
borderColor: theme?.borderColor || '#E5E7EB',
|
|
200
|
+
overflow: 'hidden',
|
|
201
|
+
borderWidth: 1,
|
|
202
|
+
background: theme?.backgroundColor || '#ffffff',
|
|
203
|
+
borderRadius: '6px',
|
|
204
|
+
boxShadow: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',
|
|
205
|
+
}, children: children }));
|
|
206
|
+
exports.ChartTooltipFrame = ChartTooltipFrame;
|
|
207
|
+
const ChartTooltipRow = ({ value, name, color, theme, }) => ((0, jsx_runtime_1.jsxs)("div", { style: {
|
|
208
|
+
marginRight: '24px',
|
|
209
|
+
display: 'flex',
|
|
210
|
+
alignItems: 'center',
|
|
211
|
+
justifyContent: 'space-between',
|
|
212
|
+
width: '100%',
|
|
213
|
+
paddingTop: 2,
|
|
214
|
+
paddingBottom: 2,
|
|
215
|
+
}, children: [(0, jsx_runtime_1.jsxs)("div", {
|
|
216
|
+
// className="qq-flex qq-items-center qq-space-x-2"
|
|
217
|
+
style: {
|
|
218
|
+
// marginLeft: '0.5rem',
|
|
219
|
+
display: 'flex',
|
|
220
|
+
alignItems: 'center',
|
|
221
|
+
}, children: [(0, jsx_runtime_1.jsx)("span", { style: {
|
|
222
|
+
background: color,
|
|
223
|
+
borderWidth: 2,
|
|
224
|
+
borderColor: 'white',
|
|
225
|
+
borderStyle: 'solid',
|
|
226
|
+
borderColor: 'white',
|
|
227
|
+
boxShadow: '0 1px 2px 0 rgba(0, 0, 0, 0.05)',
|
|
228
|
+
height: '8px',
|
|
229
|
+
width: '8px',
|
|
230
|
+
borderRadius: 100,
|
|
231
|
+
marginRight: 4,
|
|
232
|
+
} }), (0, jsx_runtime_1.jsx)("p", {
|
|
233
|
+
// className={twMerge(
|
|
234
|
+
// 'font-medium tabular-nums text-right whitespace-nowrap',
|
|
235
|
+
// 'text-[#212121] !important'
|
|
236
|
+
// )}
|
|
237
|
+
style: {
|
|
238
|
+
marginTop: 0,
|
|
239
|
+
marginBottom: 0,
|
|
240
|
+
fontFamily: theme?.fontFamily,
|
|
241
|
+
color: theme?.primaryTextColor,
|
|
242
|
+
fontSize: theme?.fontSizeSmall || '14px',
|
|
243
|
+
fontWeight: theme?.fontWeightMedium || '500',
|
|
244
|
+
}, children: value })] }), (0, jsx_runtime_1.jsx)("p", { style: {
|
|
245
|
+
marginTop: 0,
|
|
246
|
+
marginBottom: 0,
|
|
247
|
+
fontFamily: theme?.fontFamily,
|
|
248
|
+
color: theme?.secondaryTextColor,
|
|
249
|
+
textAlign: 'right',
|
|
250
|
+
whiteSpace: 'nowrap',
|
|
251
|
+
overflow: 'hidden',
|
|
252
|
+
textOverflow: 'ellipsis',
|
|
253
|
+
fontSize: theme?.fontSizeSmall || '14px',
|
|
254
|
+
fontWeight: theme?.fontWeightNormal || '400',
|
|
255
|
+
}, children: name })] }));
|
|
256
|
+
exports.ChartTooltipRow = ChartTooltipRow;
|
|
257
|
+
const ChartTooltip = ({ active, payload, label, colors, valueFormatter, dateFormatter, theme, }) => {
|
|
292
258
|
if (active && payload) {
|
|
293
|
-
return (
|
|
259
|
+
return ((0, jsx_runtime_1.jsxs)(exports.ChartTooltipFrame, { theme: theme, children: [(0, jsx_runtime_1.jsx)("div", { style: {
|
|
294
260
|
borderStyle: 'solid',
|
|
295
|
-
borderBottomColor:
|
|
296
|
-
background:
|
|
261
|
+
borderBottomColor: theme?.borderColor || '#E5E7EB',
|
|
262
|
+
background: theme?.backgroundColor || 'white',
|
|
297
263
|
borderTop: 'none',
|
|
298
264
|
borderLeft: 'none',
|
|
299
265
|
borderRight: 'none',
|
|
@@ -304,21 +270,21 @@ var ChartTooltip = function (_a) {
|
|
|
304
270
|
paddingRight: '16px',
|
|
305
271
|
paddingTop: '8px',
|
|
306
272
|
paddingBottom: '8px',
|
|
307
|
-
}
|
|
273
|
+
}, children: (0, jsx_runtime_1.jsx)("p", { style: {
|
|
308
274
|
textAlign: 'left',
|
|
309
275
|
marginTop: 0,
|
|
310
276
|
marginBottom: 0,
|
|
311
|
-
fontFamily: theme
|
|
312
|
-
color: theme
|
|
313
|
-
fontSize:
|
|
314
|
-
fontWeight:
|
|
277
|
+
fontFamily: theme?.fontFamily,
|
|
278
|
+
color: theme?.primaryTextColor,
|
|
279
|
+
fontSize: theme?.fontSizeSmall || '14px',
|
|
280
|
+
fontWeight: theme?.boldFontWeight || '500',
|
|
315
281
|
paddingTop: 2,
|
|
316
282
|
paddingBottom: 2,
|
|
317
|
-
}
|
|
283
|
+
}, children: !isNaN(new Date(label)) && dateFormatter
|
|
318
284
|
? dateFormatter(label)
|
|
319
285
|
: !isNaN(new Date(label))
|
|
320
|
-
? format(new Date(label), 'MMM yyyy')
|
|
321
|
-
: label })
|
|
286
|
+
? (0, date_fns_1.format)(new Date(label), 'MMM yyyy')
|
|
287
|
+
: label }) }), (0, jsx_runtime_1.jsx)("div", {
|
|
322
288
|
// className="qq-px-4 qq-space-y-1 qq-py-2 qq-px-4"
|
|
323
289
|
style: {
|
|
324
290
|
paddingRight: '16px',
|
|
@@ -326,209 +292,193 @@ var ChartTooltip = function (_a) {
|
|
|
326
292
|
paddingTop: '8px',
|
|
327
293
|
paddingBottom: '8px',
|
|
328
294
|
// marginTop: '0.25rem',
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
// color={categoryColors.get(name) ?? BaseColors.Blue}
|
|
333
|
-
color: colors[idx], theme: theme }, "id-".concat(idx)));
|
|
334
|
-
}) }))] })));
|
|
295
|
+
}, children: payload.map(({ value, name }, idx) => ((0, jsx_runtime_1.jsx)(exports.ChartTooltipRow, { value: valueFormatter(value), name: labelFormatter(name),
|
|
296
|
+
// color={categoryColors.get(name) ?? BaseColors.Blue}
|
|
297
|
+
color: colors[idx], theme: theme }, `id-${idx}`))) })] }));
|
|
335
298
|
}
|
|
336
299
|
return null;
|
|
337
300
|
};
|
|
338
301
|
// @ts-ignore
|
|
339
302
|
function sumByKey(arr, key) {
|
|
340
303
|
// @ts-ignore
|
|
341
|
-
return arr.reduce(
|
|
342
|
-
|
|
304
|
+
return arr.reduce((acc, cur) => {
|
|
305
|
+
const val = parseInt(cur[key], 10);
|
|
343
306
|
return isNaN(val) ? acc : acc + val;
|
|
344
307
|
}, 0);
|
|
345
308
|
}
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
return (colors === null || colors === void 0 ? void 0 : colors.length) ? colors : ['#6269E9', '#E14F62'];
|
|
309
|
+
const Chart = ({ chartId, config, colors, containerStyle, dateFilter, query, }) => {
|
|
310
|
+
const { dispatch, dashboard } = (0, react_1.useContext)(Context_1.DashboardContext);
|
|
311
|
+
const { dashboardFilters } = (0, react_1.useContext)(Context_1.DashboardFiltersContext);
|
|
312
|
+
const [client, _] = (0, react_1.useContext)(Context_1.ClientContext);
|
|
313
|
+
const [theme] = (0, react_1.useContext)(Context_1.ThemeContext);
|
|
314
|
+
const chartColors = (0, react_1.useMemo)(() => {
|
|
315
|
+
return colors?.length ? colors : ['#6269E9', '#E14F62'];
|
|
354
316
|
}, [colors]);
|
|
355
|
-
return (
|
|
317
|
+
return ((0, jsx_runtime_1.jsx)(ChartUpdater, { config: config, dispatch: dispatch, dashboard: dashboard, chartId: chartId, containerStyle: containerStyle, colors: chartColors, client: client, theme: theme, isDateFilter: dateFilter, dashboardFilters: dashboardFilters, query: query }));
|
|
356
318
|
};
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
var colors = _a.colors, chartId = _a.chartId, config = _a.config, containerStyle = _a.containerStyle, dashboard = _a.dashboard, dispatch = _a.dispatch, client = _a.client, theme = _a.theme, isDateFilter = _a.isDateFilter, dashboardFilters = _a.dashboardFilters, query = _a.query;
|
|
360
|
-
var _g = useState(true), loading = _g[0], setLoading = _g[1];
|
|
319
|
+
const ChartUpdater = ({ colors, chartId, config, containerStyle, dashboard, dispatch, client, theme, isDateFilter, dashboardFilters, query, }) => {
|
|
320
|
+
const [loading, setLoading] = (0, react_1.useState)(true);
|
|
361
321
|
// console.log('chartConfig:', chartConfig);
|
|
362
322
|
// console.log('chartConfig.rows:', chartConfig.rows);
|
|
363
323
|
// console.log('chartConfig.xAxisField:', chartConfig.xAxisField);
|
|
364
|
-
|
|
324
|
+
(0, react_1.useEffect)(() => {
|
|
365
325
|
if (isDateFilter && !dateFilter) {
|
|
366
326
|
return;
|
|
367
327
|
}
|
|
368
|
-
|
|
369
|
-
function getChartOptions() {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
task: 'item',
|
|
402
|
-
filters: __assign(__assign({}, Object.entries(dashboardFilters)
|
|
403
|
-
.filter(function (_a) {
|
|
404
|
-
var key = _a[0];
|
|
405
|
-
return key !== 'date_range';
|
|
406
|
-
})
|
|
407
|
-
.map(function (_a) {
|
|
408
|
-
var value = _a[1];
|
|
409
|
-
return value;
|
|
410
|
-
})), { dateFilter: dateFilter }),
|
|
411
|
-
},
|
|
412
|
-
}, { headers: queryHeaders, withCredentials: withCredentials })];
|
|
413
|
-
case 2:
|
|
414
|
-
resp = _a.sent();
|
|
415
|
-
if (resp.data) {
|
|
416
|
-
setLoading(false);
|
|
417
|
-
dispatch({
|
|
418
|
-
type: 'UPDATE_DASHBOARD_ITEM',
|
|
419
|
-
id: chartId,
|
|
420
|
-
data: __assign({}, resp.data),
|
|
421
|
-
});
|
|
422
|
-
}
|
|
423
|
-
return [3 /*break*/, 5];
|
|
424
|
-
case 3: return [4 /*yield*/, axios.get('https://quill-344421.uc.r.appspot.com/item', {
|
|
425
|
-
params: {
|
|
426
|
-
id: chartId,
|
|
427
|
-
orgId: customerId,
|
|
428
|
-
publicKey: publicKey,
|
|
429
|
-
filters: Object.keys(dashboardFilters).map(function (key) { return dashboardFilters[key]; }),
|
|
430
|
-
// startDate:
|
|
431
|
-
// dateFilter &&
|
|
432
|
-
// dateFilter.startDate &&
|
|
433
|
-
// dateFilter.startDate.toISOString(),
|
|
434
|
-
// endDate:
|
|
435
|
-
// dateFilter &&
|
|
436
|
-
// dateFilter.endDate &&
|
|
437
|
-
// dateFilter.endDate.toISOString(),
|
|
328
|
+
let isSubscribed = true;
|
|
329
|
+
async function getChartOptions() {
|
|
330
|
+
if (isSubscribed) {
|
|
331
|
+
const { publicKey, customerId, environment, queryEndpoint, queryHeaders, } = client;
|
|
332
|
+
//queryEndpoint = undefined;
|
|
333
|
+
setLoading(true);
|
|
334
|
+
try {
|
|
335
|
+
// if self-hosting option, only get metadata and query
|
|
336
|
+
if (queryEndpoint) {
|
|
337
|
+
// const resp = await axios.get(
|
|
338
|
+
// 'https://quill-344421.uc.r.appspot.com/selfhostitem',
|
|
339
|
+
// {
|
|
340
|
+
// params: {
|
|
341
|
+
// id: chartId,
|
|
342
|
+
// orgId: customerId,
|
|
343
|
+
// publicKey: publicKey,
|
|
344
|
+
// },
|
|
345
|
+
// environment: environment || undefined,
|
|
346
|
+
// }
|
|
347
|
+
// );
|
|
348
|
+
if (dashboardFilters['date_range'] && dashboard[chartId]) {
|
|
349
|
+
const dateFilter = dashboardFilters['date_range'];
|
|
350
|
+
dateFilter.dateField = dashboard[chartId].dateField;
|
|
351
|
+
}
|
|
352
|
+
const resp = await axios_1.default.post(queryEndpoint, {
|
|
353
|
+
metadata: {
|
|
354
|
+
id: chartId,
|
|
355
|
+
task: 'item',
|
|
356
|
+
filters: {
|
|
357
|
+
...Object.entries(dashboardFilters)
|
|
358
|
+
.filter(([key]) => key !== 'date_range')
|
|
359
|
+
.map(([, value]) => value),
|
|
360
|
+
dateFilter,
|
|
438
361
|
},
|
|
439
|
-
|
|
440
|
-
|
|
362
|
+
},
|
|
363
|
+
}, { headers: queryHeaders });
|
|
364
|
+
if (resp.data) {
|
|
365
|
+
setLoading(false);
|
|
366
|
+
dispatch({
|
|
367
|
+
type: 'UPDATE_DASHBOARD_ITEM',
|
|
368
|
+
id: chartId,
|
|
369
|
+
data: {
|
|
370
|
+
...resp.data,
|
|
441
371
|
},
|
|
442
|
-
})
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
const resp = await axios_1.default.get('https://quill-344421.uc.r.appspot.com/item', {
|
|
377
|
+
params: {
|
|
378
|
+
id: chartId,
|
|
379
|
+
orgId: customerId,
|
|
380
|
+
publicKey: publicKey,
|
|
381
|
+
filters: Object.keys(dashboardFilters).map(key => dashboardFilters[key]),
|
|
382
|
+
// startDate:
|
|
383
|
+
// dateFilter &&
|
|
384
|
+
// dateFilter.startDate &&
|
|
385
|
+
// dateFilter.startDate.toISOString(),
|
|
386
|
+
// endDate:
|
|
387
|
+
// dateFilter &&
|
|
388
|
+
// dateFilter.endDate &&
|
|
389
|
+
// dateFilter.endDate.toISOString(),
|
|
390
|
+
},
|
|
391
|
+
headers: {
|
|
392
|
+
environment: environment || undefined,
|
|
393
|
+
},
|
|
394
|
+
});
|
|
395
|
+
// console.log('RESP: ', resp.data);
|
|
396
|
+
if (resp.data) {
|
|
459
397
|
setLoading(false);
|
|
460
|
-
|
|
461
|
-
|
|
398
|
+
dispatch({
|
|
399
|
+
type: 'UPDATE_DASHBOARD_ITEM',
|
|
400
|
+
id: chartId,
|
|
401
|
+
data: { ...resp.data },
|
|
402
|
+
});
|
|
403
|
+
}
|
|
462
404
|
}
|
|
463
|
-
}
|
|
464
|
-
|
|
405
|
+
}
|
|
406
|
+
catch (e) {
|
|
407
|
+
console.log('Error fetching chart: ', e);
|
|
408
|
+
setLoading(false);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
465
411
|
}
|
|
466
412
|
if (config) {
|
|
467
413
|
setLoading(false);
|
|
468
414
|
return;
|
|
469
415
|
}
|
|
470
416
|
getChartOptions(); //when wouldn't you run this????? saw if statements before that implied you might not run this sometimes
|
|
471
|
-
return
|
|
417
|
+
return () => {
|
|
472
418
|
isSubscribed = false;
|
|
473
419
|
};
|
|
474
420
|
}, [dashboardFilters]);
|
|
475
421
|
// console.log('DASHBOARD FILTERS: ', dashboardFilters);
|
|
476
|
-
|
|
422
|
+
(0, react_1.useEffect)(() => {
|
|
477
423
|
if (config) {
|
|
478
424
|
dispatch({
|
|
479
425
|
type: 'UPDATE_DASHBOARD_ITEM',
|
|
480
426
|
id: chartId,
|
|
481
|
-
data:
|
|
427
|
+
data: { ...config },
|
|
482
428
|
});
|
|
483
429
|
}
|
|
484
430
|
}, [config]);
|
|
485
|
-
|
|
431
|
+
const dateFilter = Object.values(dashboardFilters).find(filter => filter && filter.filterType === 'DATE_RANGE');
|
|
486
432
|
if (!dashboard[chartId] || loading) {
|
|
487
|
-
return (
|
|
433
|
+
return ((0, jsx_runtime_1.jsx)("div", {
|
|
488
434
|
// className="flex flex-col flex-1 h-[100%]"
|
|
489
|
-
style:
|
|
490
|
-
|
|
435
|
+
style: {
|
|
436
|
+
...containerStyle,
|
|
437
|
+
marginLeft: 25,
|
|
438
|
+
marginRight: 25,
|
|
439
|
+
boxSizing: 'content-box',
|
|
440
|
+
height: '100%',
|
|
441
|
+
display: 'flex',
|
|
442
|
+
flexDirection: 'column',
|
|
443
|
+
flex: 1,
|
|
444
|
+
}, children: (0, jsx_runtime_1.jsx)("div", { style: {
|
|
445
|
+
height: containerStyle?.height || 300,
|
|
491
446
|
width: '100%',
|
|
492
447
|
boxSizing: 'content-box',
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
? (containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.height) + (containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.marginTop)
|
|
497
|
-
: (containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.height)
|
|
498
|
-
? containerStyle === null || containerStyle === void 0 ? void 0 : containerStyle.height
|
|
499
|
-
: 300, borderRadius: 8,
|
|
500
|
-
// highlightColor="#F7F7F8"
|
|
501
|
-
highlightColor: "#FDFDFD",
|
|
502
|
-
// baseColor="#F3F4F6"
|
|
503
|
-
baseColor: "#F9F9FA", width: "100%" }) })) })));
|
|
448
|
+
borderRadius: 8,
|
|
449
|
+
overflow: 'hidden',
|
|
450
|
+
}, children: (0, jsx_runtime_1.jsxs)("svg", { width: "100%", height: "100%", xmlns: "http://www.w3.org/2000/svg", "xmlns:xlink": "http://www.w3.org/1999/xlink", children: [(0, jsx_runtime_1.jsx)("rect", { width: "100%", height: "100%", fill: "#F9F9FA" }), (0, jsx_runtime_1.jsx)("defs", { fill: "#F9F9FA", children: (0, jsx_runtime_1.jsxs)("linearGradient", { id: "skeletonGradient", x1: "0%", y1: "0%", x2: "10%", y2: "0%", gradientUnits: "userSpaceOnUse", children: [(0, jsx_runtime_1.jsx)("stop", { offset: "0%", "stop-color": "rgba(255,255,255,0)" }), (0, jsx_runtime_1.jsx)("stop", { offset: "50%", "stop-color": "#FEFEFE" }), (0, jsx_runtime_1.jsx)("stop", { offset: "100%", "stop-color": "rgba(255,255,255,0)" }), (0, jsx_runtime_1.jsx)("animate", { attributeName: "x1", from: "-100%", to: "100%", dur: "2s", repeatCount: "indefinite" }), (0, jsx_runtime_1.jsx)("animate", { attributeName: "x2", from: "-50%", to: "150%", dur: "2s", repeatCount: "indefinite" })] }) }), (0, jsx_runtime_1.jsx)("rect", { width: "50%", height: "100%", fill: "url(#skeletonGradient)", children: (0, jsx_runtime_1.jsx)("animate", { attributeName: "x", from: "-100%", to: "100%", dur: "2s", repeatCount: "indefinite" }) })] }) }) }));
|
|
504
451
|
}
|
|
505
|
-
if (
|
|
506
|
-
|
|
507
|
-
return (
|
|
452
|
+
if (dashboard[chartId]?.chartType === 'pie') {
|
|
453
|
+
const { xAxisField, yAxisFields } = dashboard[chartId];
|
|
454
|
+
return ((0, jsx_runtime_1.jsx)(PieChart_1.default
|
|
508
455
|
// @ts-ignore
|
|
509
456
|
, {
|
|
510
457
|
// @ts-ignore
|
|
511
|
-
containerStyle: containerStyle, data: dashboard[chartId].rows.map(
|
|
512
|
-
return
|
|
513
|
-
|
|
514
|
-
|
|
458
|
+
containerStyle: containerStyle, data: dashboard[chartId].rows.map(row => {
|
|
459
|
+
return {
|
|
460
|
+
...row,
|
|
461
|
+
count: parseInt(row[yAxisFields[0].field]) /
|
|
462
|
+
sumByKey(dashboard[chartId].rows, yAxisFields[0].field),
|
|
463
|
+
};
|
|
464
|
+
}), category: yAxisFields[0].field, index: xAxisField, colors: colors, theme: theme }));
|
|
515
465
|
}
|
|
516
|
-
if (
|
|
517
|
-
return (
|
|
466
|
+
if (dashboard[chartId]?.chartType === 'table') {
|
|
467
|
+
return ((0, jsx_runtime_1.jsx)(TableChart_1.default, { data: dashboard[chartId].rows, yAxisFields: dashboard[chartId].yAxisFields, theme: theme, containerStyle: containerStyle }));
|
|
518
468
|
}
|
|
519
|
-
if (
|
|
520
|
-
return (
|
|
469
|
+
if (dashboard[chartId]?.chartType === 'bar') {
|
|
470
|
+
return ((0, jsx_runtime_1.jsx)(BarList_1.default, { data: dashboard[chartId].rows, theme: theme, yAxisFields: dashboard[chartId].yAxisFields, xAxisFormat: dashboard[chartId].xAxisFormat, colors: colors, xAxisField: dashboard[chartId].xAxisField, containerStyle: containerStyle }));
|
|
521
471
|
}
|
|
522
|
-
if (
|
|
523
|
-
return (
|
|
472
|
+
if (dashboard[chartId]?.chartType === 'column') {
|
|
473
|
+
return ((0, jsx_runtime_1.jsx)(BarChart, { colors: colors, theme: theme, yAxisFields: dashboard[chartId].yAxisFields,
|
|
524
474
|
// @ts-ignore
|
|
525
475
|
data: dashboard[chartId].rows, xAxisField: dashboard[chartId].xAxisField, xAxisLabel: dashboard[chartId].xAxisLabel, xAxisFormat: dashboard[chartId].xAxisFormat, containerStyle: containerStyle }));
|
|
526
476
|
}
|
|
527
|
-
if (
|
|
528
|
-
return (
|
|
529
|
-
fontFamily: theme
|
|
477
|
+
if (dashboard[chartId]?.chartType === 'metric') {
|
|
478
|
+
return ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
479
|
+
fontFamily: theme?.fontFamily,
|
|
530
480
|
fontSize: 32,
|
|
531
|
-
color: theme
|
|
481
|
+
color: theme?.primaryTextColor,
|
|
532
482
|
fontWeight: '600',
|
|
533
483
|
textOverflow: 'ellipsis',
|
|
534
484
|
margin: 0,
|
|
@@ -542,12 +492,12 @@ var ChartUpdater = function (_a) {
|
|
|
542
492
|
maxWidth: '100%',
|
|
543
493
|
textAlign: 'left',
|
|
544
494
|
overflow: 'hidden',
|
|
545
|
-
height:
|
|
495
|
+
height: containerStyle?.height || '100%',
|
|
546
496
|
display: 'flex',
|
|
547
497
|
flexDirection: 'column',
|
|
548
498
|
// background: 'red',
|
|
549
|
-
}
|
|
550
|
-
valueFormatter({
|
|
499
|
+
}, children: dashboard[chartId].rows.length > 0 &&
|
|
500
|
+
(0, exports.valueFormatter)({
|
|
551
501
|
value: dashboard[chartId].rows[0][dashboard[chartId].xAxisField],
|
|
552
502
|
field: dashboard[chartId].xAxisField,
|
|
553
503
|
fields: [
|
|
@@ -556,9 +506,9 @@ var ChartUpdater = function (_a) {
|
|
|
556
506
|
format: dashboard[chartId].xAxisFormat,
|
|
557
507
|
},
|
|
558
508
|
],
|
|
559
|
-
}) }))
|
|
509
|
+
}) }));
|
|
560
510
|
}
|
|
561
|
-
return (
|
|
511
|
+
return ((0, jsx_runtime_1.jsx)(LineChart, { colors: colors, yAxisFields: dashboard[chartId].yAxisFields,
|
|
562
512
|
// @ts-ignore
|
|
563
513
|
data: dashboard[chartId].rows, xAxisField: dashboard[chartId].xAxisField, xAxisLabel: dashboard[chartId].xAxisLabel, xAxisFormat: dashboard[chartId].xAxisFormat, containerStyle: containerStyle, theme: theme }));
|
|
564
514
|
};
|
|
@@ -594,13 +544,13 @@ function formatNumber(num, label) {
|
|
|
594
544
|
// return [adjustedMin, adjustedMax];
|
|
595
545
|
// }
|
|
596
546
|
function getDomain(data, fields) {
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
data.forEach(
|
|
600
|
-
fieldsArray.forEach(
|
|
601
|
-
|
|
547
|
+
const fieldsArray = fields.map(elem => elem.field);
|
|
548
|
+
const numericValues = [];
|
|
549
|
+
data.forEach(item => {
|
|
550
|
+
fieldsArray.forEach(field => {
|
|
551
|
+
let value = item[field];
|
|
602
552
|
// Try to cast the value to a number
|
|
603
|
-
|
|
553
|
+
const numericValue = parseFloat(value);
|
|
604
554
|
if (!isNaN(numericValue)) {
|
|
605
555
|
value = numericValue;
|
|
606
556
|
}
|
|
@@ -609,29 +559,36 @@ function getDomain(data, fields) {
|
|
|
609
559
|
}
|
|
610
560
|
});
|
|
611
561
|
});
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
var adjustedMin = Math.min(minValue, 0);
|
|
617
|
-
var padding = Math.round(0.2 * (maxValue - minValue));
|
|
618
|
-
var adjustedMax = maxValue + padding;
|
|
562
|
+
const [minValue, maxValue] = numericValues.reduce(([min, max], value) => [Math.min(min, value), Math.max(max, value)], [Infinity, -Infinity]);
|
|
563
|
+
const adjustedMin = Math.min(minValue, 0);
|
|
564
|
+
const padding = Math.round(0.2 * (maxValue - minValue));
|
|
565
|
+
const adjustedMax = maxValue + padding;
|
|
619
566
|
return [adjustedMin, adjustedMax];
|
|
620
567
|
}
|
|
621
|
-
|
|
622
|
-
var x = _a.x, y = _a.y, payload = _a.payload, theme = _a.theme;
|
|
568
|
+
const CustomizedTick = ({ x, y, payload, theme, }) => {
|
|
623
569
|
// const { x, y, payload } = props;
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
return (
|
|
570
|
+
const maxLength = 10;
|
|
571
|
+
const value = payload.value;
|
|
572
|
+
const truncatedValue = value.length > maxLength ? value.substring(0, maxLength) + '...' : value;
|
|
573
|
+
return ((0, jsx_runtime_1.jsx)("text", { xlinkTitle: value, fill: theme?.chartLabelColor, fontSize: 12, x: x, y: y + 15, width: 30, textAnchor: "middle", children: truncatedValue }));
|
|
628
574
|
};
|
|
629
|
-
function BarChart(
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
575
|
+
function BarChart({ colors, yAxisFields, data, containerStyle, xAxisField, xAxisLabel, xAxisFormat, theme, }) {
|
|
576
|
+
const newColors = (0, PieChart_1.findComplementaryAndAnalogousColors)(colors[0], colors[1]);
|
|
577
|
+
return ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
578
|
+
...containerStyle,
|
|
579
|
+
boxSizing: 'content-box',
|
|
580
|
+
// display: 'flex',
|
|
581
|
+
// flexDirection: 'column',
|
|
582
|
+
// flex: 1,
|
|
583
|
+
// height: '100%',
|
|
584
|
+
// minHeight: 400,
|
|
585
|
+
// minWidth: 400,
|
|
586
|
+
// height: 400,
|
|
587
|
+
// width: 800,
|
|
588
|
+
// width: '100%',
|
|
589
|
+
}, children: (0, jsx_runtime_1.jsx)(recharts_1.ResponsiveContainer, { width: "100%", height: '100%', children: (0, jsx_runtime_1.jsxs)(recharts_1.BarChart, { data: data,
|
|
633
590
|
// stackOffset={'none'}
|
|
634
|
-
layout: 'horizontal'
|
|
591
|
+
layout: 'horizontal', children: [(0, jsx_runtime_1.jsx)(recharts_1.CartesianGrid, { strokeDasharray: "3 3", horizontal: true, vertical: false }), (0, jsx_runtime_1.jsx)(recharts_1.YAxis
|
|
635
592
|
// width={56}
|
|
636
593
|
// width={30}
|
|
637
594
|
// textAnchor="start"
|
|
@@ -644,13 +601,11 @@ function BarChart(_a) {
|
|
|
644
601
|
tick: { transform: 'translate(-3, 0)' }, style: {
|
|
645
602
|
fontSize: '12px',
|
|
646
603
|
fontFamily: theme.chartLabelFontFamily,
|
|
647
|
-
}, tickFormatter:
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
});
|
|
653
|
-
} }), _jsx(XAxis, { hide: false, dataKey: xAxisField,
|
|
604
|
+
}, tickFormatter: tick => (0, exports.valueFormatter)({
|
|
605
|
+
value: tick,
|
|
606
|
+
field: yAxisFields[0].field || 'what',
|
|
607
|
+
fields: yAxisFields,
|
|
608
|
+
}) }), (0, jsx_runtime_1.jsx)(recharts_1.XAxis, { hide: false, dataKey: xAxisField,
|
|
654
609
|
// interval="preserveStartEnd"
|
|
655
610
|
tick: { transform: 'translate(0, 6)' },
|
|
656
611
|
//padding between labels and axis
|
|
@@ -659,40 +614,32 @@ function BarChart(_a) {
|
|
|
659
614
|
// TODO: generalize
|
|
660
615
|
fontFamily: theme.chartLabelFontFamily,
|
|
661
616
|
marginTop: '20px',
|
|
662
|
-
}, tickLine: false, axisLine: false, tickFormatter:
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
return valueFormatter({
|
|
678
|
-
value: value,
|
|
679
|
-
field: payload[0].dataKey,
|
|
680
|
-
fields: yAxisFields,
|
|
681
|
-
});
|
|
682
|
-
}, colors: newColors }));
|
|
683
|
-
}, position: { y: 0 } }), yAxisFields.map(function (elem, index) { return (_jsx(Bar, { name: elem.label, dataKey: elem.field, type: "linear",
|
|
617
|
+
}, tickLine: false, axisLine: false, tickFormatter: tick => (0, exports.valueFormatter)({
|
|
618
|
+
value: tick,
|
|
619
|
+
field: xAxisField,
|
|
620
|
+
fields: [{ field: xAxisField, format: xAxisFormat }],
|
|
621
|
+
}) }), (0, jsx_runtime_1.jsx)(recharts_1.Tooltip, { wrapperStyle: { outline: 'none' }, isAnimationActive: false, cursor: { fill: '#d1d5db', opacity: '0.15' }, content: ({ active, payload, label }) => {
|
|
622
|
+
return ((0, jsx_runtime_1.jsx)(ChartTooltip, { theme: theme, active: active, payload: payload, label: label, dateFormatter: value => (0, exports.valueFormatter)({
|
|
623
|
+
value,
|
|
624
|
+
field: xAxisField,
|
|
625
|
+
fields: [{ field: xAxisField, format: xAxisFormat }],
|
|
626
|
+
}), valueFormatter: value => (0, exports.valueFormatter)({
|
|
627
|
+
value,
|
|
628
|
+
field: payload[0].dataKey,
|
|
629
|
+
fields: yAxisFields,
|
|
630
|
+
}), colors: newColors }));
|
|
631
|
+
}, position: { y: 0 } }), yAxisFields.map((elem, index) => ((0, jsx_runtime_1.jsx)(recharts_1.Bar, { name: elem.label, dataKey: elem.field, type: "linear",
|
|
684
632
|
// stackId={stack || relative ? "a" : undefined}
|
|
685
633
|
fill: newColors[index],
|
|
686
634
|
// barSize={20}
|
|
687
|
-
isAnimationActive: true }, elem.field))
|
|
635
|
+
isAnimationActive: true }, elem.field)))] }) }) }));
|
|
688
636
|
}
|
|
689
|
-
function LineChart(
|
|
690
|
-
var colors = _a.colors, yAxisFields = _a.yAxisFields, data = _a.data, containerStyle = _a.containerStyle, xAxisField = _a.xAxisField, xAxisLabel = _a.xAxisLabel, xAxisFormat = _a.xAxisFormat, theme = _a.theme;
|
|
637
|
+
function LineChart({ colors, yAxisFields, data, containerStyle, xAxisField, xAxisLabel, xAxisFormat, theme, }) {
|
|
691
638
|
// console.log('CONTAINER: ', containerStyle);
|
|
692
639
|
if (!yAxisFields || !yAxisFields.length) {
|
|
693
640
|
return null;
|
|
694
641
|
}
|
|
695
|
-
return (
|
|
642
|
+
return ((0, jsx_runtime_1.jsx)("div", { style: { ...containerStyle, boxSizing: 'content-box' }, children: (0, jsx_runtime_1.jsx)(recharts_1.ResponsiveContainer, { width: "100%", height: '100%', children: (0, jsx_runtime_1.jsxs)(recharts_1.ComposedChart, { data: data, children: [(0, jsx_runtime_1.jsx)(recharts_1.CartesianGrid, { strokeDasharray: "3 3", horizontal: true, vertical: false }), (0, jsx_runtime_1.jsx)(recharts_1.XAxis
|
|
696
643
|
// hide={!showXAxis}
|
|
697
644
|
, {
|
|
698
645
|
// hide={!showXAxis}
|
|
@@ -704,21 +651,19 @@ function LineChart(_a) {
|
|
|
704
651
|
// }
|
|
705
652
|
style: {
|
|
706
653
|
fontSize: '12px',
|
|
707
|
-
fontFamily:
|
|
708
|
-
|
|
654
|
+
fontFamily: theme?.chartLabelFontFamily ||
|
|
655
|
+
theme?.fontFamily ||
|
|
709
656
|
'Inter; Helvetica',
|
|
710
|
-
color:
|
|
657
|
+
color: theme?.chartLabelColor || '#666666',
|
|
711
658
|
},
|
|
712
659
|
// interval="preserveStartEnd"
|
|
713
660
|
interval: "preserveStartEnd",
|
|
714
661
|
// interval={0}
|
|
715
|
-
tickLine: false, axisLine: false, padding: { left: 10, right: 10 }, minTickGap: 5, tickFormatter:
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
});
|
|
721
|
-
} }), _jsx(YAxis
|
|
662
|
+
tickLine: false, axisLine: false, padding: { left: 10, right: 10 }, minTickGap: 5, tickFormatter: tick => (0, exports.valueFormatter)({
|
|
663
|
+
value: tick,
|
|
664
|
+
field: xAxisField,
|
|
665
|
+
fields: [{ field: xAxisField, format: xAxisFormat }],
|
|
666
|
+
}) }), (0, jsx_runtime_1.jsx)(recharts_1.YAxis
|
|
722
667
|
// textAnchor="left"
|
|
723
668
|
// tickMargin={0}
|
|
724
669
|
// width={56}
|
|
@@ -734,39 +679,34 @@ function LineChart(_a) {
|
|
|
734
679
|
// domain={yAxisDomain as AxisDomain}
|
|
735
680
|
domain: getDomain(data, yAxisFields), tick: { transform: 'translate(-3, 0)' }, style: {
|
|
736
681
|
fontSize: '12px',
|
|
737
|
-
fontFamily:
|
|
738
|
-
|
|
682
|
+
fontFamily: theme?.chartLabelFontFamily ||
|
|
683
|
+
theme?.fontFamily ||
|
|
739
684
|
'Inter; Helvetica',
|
|
740
|
-
color:
|
|
741
|
-
}, tickFormatter:
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
{ field: xAxisField, format: xAxisFormat },
|
|
763
|
-
], false),
|
|
764
|
-
});
|
|
765
|
-
}, colors: colors, theme: theme }));
|
|
766
|
-
}, position: { y: 0 } }), yAxisFields.map(function (elem, index) { return (_jsx("defs", { children: _jsxs("linearGradient", __assign({ id: "gradient".concat(index), x1: "0", y1: "0", x2: "0", y2: "1" }, { children: [_jsx("stop", { offset: "5%", stopColor: colors[index], stopOpacity: 0.4 }), _jsx("stop", { offset: "95%", stopColor: 'rgba(0,0,0,0)', stopOpacity: 0 })] })) }, "defs".concat(elem.field + index))); }), yAxisFields.map(function (elem, index) { return (_jsx(Area, { name: elem.label, type: "linear", dataKey: elem.field, stroke: colors[index],
|
|
685
|
+
color: theme?.chartLabelColor || '#666666',
|
|
686
|
+
}, tickFormatter: value => (0, exports.valueFormatter)({
|
|
687
|
+
value,
|
|
688
|
+
field: yAxisFields[0].field,
|
|
689
|
+
fields: [
|
|
690
|
+
...yAxisFields,
|
|
691
|
+
{ field: xAxisField, format: xAxisFormat },
|
|
692
|
+
],
|
|
693
|
+
}) }), (0, jsx_runtime_1.jsx)(recharts_1.Tooltip, { wrapperStyle: { outline: 'none' }, isAnimationActive: false, cursor: { stroke: '#d1d5db', strokeWidth: 1 }, content: ({ active, payload, label }) => {
|
|
694
|
+
return ((0, jsx_runtime_1.jsx)(ChartTooltip, { active: active, payload: payload, label: label, dateFormatter: value => (0, exports.valueFormatter)({
|
|
695
|
+
value,
|
|
696
|
+
field: xAxisField,
|
|
697
|
+
fields: [{ field: xAxisField, format: xAxisFormat }],
|
|
698
|
+
}), valueFormatter: value => (0, exports.valueFormatter)({
|
|
699
|
+
value,
|
|
700
|
+
field: payload[0].dataKey,
|
|
701
|
+
fields: [
|
|
702
|
+
...yAxisFields,
|
|
703
|
+
{ field: xAxisField, format: xAxisFormat },
|
|
704
|
+
],
|
|
705
|
+
}), colors: colors, theme: theme }));
|
|
706
|
+
}, position: { y: 0 } }), yAxisFields.map((elem, index) => ((0, jsx_runtime_1.jsx)("defs", { children: (0, jsx_runtime_1.jsxs)("linearGradient", { id: `gradient${index}`, x1: "0", y1: "0", x2: "0", y2: "1", children: [(0, jsx_runtime_1.jsx)("stop", { offset: "5%", stopColor: colors[index], stopOpacity: 0.4 }), (0, jsx_runtime_1.jsx)("stop", { offset: "95%", stopColor: 'rgba(0,0,0,0)', stopOpacity: 0 })] }) }, `defs${elem.field + index}`))), yAxisFields.map((elem, index) => ((0, jsx_runtime_1.jsx)(recharts_1.Area, { name: elem.label, type: "linear", dataKey: elem.field, stroke: colors[index],
|
|
767
707
|
// if hide area
|
|
768
708
|
// fill="transparent"
|
|
769
|
-
fill:
|
|
709
|
+
fill: `url(#gradient${index})`, strokeWidth: 2, dot: false, isAnimationActive: true }, elem.field)))] }) }) }));
|
|
770
710
|
}
|
|
771
|
-
|
|
711
|
+
exports.default = Chart;
|
|
772
712
|
//# sourceMappingURL=Chart.js.map
|