switch plots to use flatbush

This commit is contained in:
Scott Bell 2023-04-20 15:18:42 +02:00
parent 72d8779736
commit 91ad130f8b
2 changed files with 35 additions and 10 deletions

View File

@ -33,7 +33,6 @@
<script>
import e from 'cors';
import Flatbush from 'flatbush';
const EXISTING_ANNOTATION_STROKE_STYLE = "#D79078";
const EXISTING_ANNOTATION_FILL_STYLE = "rgba(202, 202, 142, 0.2)";

View File

@ -215,6 +215,7 @@ import MctChart from "./chart/MctChart.vue";
import XAxis from "./axis/XAxis.vue";
import YAxis from "./axis/YAxis.vue";
import KDBush from 'kdbush';
import Flatbush from 'flatbush';
import _ from "lodash";
const OFFSET_THRESHOLD = 10;
@ -1348,6 +1349,32 @@ export default {
return annotationsByPoints.flat();
},
searchWithKDTree(seriesData, seriesModel, boundingBox) {
const kdTree = new KDBush(seriesData,
(point) => {
return seriesModel.getXVal(point);
},
(point) => {
return seriesModel.getYVal(point);
}
);
const rangeResults = kdTree.range(boundingBox.minX, boundingBox.minY, boundingBox.maxX, boundingBox.maxY);
return rangeResults;
},
searchWithFlatbush(seriesData, seriesModel, boundingBox) {
const flatbush = new Flatbush(seriesData.length);
seriesData.forEach(point => {
const x = seriesModel.getXVal(point);
const y = seriesModel.getYVal(point);
flatbush.add(x, y, x, y);
});
flatbush.finish();
const rangeResults = flatbush.search(boundingBox.minX, boundingBox.minY, boundingBox.maxX, boundingBox.maxY);
return rangeResults;
},
getPointsInBox(boundingBoxPerYAxis, rawAnnotation) {
// load series models in KD-Trees
const seriesKDTrees = [];
@ -1361,16 +1388,15 @@ export default {
const seriesData = seriesModel.getSeriesData();
if (seriesData && seriesData.length) {
const kdTree = new KDBush(seriesData,
(point) => {
return seriesModel.getXVal(point);
},
(point) => {
return seriesModel.getYVal(point);
}
);
const searchResults = [];
const rangeResults = kdTree.range(boundingBox.minX, boundingBox.minY, boundingBox.maxX, boundingBox.maxY);
let startTime = Date.now();
let rangeResults = this.searchWithKDTree(seriesData, seriesModel, boundingBox);
let endTime = Date.now();
console.debug(`KD Tree Annotation search took ${endTime - startTime} ms for ${seriesData.length} points`);
startTime = Date.now();
rangeResults = this.searchWithFlatbush(seriesData, seriesModel, boundingBox);
endTime = Date.now();
console.debug(`Flatbush Tree Annotation search took ${endTime - startTime} ms for ${seriesData.length} points`);
rangeResults.forEach(id => {
const seriesDatum = seriesData[id];
if (seriesDatum) {