Skip to content

Commit

Permalink
at this point, we may want to revert
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbell committed Aug 18, 2023
1 parent 9f6880b commit 6978b34
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 44 deletions.
32 changes: 24 additions & 8 deletions src/plugins/plot/MctPlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ import MctChart from './chart/MctChart.vue';
import XAxis from './axis/XAxis.vue';
import YAxis from './axis/YAxis.vue';
import Flatbush from 'flatbush';
import _ from 'lodash';

const OFFSET_THRESHOLD = 10;
const AXES_PADDING = 20;
Expand Down Expand Up @@ -1390,7 +1389,7 @@ export default {
if (!series) {
return;
}
if (!annotationsBySeries[seriesId]){
if (!annotationsBySeries[seriesId]) {
annotationsBySeries[seriesId] = [];
}

Expand All @@ -1408,7 +1407,10 @@ export default {
Object.keys(pointsInBoxBySeries).forEach((seriesKeyString) => {
const pointsInBox = pointsInBoxBySeries[seriesKeyString];
if (pointsInBox && pointsInBox.length) {
annotationsBySeries[seriesKeyString].push(...pointsInBox);
annotationsBySeries[seriesKeyString] = this.concatTypedArrays(
annotationsBySeries[seriesKeyString],
pointsInBox
);
}
});
}
Expand Down Expand Up @@ -1459,13 +1461,12 @@ export default {
if (seriesData && seriesData.length) {
searchResultsBySeries[seriesModel.keyString] = [];
const rangeResults = this.searchWithFlatbush(seriesData, seriesModel, boundingBox);
rangeResults.forEach((id) => {
const searchResultsBuffer = new Float32Array(rangeResults.length * 2);
rangeResults.forEach((id, index) => {
const seriesDatum = seriesData[id];
if (seriesDatum) {
const result = {
point: seriesDatum
};
searchResultsBySeries[seriesModel.keyString].push(result);
searchResultsBuffer[index * 2] = seriesModel.getXVal(seriesDatum);
searchResultsBuffer[index * 2 + 1] = seriesModel.getYVal(seriesDatum);
}

if (rawAnnotation) {
Expand All @@ -1479,11 +1480,25 @@ export default {
seriesDatum.annotationsById[annotationKeyString] = rawAnnotation;
}
});
searchResultsBySeries[seriesModel.keyString] = this.concatTypedArrays(
searchResultsBySeries[seriesModel.keyString],
searchResultsBuffer
);
}
});

return searchResultsBySeries;
},
concatTypedArrays(sourceArray, targetArray) {
if (!sourceArray) {
return targetArray;
}
const combinedArray = new Float32Array(sourceArray.length + targetArray.length);
combinedArray.set(sourceArray);
combinedArray.set(targetArray, sourceArray.length);

return combinedArray;
},
endAnnotationMarquee(event) {
const boundingBoxPerYAxis = [];
this.yAxisListWithRange.forEach((yAxis, yIndex) => {
Expand All @@ -1509,6 +1524,7 @@ export default {
}

this.annotationSelectionsBySeries = pointsInBoxBySeries;
console.debug('🤖 Found points', this.annotationSelectionsBySeries);
this.selectNewPlotAnnotations(boundingBoxPerYAxis, this.annotationSelectionsBySeries, event);
},
endZoomMarquee() {
Expand Down
48 changes: 12 additions & 36 deletions src/plugins/plot/chart/MctChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -833,31 +833,17 @@ export default {
},
prepareToDrawAnnotatedPoints(yAxisId) {
if (this.annotatedPointsBySeries && Object.values(this.annotatedPointsBySeries).length) {
const uniquePointsToDraw = [];

Object.keys(this.annotatedPointsBySeries).forEach((seriesKeyString) => {
const seriesModel = this.getSeries(seriesKeyString);
const matchesYAxis = this.matchByYAxisId(yAxisId, { series: seriesModel });
if (matchesYAxis) {
// annotation points are all within range (checked in MctPlot with FlatBush), so we don't need to check
const annotatedPointBuffer = new Float32Array(
this.annotatedPointsBySeries[seriesKeyString].length * 2
);
Object.values(this.annotatedPointsBySeries[seriesKeyString]).forEach(
(annotatedPoint, index) => {
const canvasXValue = this.offset[yAxisId].xVal(annotatedPoint.point, seriesModel);
const canvasYValue = this.offset[yAxisId].yVal(annotatedPoint.point, seriesModel);
const drawnPoint = uniquePointsToDraw.some((rawPoint) => {
return rawPoint[0] === canvasXValue && rawPoint[1] === canvasYValue;
});
if (!drawnPoint) {
annotatedPointBuffer[index * 2] = canvasXValue;
annotatedPointBuffer[index * 2 + 1] = canvasYValue;
uniquePointsToDraw.push([canvasXValue, canvasYValue]);
}
}
//console.time('🎨 drawAnnotations opengl');
this.drawAnnotatedPoints(
seriesModel,
toRaw(this.annotatedPointsBySeries[seriesKeyString])
);
this.drawAnnotatedPoints(seriesModel, annotatedPointBuffer);
//console.timeEnd('🎨 drawAnnotations opengl');
}
});
}
Expand All @@ -869,6 +855,7 @@ export default {
color[3] = 0.15;
const pointCount = annotatedPointBuffer.length / 2;
const shape = seriesModel.get('markerShape');
console.debug(`🎨 drawAnnotationPoints opengl`, annotatedPointBuffer);

this.drawAPI.drawPoints(annotatedPointBuffer, color, pointCount, ANNOTATION_SIZE, shape);
}
Expand All @@ -882,24 +869,12 @@ export default {
const seriesModel = this.getSeries(seriesKeyString);
const matchesYAxis = this.matchByYAxisId(yAxisId, { series: seriesModel });
if (matchesYAxis) {
const annotationSelectionBuffer = new Float32Array(
this.annotationSelectionsBySeries[seriesKeyString].length * 2
);
Object.values(this.annotationSelectionsBySeries[seriesKeyString]).forEach(
(annotatedSelectedPoint, index) => {
const canvasXValue = this.offset[yAxisId].xVal(
annotatedSelectedPoint.point,
seriesModel
);
const canvasYValue = this.offset[yAxisId].yVal(
annotatedSelectedPoint.point,
seriesModel
);
annotationSelectionBuffer[index * 2] = canvasXValue;
annotationSelectionBuffer[index * 2 + 1] = canvasYValue;
}
console.time('🎨 drawAnnotationSelections opengl');
this.drawAnnotationSelections(
seriesModel,
toRaw(this.annotationSelectionsBySeries[seriesKeyString])
);
this.drawAnnotationSelections(seriesModel, annotationSelectionBuffer);
console.timeEnd('🎨 drawAnnotationSelections opengl');
}
});
}
Expand All @@ -908,6 +883,7 @@ export default {
const color = [255, 255, 255, 1]; // white
const pointCount = annotationSelectionBuffer.length / 2;
const shape = seriesModel.get('markerShape');
console.debug(`🎨 drawAnnotationSelections opengl`, annotationSelectionBuffer);

this.drawAPI.drawPoints(annotationSelectionBuffer, color, pointCount, ANNOTATION_SIZE, shape);
},
Expand Down

0 comments on commit 6978b34

Please sign in to comment.