Skip to content

Commit

Permalink
merge fix
Browse files Browse the repository at this point in the history
  • Loading branch information
enjalot committed Dec 1, 2024
1 parent 73cfcb6 commit 73e8c01
Showing 1 changed file with 0 additions and 44 deletions.
44 changes: 0 additions & 44 deletions web/src/components/Scatter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ import { rgb } from 'd3-color';
import { interpolateViridis, interpolateTurbo, interpolateCool } from 'd3-scale-chromatic';
import { SELECT } from '../pages/FullScreenExplore';

import styles from './Scatter.module.css';
import styles from './Scatter.module.css';

import PropTypes from 'prop-types';
ScatterPlot.propTypes = {
points: PropTypes.array.isRequired, // an array of [x,y] points
points: PropTypes.array.isRequired, // an array of [x,y] points
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
pointScale: PropTypes.number,
colorScaleType: PropTypes.oneOf(['categorical', 'continuous']),
colorScaleType: PropTypes.oneOf(['categorical', 'continuous']),
colorDomain: PropTypes.array,
colorRange: PropTypes.array,
colorInterpolator: PropTypes.func,
Expand All @@ -34,32 +30,23 @@ ScatterPlot.propTypes = {
const calculatePointSize = (numPoints) => {
const minPoints = 100; // Minimum number of points to start scaling
const maxPoints = 1000000;
const maxPoints = 1000000;
const minSize = 6; // Minimum size of points
const maxSize = 1; // Maximum size of points when number of points is very large
const scale = scaleLog().domain([minPoints, maxPoints]).range([minSize, maxSize]).clamp(true);
const scale = scaleLog().domain([minPoints, maxPoints]).range([minSize, maxSize]).clamp(true);
return scale(numPoints);
};
const calculatePointOpacity = (numPoints) => {
const minPoints = 100; // Minimum number of points to start scaling
const maxPoints = 1000000;
const minOpacity = 0.2;
const maxOpacity = 0.7;
const maxPoints = 1000000;
const minOpacity = 0.2;
const maxOpacity = 0.7;
const scale = scaleLog()
.domain([minPoints, maxPoints])
.range([maxOpacity, minOpacity])
.clamp(true);
return scale(numPoints);
};

function ScatterPlot({
points,
width,
height,
function ScatterPlot({
points,
width,
Expand Down Expand Up @@ -94,21 +81,16 @@ function ScatterPlot({
const xScale = scaleLinear()
// .domain(xDomain.current)
.domain([-1, 1]);
.domain([-1, 1]);
const yScale = scaleLinear()
// .domain(yDomain.current)
.domain([-1, 1]);

const selectKeyMap = { alt: 'rotate', shift: 'lasso' };

const scatterSettings = {
canvas: container.current,
width,
height,
pointColorHover: [0.1, 0.1, 0.1, 0.5],
xScale,
yScale,
keyMap: activeFilterTab === SELECT ? selectKeyMap : {},
};
// console.log("creating scatterplot", xDomain.current)
const scatterplot = createScatterplot(scatterSettings);
Expand All @@ -134,23 +116,16 @@ function ScatterPlot({
scatterplot.subscribe('select', ({ points }) => {
onSelect && onSelect(points);
});
scatterplot.subscribe('deselect', () => {
onSelect && onSelect([]);
scatterplot.subscribe('deselect', () => {
onSelect && onSelect([]);
});
scatterplot.subscribe('pointOver', (pointIndex) => {
onHover && onHover(pointIndex);
scatterplot.subscribe('pointOver', (pointIndex) => {
onHover && onHover(pointIndex);
});
scatterplot.subscribe('pointOut', () => {
onHover && onHover(null);
scatterplot.subscribe('pointOut', () => {
onHover && onHover(null);
});


// const canvas = container.current;
// canvas.addEventListener('mouseleave', handleMouseLeave);

Expand All @@ -167,7 +142,6 @@ function ScatterPlot({
useEffect(() => {
const scatterplot = scatterplotRef.current;
const prevPoints = prevPointsRef.current;
if (scatterplot && points && points.length) {
if (scatterplot && points && points.length) {
const pointSize = calculatePointSize(points.length) * pointScale;
const opacity = calculatePointOpacity(points.length);
Expand All @@ -193,58 +167,40 @@ function ScatterPlot({
.sort((a, b) => a - b);
}
let domain = extent(uniques).reverse();
if (!colorRange) {
const colorScale = scaleSequential(colorInterpolator).domain(domain);
pointColor = range(uniques).map((u) => rgb(colorScale(u)).hex());
let domain = extent(uniques).reverse();
if (!colorRange) {
const colorScale = scaleSequential(colorInterpolator).domain(domain);
pointColor = range(uniques).map((u) => rgb(colorScale(u)).hex());
} else {
pointColor = colorRange;
pointColor = colorRange;
}
} else if (colorScaleType === 'continuous') {
let r = range(0, 100);
const colorScale = scaleSequential(colorInterpolator).domain([0, 100]);
pointColor = r.map((i) => rgb(colorScale(i)).hex());
} else if (colorScaleType === 'continuous') {
let r = range(0, 100);
const colorScale = scaleSequential(colorInterpolator).domain([0, 100]);
pointColor = r.map((i) => rgb(colorScale(i)).hex());
}

if (colorScaleType) {
scatterplot.set({ colorBy: 'valueA' });
if (colorScaleType) {
scatterplot.set({ colorBy: 'valueA' });
}
if (opacityBy) {
if (opacityBy) {
scatterplot.set({
opacityBy,
sizeBy: opacityBy,
opacity: opacityRange || [0.1, 0.2, 0.3, 0.4, 0.5, 1],
pointSize: pointSizeRange || [2, 4, 5, 6, pointSize],
});
opacity: opacityRange || [0.1, 0.2, 0.3, 0.4, 0.5, 1],
pointSize: pointSizeRange || [2, 4, 5, 6, pointSize],
});
} else {
scatterplot.set({
opacity: opacity,
pointSize: pointSize,
});
});
}
if (prevPoints && prevPoints.length === points.length) {
scatterplot.draw(points, { transition: true, transitionDuration: duration }).then(() => {
scatterplot.draw(points, { transition: true, transitionDuration: duration }).then(() => {
// don't color till after
scatterplot.set({
pointColor: pointColor,
});
});
scatterplot.draw(points, { transition: false });
});
} else {
Expand Down

0 comments on commit 73e8c01

Please sign in to comment.