Skip to content

Commit 9f8dab7

Browse files
committed
pulling in changes from: PR #8199
1 parent 51453c0 commit 9f8dab7

File tree

6 files changed

+66
-31
lines changed

6 files changed

+66
-31
lines changed

src/plugins/plot/MctPlot.vue

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -639,11 +639,23 @@ export default {
639639
640640
this.startLoading();
641641
const bounds = this.timeContext.getBounds();
642+
let rangeBounds = {
643+
start: bounds.start,
644+
end: bounds.end
645+
};
646+
// If we have pan/zoom history, load based on the last viewed range instead of time conductor
647+
if (this.plotHistory.length > 0) {
648+
const historyRange = this.plotHistory.slice(-1)[0];
649+
rangeBounds = {
650+
start: historyRange.x.min,
651+
end: historyRange.x.max
652+
};
653+
}
642654
const options = {
643655
size: this.$parent.$refs.plotWrapper.offsetWidth,
644656
domain: this.config.xAxis.get('key'),
645-
start: bounds.start,
646-
end: bounds.end
657+
start: rangeBounds.start,
658+
end: rangeBounds.end
647659
};
648660
649661
series.load(options).then(this.stopLoading.bind(this));
@@ -1458,15 +1470,15 @@ export default {
14581470
// Don't zoom if mouse moved less than 7.5 pixels.
14591471
if (marqueeDistance > 7.5) {
14601472
this.config.xAxis.set('displayRange', {
1461-
min: Math.min(this.marquee.start.x, this.marquee.end.x),
1462-
max: Math.max(this.marquee.start.x, this.marquee.end.x)
1473+
min: Math.round(Math.min(this.marquee.start.x, this.marquee.end.x)),
1474+
max: Math.round(Math.max(this.marquee.start.x, this.marquee.end.x))
14631475
});
14641476
this.yAxisListWithRange.forEach((yAxis) => {
14651477
const yStartPosition = this.getYPositionForYAxis(this.marquee.start, yAxis);
14661478
const yEndPosition = this.getYPositionForYAxis(this.marquee.end, yAxis);
14671479
yAxis.set('displayRange', {
1468-
min: Math.min(yStartPosition, yEndPosition),
1469-
max: Math.max(yStartPosition, yEndPosition)
1480+
min: Math.round(Math.min(yStartPosition, yEndPosition)),
1481+
max: Math.round(Math.max(yStartPosition, yEndPosition))
14701482
});
14711483
});
14721484
this.userViewportChangeEnd();

src/plugins/plot/chart/MCTChartAlarmLineSet.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default class MCTChartAlarmLineSet {
6161

6262
makePoint(point, series) {
6363
if (!this.offset.xVal) {
64-
this.chart.setOffset(point, undefined, series);
64+
this.chart.setOffset(point, series);
6565
}
6666

6767
return {
@@ -112,6 +112,7 @@ export default class MCTChartAlarmLineSet {
112112
reset() {
113113
this.limits = [];
114114
if (this.series.limits) {
115+
this.chart.resetOffsets(this.offset);
115116
this.getLimitPoints(this.series);
116117
}
117118
}

src/plugins/plot/chart/MCTChartAlarmPointSet.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ export default class MCTChartAlarmPointSet {
4343

4444
append(datum) {
4545
if (datum.mctLimitState) {
46+
if (!this.offset.xVal) {
47+
this.chart.setOffset(datum, this.series);
48+
}
49+
4650
this.points.push({
4751
x: this.offset.xVal(datum, this.series),
4852
y: this.offset.yVal(datum, this.series),
@@ -58,6 +62,7 @@ export default class MCTChartAlarmPointSet {
5862
}
5963

6064
reset() {
65+
this.chart.resetOffsets(this.offset);
6166
this.points = [];
6267
}
6368

src/plugins/plot/chart/MCTChartSeriesElement.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,17 @@
2222

2323
import eventHelpers from '../lib/eventHelpers.js';
2424

25+
const bufferSize = 20000;
26+
2527
/** @abstract */
2628
export default class MCTChartSeriesElement {
2729
constructor(series, chart, offset) {
2830
this.series = series;
2931
this.chart = chart;
3032
this.offset = offset;
31-
this.buffer = new Float32Array(20000);
33+
this.buffer = new Float32Array(bufferSize);
3234
this.count = 0;
35+
this.indexCount = 0;
3336

3437
eventHelpers.extend(this);
3538

@@ -94,7 +97,7 @@ export default class MCTChartSeriesElement {
9497

9598
makePoint(point, series) {
9699
if (!this.offset.xVal) {
97-
this.chart.setOffset(point, undefined, series);
100+
this.chart.setOffset(point, series);
98101
}
99102

100103
return {
@@ -104,12 +107,15 @@ export default class MCTChartSeriesElement {
104107
}
105108

106109
append(point, index, series) {
107-
const pointsRequired = this.vertexCountForPointAtIndex(index);
108-
const insertionPoint = this.startIndexForPointAtIndex(index);
109-
this.growIfNeeded(pointsRequired);
110-
this.makeInsertionPoint(insertionPoint, pointsRequired);
111-
this.addPoint(this.makePoint(point, series), insertionPoint);
112-
this.count += pointsRequired / 2;
110+
if (this.chart.pointIsInRange(point, series)) {
111+
const pointsRequired = this.vertexCountForPointAtIndex(this.indexCount);
112+
const insertionPoint = this.startIndexForPointAtIndex(this.indexCount);
113+
this.growIfNeeded(pointsRequired);
114+
this.makeInsertionPoint(insertionPoint, pointsRequired);
115+
this.addPoint(this.makePoint(point, series), insertionPoint);
116+
this.count += pointsRequired / 2;
117+
this.indexCount++;
118+
}
113119
}
114120

115121
makeInsertionPoint(insertionPoint, pointsRequired) {
@@ -128,9 +134,13 @@ export default class MCTChartSeriesElement {
128134
}
129135

130136
reset() {
131-
this.buffer = new Float32Array(20000);
137+
this.buffer = new Float32Array(bufferSize);
132138
this.count = 0;
139+
this.indexCount = 0;
133140
if (this.offset.x) {
141+
// reset the offset since we're starting over
142+
// TODO: handle what happens when we zoom out - do we request the data again?
143+
this.chart.resetOffsets(this.offset);
134144
this.series.getSeriesData().forEach(function (point, index) {
135145
this.append(point, index, this.series);
136146
}, this);
@@ -142,7 +152,7 @@ export default class MCTChartSeriesElement {
142152
let temp;
143153

144154
if (remainingPoints <= pointsRequired) {
145-
temp = new Float32Array(this.buffer.length + 20000);
155+
temp = new Float32Array(this.buffer.length + bufferSize);
146156
temp.set(this.buffer);
147157
this.buffer = temp;
148158
}

src/plugins/plot/chart/MctChart.vue

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,12 @@ export default {
366366
this.seriesModels.splice(seriesIndexToRemove, 1);
367367
},
368368
onAddPoint(point, insertIndex, series) {
369+
// if user is not looking at data within the current bounds, don't draw the point
370+
if (this.pointIsInRange(point, series)) {
371+
this.scheduleDraw();
372+
}
373+
},
374+
pointIsInRange(point, series) {
369375
const mainYAxisId = this.config.yAxis.get('id');
370376
const seriesYAxisId = series.get('yAxisId');
371377
const xRange = this.config.xAxis.get('displayRange');
@@ -383,14 +389,9 @@ export default {
383389
const yValue = series.getYVal(point);
384390
385391
// if user is not looking at data within the current bounds, don't draw the point
386-
if (
387-
xValue > xRange.min &&
388-
xValue < xRange.max &&
389-
yValue > yRange.min &&
390-
yValue < yRange.max
391-
) {
392-
this.scheduleDraw();
393-
}
392+
return (
393+
xValue > xRange.min && xValue < xRange.max && yValue > yRange.min && yValue < yRange.max
394+
);
394395
},
395396
changeInterpolate(mode, o, series) {
396397
if (mode === o) {
@@ -505,17 +506,23 @@ export default {
505506
pointSet.reset();
506507
});
507508
},
508-
setOffset(offsetPoint, index, series) {
509+
// This function is designed to establish a relative coordinate system for a data series.
510+
// It defines a specific data point as the new origin (0, 0).
511+
// In the context of plotting large time-series data using relative time,
512+
// this function is a key step in implementing the "Relative Time".
513+
// It shifts the entire series so that one chosen point (offsets) now corresponds to zero on both the X and Y axes.
514+
// Any subsequent data points are then plotted relative to this new origin (x - offsets.x and y - offsets.y)
515+
setOffset(offsetPoint, series) {
509516
const mainYAxisId = this.config.yAxis.get('id');
510517
const yAxisId = series.get('yAxisId') || mainYAxisId;
511518
if (this.offset[yAxisId].x && this.offset[yAxisId].y) {
512519
return;
513520
}
514521
515-
const offsets = {
516-
x: series.getXVal(offsetPoint),
517-
y: series.getYVal(offsetPoint)
518-
};
522+
// Set the origin point.
523+
let offsets = {};
524+
offsets.x = series.getXVal(offsetPoint);
525+
offsets.y = series.getYVal(offsetPoint);
519526
520527
this.offset[yAxisId].x = function (x) {
521528
return x - offsets.x;

src/plugins/plot/configuration/PlotSeries.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export default class PlotSeries extends Model {
230230
const newPoints = _(data)
231231
.concat(points)
232232
.sortBy(this.getXVal)
233-
.uniq(true, (point) => [this.getXVal(point), this.getYVal(point)].join())
233+
.uniqBy((point) => [this.getXVal(point), this.getYVal(point)].join())
234234
.value();
235235
this.reset(newPoints);
236236
} catch (error) {

0 commit comments

Comments
 (0)