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