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

feat: density-based point size #143

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Prev Previous commit
Next Next commit
Adjust the hover rendering
Also fix an issue with `scatter.get('filteredPoints')`
  • Loading branch information
flekschas committed May 29, 2023
commit 3811756086ef2c4d882030e09141f111aaab3b60
2 changes: 1 addition & 1 deletion src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export const DEFAULT_GAMMA = 1;
// Default styles
export const MIN_POINT_SIZE = 1;
export const DEFAULT_POINT_SIZE = 6;
export const DEFAULT_POINT_SIZE_SELECTED = 2;
export const DEFAULT_POINT_SIZE_SELECTED = 0;
export const DEFAULT_POINT_OUTLINE_WIDTH = 2;
export const DEFAULT_SIZE_BY = null;
export const DEFAULT_POINT_CONNECTION_SIZE = 2;
Expand Down
56 changes: 37 additions & 19 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ const createScatterplot = (
let canvasObserver;
let densityBasedOpacity = 1;
let densityBasedPointSize = 1;
let hoveredPointExtraSize = 0;

const positionBuffer = renderer.regl.buffer([
-1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1,
Expand Down Expand Up @@ -1658,7 +1659,7 @@ const createScatterplot = (
getNormalPointsIndexBuffer
);

const drawHoveredPoint = drawPoints(
const drawHoveredPointBody = drawPoints(
getNormalPointSizeExtra,
() => 1,
() => hoveredPointIndexBuffer,
Expand All @@ -1667,6 +1668,40 @@ const createScatterplot = (
() => 1
);

// Draw outer outline
const drawHoveredPointOutline = drawPoints(
() => hoveredPointExtraSize * window.devicePixelRatio,
() => 1,
() => hoveredPointIndexBuffer,
COLOR_ACTIVE_IDX,
() => 1,
() => 1
);

// Draw inner outline
const drawHoveredPointInnerBorder = drawPoints(
() => hoveredPointExtraSize * window.devicePixelRatio,
() => 1,
() => hoveredPointIndexBuffer,
COLOR_BG_IDX,
() => 1,
() => 1
);

const drawHoveredPoint = () => {
const pointExtraSize = selectedPointsSet.has(hoveredPoint)
? pointSizeSelected
: 0;

const pointOutlineWidthPx = pointOutlineWidth / camera.scaling[0];

hoveredPointExtraSize = pointExtraSize + pointOutlineWidthPx * 2;
drawHoveredPointOutline();
hoveredPointExtraSize = pointExtraSize + pointOutlineWidthPx;
drawHoveredPointInnerBorder();
drawHoveredPointBody();
};

const drawSelectedPointOutlines = drawPoints(
() => (pointSizeSelected + pointOutlineWidth * 2) * window.devicePixelRatio,
getSelectedNumPoints,
Expand Down Expand Up @@ -1786,23 +1821,6 @@ const createScatterplot = (

reticleHLine.draw();
reticleVLine.draw();

// Draw outer outline
drawPoints(
() =>
(pointSizeSelected + pointOutlineWidth * 2) * window.devicePixelRatio,
() => 1,
hoveredPointIndexBuffer,
COLOR_ACTIVE_IDX
)();

// Draw inner outline
drawPoints(
() => (pointSizeSelected + pointOutlineWidth) * window.devicePixelRatio,
() => 1,
hoveredPointIndexBuffer,
COLOR_BG_IDX
)();
};

const createPointIndex = (numNewPoints) => {
Expand Down Expand Up @@ -2993,7 +3011,7 @@ const createScatterplot = (
if (property === 'filteredPoints')
return isPointsFiltered
? Array.from(filteredPointsSet)
: Array.from({ length: searchIndex.points.length }, (_, i) => i);
: Array.from({ length: points.length }, (_, i) => i);
if (property === 'pointsInView') return getPointsInView();
if (property === 'pointColor')
return pointColor.length === 1 ? pointColor[0] : pointColor;
Expand Down