Skip to content

Commit e11ae50

Browse files
authored
Merge pull request tradingview#2025 from tradingview/data-conflation-part2
Fix conflation logic and update tests for data handling
2 parents 91169a1 + 4d5dda7 commit e11ae50

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

src/model/data-conflater.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,19 +445,18 @@ export class DataConflater<T extends SeriesType, HorzScaleItem = unknown> {
445445
}
446446

447447
const lastOriginalIndex = originalData.length - 1;
448-
const overrideIndex = lastOriginalIndex;
449448
const chunkStartIndex = Math.floor(lastOriginalIndex / conflationLevel) * conflationLevel;
450449
const chunkEndIndex = Math.min(chunkStartIndex + conflationLevel, originalData.length);
451450

452451
if (chunkEndIndex - chunkStartIndex < conflationLevel && originalData.length > conflationLevel) {
453452
// we must allocate a new array here to do a full rebuild.
454453
const newOriginalData = originalData.slice();
455454
newOriginalData[newOriginalData.length - 1] = newLastRow;
456-
return this.conflateByFactor(originalData, conflationLevel, customReducer, isCustomSeries, priceValueBuilder);
455+
return this.conflateByFactor(newOriginalData, conflationLevel, customReducer, isCustomSeries, priceValueBuilder);
457456
}
458457

459458
const lastChunkIndex = Math.floor((lastOriginalIndex - 1) / conflationLevel);
460-
const newChunkIndex = Math.floor(overrideIndex / conflationLevel);
459+
const newChunkIndex = Math.floor(lastOriginalIndex / conflationLevel);
461460

462461
if (lastChunkIndex === newChunkIndex || cachedRows.length === 1) {
463462
// Data length is within the same chunk OR it's the only chunk
@@ -469,10 +468,10 @@ export class DataConflater<T extends SeriesType, HorzScaleItem = unknown> {
469468
}
470469

471470
const mergedChunk = count === 1
472-
? this._plotRowToChunk((chunkStartIndex === overrideIndex) ? newLastRow : originalData[chunkStartIndex], /* isRemainder*/ true)
471+
? this._plotRowToChunk((chunkStartIndex === lastOriginalIndex) ? newLastRow : originalData[chunkStartIndex], /* isRemainder*/ true)
473472
: this._mergeRangeWithOverride(
474473
originalData, chunkStartIndex, actualEndIndex,
475-
overrideIndex, newLastRow,
474+
lastOriginalIndex, newLastRow,
476475
customReducer, isCustomSeries, priceValueBuilder
477476
);
478477

src/model/time-scale.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,17 +261,16 @@ export interface HorzScaleOptions {
261261

262262
/**
263263
* Precompute conflation chunks for common levels right after data load.
264-
* When enabled, the system will precompute conflation data for standard factors
265-
* (2, 5, 10, 25, 50, 100, 200, 300) in the background, which improves performance
266-
* when zooming out but increases initial load time and memory usage.
264+
* When enabled, the system will precompute conflation data in the background,
265+
* which improves performance when zooming out but increases initial load time
266+
* and memory usage.
267267
*
268268
* Performance impact:
269269
* - Initial load: +100-500ms depending on dataset size
270270
* - Memory usage: +20-50% of original dataset size
271271
* - Zoom performance: Significant improvement (10-100x faster)
272272
*
273273
* Recommended for: Large datasets (\>10K points) on machines with sufficient memory
274-
* Precompute conflation chunks for common levels right after data load.
275274
* @defaultValue false
276275
*/
277276
precomputeConflationOnInit: boolean;

tests/e2e/graphics/test-cases/time-scale/conflation-line-series.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
function generateData() {
1+
function generateData(count) {
22
const res = [];
33
const time = new Date(Date.UTC(2018, 0, 1, 0, 0, 0, 0));
4-
for (let i = 0; i < 1000; ++i) {
4+
for (let i = 0; i < count; ++i) {
55
res.push({
66
time: time.getTime() / 1000,
77
value: i,
@@ -28,7 +28,7 @@ function runTestCase(container) {
2828
lineWidth: 2,
2929
});
3030

31-
// Generate 400k data points
31+
// Generate 40k data points
3232
const data = generateData(40000);
3333
lineSeries.setData(data);
3434

tests/unittests/data-layer.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function createSeriesMock<T extends SeriesType = SeriesType>(seriesType?: T): Se
2323

2424
return {
2525
bars: () => data,
26+
conflatedBars: () => data,
2627
seriesType: () => seriesType || 'Line',
2728
customSeriesPlotValuesBuilder: () => {},
2829
customSeriesWhitespaceCheck: () => {},

0 commit comments

Comments
 (0)