dbgate-datalib 6.5.1 → 6.5.3
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/CollectionGridDisplay.d.ts +1 -1
- package/lib/CollectionGridDisplay.js +2 -2
- package/lib/JslGridDisplay.d.ts +1 -1
- package/lib/JslGridDisplay.js +2 -2
- package/lib/ViewGridDisplay.d.ts +1 -1
- package/lib/ViewGridDisplay.js +2 -2
- package/lib/chartDefinitions.d.ts +3 -0
- package/lib/chartDefinitions.js +2 -1
- package/lib/chartProcessor.d.ts +1 -0
- package/lib/chartProcessor.js +23 -2
- package/lib/chartTools.js +6 -0
- package/lib/tests/chartProcessor.test.js +25 -0
- package/package.json +5 -5
|
@@ -4,5 +4,5 @@ import { GridConfig, GridCache } from './GridConfig';
|
|
|
4
4
|
export declare function analyseCollectionDisplayColumns(rows: any, display: any): any[];
|
|
5
5
|
export declare class CollectionGridDisplay extends GridDisplay {
|
|
6
6
|
collection: CollectionInfo;
|
|
7
|
-
constructor(collection: CollectionInfo, driver: EngineDriver, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, loadedRows: any, changeSet: any, readOnly?: boolean);
|
|
7
|
+
constructor(collection: CollectionInfo, driver: EngineDriver, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, loadedRows: any, changeSet: any, readOnly?: boolean, currentSettings?: any);
|
|
8
8
|
}
|
|
@@ -93,9 +93,9 @@ function analyseCollectionDisplayColumns(rows, display) {
|
|
|
93
93
|
}
|
|
94
94
|
exports.analyseCollectionDisplayColumns = analyseCollectionDisplayColumns;
|
|
95
95
|
class CollectionGridDisplay extends GridDisplay_1.GridDisplay {
|
|
96
|
-
constructor(collection, driver, config, setConfig, cache, setCache, loadedRows, changeSet, readOnly = false) {
|
|
96
|
+
constructor(collection, driver, config, setConfig, cache, setCache, loadedRows, changeSet, readOnly = false, currentSettings = null) {
|
|
97
97
|
var _a, _b;
|
|
98
|
-
super(config, setConfig, cache, setCache, driver);
|
|
98
|
+
super(config, setConfig, cache, setCache, driver, undefined, undefined, currentSettings);
|
|
99
99
|
this.collection = collection;
|
|
100
100
|
const changedDocs = lodash_1.default.compact(changeSet.updates.map(chs => chs.document));
|
|
101
101
|
const insertedDocs = lodash_1.default.compact(changeSet.inserts.map(chs => chs.fields));
|
package/lib/JslGridDisplay.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import { GridDisplay, ChangeCacheFunc, ChangeConfigFunc } from './GridDisplay';
|
|
|
2
2
|
import { GridConfig, GridCache } from './GridConfig';
|
|
3
3
|
import { EngineDriver } from 'dbgate-types';
|
|
4
4
|
export declare class JslGridDisplay extends GridDisplay {
|
|
5
|
-
constructor(jslid: any, structure: any, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, rows: any, isDynamicStructure: boolean, supportsReload: boolean, editable?: boolean, driver?: EngineDriver);
|
|
5
|
+
constructor(jslid: any, structure: any, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, rows: any, isDynamicStructure: boolean, supportsReload: boolean, editable?: boolean, driver?: EngineDriver, currentSettings?: any);
|
|
6
6
|
}
|
package/lib/JslGridDisplay.js
CHANGED
|
@@ -9,9 +9,9 @@ const GridDisplay_1 = require("./GridDisplay");
|
|
|
9
9
|
const CollectionGridDisplay_1 = require("./CollectionGridDisplay");
|
|
10
10
|
const dbgate_tools_1 = require("dbgate-tools");
|
|
11
11
|
class JslGridDisplay extends GridDisplay_1.GridDisplay {
|
|
12
|
-
constructor(jslid, structure, config, setConfig, cache, setCache, rows, isDynamicStructure, supportsReload, editable = false, driver = null) {
|
|
12
|
+
constructor(jslid, structure, config, setConfig, cache, setCache, rows, isDynamicStructure, supportsReload, editable = false, driver = null, currentSettings = null) {
|
|
13
13
|
var _a;
|
|
14
|
-
super(config, setConfig, cache, setCache, driver);
|
|
14
|
+
super(config, setConfig, cache, setCache, driver, undefined, undefined, currentSettings);
|
|
15
15
|
this.filterable = true;
|
|
16
16
|
this.sortable = true;
|
|
17
17
|
this.supportsReload = supportsReload;
|
package/lib/ViewGridDisplay.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { EngineDriver, ViewInfo, ColumnInfo, DatabaseInfo } from 'dbgate-ty
|
|
|
3
3
|
import { GridConfig, GridCache } from './GridConfig';
|
|
4
4
|
export declare class ViewGridDisplay extends GridDisplay {
|
|
5
5
|
view: ViewInfo;
|
|
6
|
-
constructor(view: ViewInfo, driver: EngineDriver, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, dbinfo: DatabaseInfo, serverVersion: any);
|
|
6
|
+
constructor(view: ViewInfo, driver: EngineDriver, config: GridConfig, setConfig: ChangeConfigFunc, cache: GridCache, setCache: ChangeCacheFunc, dbinfo: DatabaseInfo, serverVersion: any, currentSettings: any);
|
|
7
7
|
getDisplayColumns(view: ViewInfo): {
|
|
8
8
|
isChecked: boolean;
|
|
9
9
|
pureName: string;
|
package/lib/ViewGridDisplay.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ViewGridDisplay = void 0;
|
|
4
4
|
const GridDisplay_1 = require("./GridDisplay");
|
|
5
5
|
class ViewGridDisplay extends GridDisplay_1.GridDisplay {
|
|
6
|
-
constructor(view, driver, config, setConfig, cache, setCache, dbinfo, serverVersion) {
|
|
7
|
-
super(config, setConfig, cache, setCache, driver, dbinfo, serverVersion);
|
|
6
|
+
constructor(view, driver, config, setConfig, cache, setCache, dbinfo, serverVersion, currentSettings) {
|
|
7
|
+
super(config, setConfig, cache, setCache, driver, dbinfo, serverVersion, currentSettings);
|
|
8
8
|
this.view = view;
|
|
9
9
|
this.columns = this.getDisplayColumns(view);
|
|
10
10
|
this.formColumns = this.columns;
|
|
@@ -16,6 +16,7 @@ export declare const ChartLimits: {
|
|
|
16
16
|
VALID_VALUE_RATIO_LIMIT: number;
|
|
17
17
|
PIE_RATIO_LIMIT: number;
|
|
18
18
|
PIE_COUNT_LIMIT: number;
|
|
19
|
+
CHART_FILL_LIMIT: number;
|
|
19
20
|
};
|
|
20
21
|
export interface ChartXFieldDefinition {
|
|
21
22
|
field: string;
|
|
@@ -36,6 +37,7 @@ export interface ChartDefinition {
|
|
|
36
37
|
title?: string;
|
|
37
38
|
pieRatioLimit?: number;
|
|
38
39
|
pieCountLimit?: number;
|
|
40
|
+
trimXCountLimit?: number;
|
|
39
41
|
xdef: ChartXFieldDefinition;
|
|
40
42
|
ydefs: ChartYFieldDefinition[];
|
|
41
43
|
useDataLabels?: boolean;
|
|
@@ -76,5 +78,6 @@ export interface ProcessedChart {
|
|
|
76
78
|
[key: string]: Set<any>;
|
|
77
79
|
};
|
|
78
80
|
availableColumns: ChartAvailableColumn[];
|
|
81
|
+
errorMessage?: string;
|
|
79
82
|
definition: ChartDefinition;
|
|
80
83
|
}
|
package/lib/chartDefinitions.js
CHANGED
|
@@ -14,5 +14,6 @@ exports.ChartLimits = {
|
|
|
14
14
|
MAX_DISTINCT_VALUES: 10,
|
|
15
15
|
VALID_VALUE_RATIO_LIMIT: 0.5,
|
|
16
16
|
PIE_RATIO_LIMIT: 0.05,
|
|
17
|
-
PIE_COUNT_LIMIT: 10,
|
|
17
|
+
PIE_COUNT_LIMIT: 10,
|
|
18
|
+
CHART_FILL_LIMIT: 10000, // limit for filled charts (time intervals), to avoid too many points
|
|
18
19
|
};
|
package/lib/chartProcessor.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export declare class ChartProcessor {
|
|
|
9
9
|
availableColumns: ChartAvailableColumn[];
|
|
10
10
|
autoDetectCharts: boolean;
|
|
11
11
|
rowsAdded: number;
|
|
12
|
+
errorMessage?: string;
|
|
12
13
|
constructor(givenDefinitions?: ChartDefinition[]);
|
|
13
14
|
addRow(row: any): void;
|
|
14
15
|
applyLimitsOnCharts(): void;
|
package/lib/chartProcessor.js
CHANGED
|
@@ -140,9 +140,18 @@ class ChartProcessor {
|
|
|
140
140
|
}
|
|
141
141
|
// apply on all charts with this date column
|
|
142
142
|
for (const chart of this.chartsProcessing) {
|
|
143
|
+
if (chart.errorMessage) {
|
|
144
|
+
continue; // skip charts with errors
|
|
145
|
+
}
|
|
143
146
|
this.applyRawData(chart, row, dateColumns[chart.definition.xdef.field], chart.isGivenDefinition ? numericColumns : numericColumnsForAutodetect, stringColumns);
|
|
147
|
+
if (Object.keys(chart.buckets).length > chartDefinitions_1.ChartLimits.CHART_FILL_LIMIT) {
|
|
148
|
+
chart.errorMessage = `Chart has too many buckets, limit is ${chartDefinitions_1.ChartLimits.CHART_FILL_LIMIT}.`;
|
|
149
|
+
}
|
|
144
150
|
}
|
|
145
151
|
for (let i = 0; i < this.chartsProcessing.length; i++) {
|
|
152
|
+
if (this.chartsProcessing[i].errorMessage) {
|
|
153
|
+
continue; // skip charts with errors
|
|
154
|
+
}
|
|
146
155
|
this.chartsProcessing[i] = (0, chartTools_1.autoAggregateCompactTimelineChart)(this.chartsProcessing[i]);
|
|
147
156
|
}
|
|
148
157
|
this.rowsAdded += 1;
|
|
@@ -173,17 +182,25 @@ class ChartProcessor {
|
|
|
173
182
|
this.applyLimitsOnCharts();
|
|
174
183
|
this.availableColumns = Object.values(this.availableColumnsDict);
|
|
175
184
|
for (const chart of this.chartsProcessing) {
|
|
185
|
+
if (chart.errorMessage) {
|
|
186
|
+
this.charts.push(chart);
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
176
189
|
let addedChart = chart;
|
|
177
|
-
if (chart.rowsAdded == 0) {
|
|
190
|
+
if (chart.rowsAdded == 0 && !chart.isGivenDefinition) {
|
|
178
191
|
continue; // skip empty charts
|
|
179
192
|
}
|
|
180
193
|
const sortOrder = (_a = chart.definition.xdef.sortOrder) !== null && _a !== void 0 ? _a : 'ascKeys';
|
|
181
194
|
if (sortOrder != 'natural') {
|
|
182
195
|
if (sortOrder == 'ascKeys' || sortOrder == 'descKeys') {
|
|
183
|
-
if (chart.definition.xdef.transformFunction.startsWith('date:')) {
|
|
196
|
+
if (chart.definition.chartType == 'line' && chart.definition.xdef.transformFunction.startsWith('date:')) {
|
|
184
197
|
addedChart = (0, chartTools_1.autoAggregateCompactTimelineChart)(addedChart);
|
|
185
198
|
(0, chartTools_1.fillChartTimelineBuckets)(addedChart);
|
|
186
199
|
}
|
|
200
|
+
if (addedChart.errorMessage) {
|
|
201
|
+
this.charts.push(addedChart);
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
187
204
|
addedChart.bucketKeysOrdered = (0, sortBy_1.default)(Object.keys(addedChart.buckets));
|
|
188
205
|
if (sortOrder == 'descKeys') {
|
|
189
206
|
addedChart.bucketKeysOrdered.reverse();
|
|
@@ -200,6 +217,10 @@ class ChartProcessor {
|
|
|
200
217
|
addedChart = Object.assign(Object.assign({}, addedChart), { definition: Object.assign(Object.assign({}, addedChart.definition), { ydefs: addedChart.definition.ydefs.filter(y => !addedChart.invalidYRows[y.field] &&
|
|
201
218
|
addedChart.validYRows[y.field] / addedChart.rowsAdded >= chartDefinitions_1.ChartLimits.VALID_VALUE_RATIO_LIMIT) }) });
|
|
202
219
|
}
|
|
220
|
+
if (addedChart.definition.trimXCountLimit != null &&
|
|
221
|
+
addedChart.bucketKeysOrdered.length > addedChart.definition.trimXCountLimit) {
|
|
222
|
+
addedChart.bucketKeysOrdered = addedChart.bucketKeysOrdered.slice(0, addedChart.definition.trimXCountLimit);
|
|
223
|
+
}
|
|
203
224
|
if (addedChart) {
|
|
204
225
|
addedChart.availableColumns = this.availableColumns;
|
|
205
226
|
this.charts.push(addedChart);
|
package/lib/chartTools.js
CHANGED
|
@@ -455,6 +455,7 @@ function fillChartTimelineBuckets(chart) {
|
|
|
455
455
|
}
|
|
456
456
|
const transform = chart.definition.xdef.transformFunction;
|
|
457
457
|
let currentParsed = fromParsed;
|
|
458
|
+
let count = 0;
|
|
458
459
|
while (compareChartDatesParsed(currentParsed, toParsed, transform) <= 0) {
|
|
459
460
|
const bucketKey = stringifyChartDate(currentParsed, transform);
|
|
460
461
|
if (!chart.buckets[bucketKey]) {
|
|
@@ -462,6 +463,11 @@ function fillChartTimelineBuckets(chart) {
|
|
|
462
463
|
chart.bucketKeyDateParsed[bucketKey] = currentParsed;
|
|
463
464
|
}
|
|
464
465
|
currentParsed = incrementChartDate(currentParsed, transform);
|
|
466
|
+
count++;
|
|
467
|
+
if (count > chartDefinitions_1.ChartLimits.CHART_FILL_LIMIT) {
|
|
468
|
+
chart.errorMessage = `Too many buckets to fill in chart, limit is ${chartDefinitions_1.ChartLimits.CHART_FILL_LIMIT}`;
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
465
471
|
}
|
|
466
472
|
}
|
|
467
473
|
exports.fillChartTimelineBuckets = fillChartTimelineBuckets;
|
|
@@ -354,4 +354,29 @@ describe('Chart processor', () => {
|
|
|
354
354
|
expect(chart.bucketKeysOrdered).toEqual(expectedOrder);
|
|
355
355
|
expect(chart.buckets).toEqual(expectedBuckets);
|
|
356
356
|
});
|
|
357
|
+
test.only('Incorrect chart definition', () => {
|
|
358
|
+
const processor = new chartProcessor_1.ChartProcessor([
|
|
359
|
+
{
|
|
360
|
+
chartType: 'bar',
|
|
361
|
+
xdef: {
|
|
362
|
+
field: 'category',
|
|
363
|
+
transformFunction: 'date:day',
|
|
364
|
+
},
|
|
365
|
+
ydefs: [],
|
|
366
|
+
},
|
|
367
|
+
]);
|
|
368
|
+
processor.addRows(...DS1.slice(0, 3));
|
|
369
|
+
processor.finalize();
|
|
370
|
+
expect(processor.charts.length).toEqual(1);
|
|
371
|
+
const chart = processor.charts[0];
|
|
372
|
+
expect(chart.definition.xdef.transformFunction).toEqual('date:day');
|
|
373
|
+
// console.log(getChartDebugPrint(processor.charts[0]));
|
|
374
|
+
// expect(chart.definition.xdef.transformFunction).toEqual('date:day');
|
|
375
|
+
// expect(chart.definition.ydefs).toEqual([
|
|
376
|
+
// expect.objectContaining({
|
|
377
|
+
// field: 'value',
|
|
378
|
+
// }),
|
|
379
|
+
// ]);
|
|
380
|
+
// expect(chart.bucketKeysOrdered).toEqual(['2023-10-01', '2023-10-02', '2023-10-03']);
|
|
381
|
+
});
|
|
357
382
|
});
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "6.5.
|
|
2
|
+
"version": "6.5.3",
|
|
3
3
|
"name": "dbgate-datalib",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"typings": "lib/index.d.ts",
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"date-fns": "^4.1.0",
|
|
18
|
-
"dbgate-filterparser": "^6.5.
|
|
19
|
-
"dbgate-sqltree": "^6.5.
|
|
20
|
-
"dbgate-tools": "^6.5.
|
|
18
|
+
"dbgate-filterparser": "^6.5.3",
|
|
19
|
+
"dbgate-sqltree": "^6.5.3",
|
|
20
|
+
"dbgate-tools": "^6.5.3",
|
|
21
21
|
"uuid": "^3.4.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/node": "^13.7.0",
|
|
25
|
-
"dbgate-types": "^6.5.
|
|
25
|
+
"dbgate-types": "^6.5.3",
|
|
26
26
|
"jest": "^28.1.3",
|
|
27
27
|
"ts-jest": "^28.0.7",
|
|
28
28
|
"typescript": "^4.4.3"
|