Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show set of labels for selected points #138

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 29 additions & 24 deletions src/scatter_gl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export class ScatterGL {

private generateVisibleLabelRenderParams(): LabelRenderParams {
const {hoverPointIndex, selectedPointIndices, styles} = this;
const n = hoverPointIndex !== null ? 1 : 0;
const n = selectedPointIndices.size + (hoverPointIndex !== null ? 1 : 0);

const visibleLabels = new Uint32Array(n);
const scale = new Float32Array(n);
Expand All @@ -368,6 +368,7 @@ export class ScatterGL {

let dst = 0;

// Hover point
if (hoverPointIndex !== null) {
labelStrings.push(this.getLabelText(hoverPointIndex));
visibleLabels[dst] = hoverPointIndex;
Expand Down Expand Up @@ -401,26 +402,30 @@ export class ScatterGL {
styles.label.strokeColorSelected
);

if (selectedPointIndices.size === 1) {
const labelIndex = [...selectedPointIndices][0];
labelStrings.push(this.getLabelText(labelIndex));
visibleLabels[dst] = labelIndex;
scale[dst] = styles.label.scaleLarge;
opacityFlags[dst] = 0;
util.packRgbIntoUint8Array(
fillColors,
dst,
fillRgb[0],
fillRgb[1],
fillRgb[2]
);
util.packRgbIntoUint8Array(
strokeColors,
dst,
strokeRgb[0],
strokeRgb[1],
strokeRgb[2]
);
if (selectedPointIndices.size > 0) {
const arr = [...selectedPointIndices];
for (let i = 0; i < arr.length; i++) {
const labelIndex = arr[i];
labelStrings.push(this.getLabelText(labelIndex));
visibleLabels[dst] = labelIndex;
scale[dst] = styles.label.scaleLarge;
opacityFlags[dst] = 0;
util.packRgbIntoUint8Array(
fillColors,
dst,
fillRgb[0],
fillRgb[1],
fillRgb[2]
);
util.packRgbIntoUint8Array(
strokeColors,
dst,
strokeRgb[0],
strokeRgb[1],
strokeRgb[2]
);
++dst;
}
}
}

Expand Down Expand Up @@ -657,9 +662,9 @@ export class ScatterGL {
}

private initializeCanvasLabelsVisualizer() {
if (!this.canvasLabelsVisualizer) {
if (!this.canvasLabelsVisualizer && this.containerElement) {
this.canvasLabelsVisualizer = new ScatterPlotVisualizerCanvasLabels(
this.containerElement!,
this.containerElement,
this.styles
);
}
Expand Down Expand Up @@ -749,7 +754,7 @@ export class ScatterGL {
renderMode === RenderMode.POINT || renderMode === RenderMode.SPRITE;
if (textLabelsRenderMode && this.showLabelsOnHover) {
const visualizer = this.initializeCanvasLabelsVisualizer();
activeVisualizers.push(visualizer);
visualizer && activeVisualizers.push(visualizer);
}

this.scatterPlot.setActiveVisualizers(activeVisualizers);
Expand Down