Skip to content

Commit 2fbb836

Browse files
committed
Fix and test toRgba(). Fix point and connection return values
1 parent e851ddf commit 2fbb836

5 files changed

Lines changed: 234 additions & 82 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Stop calling `camera.refresh()` as that is unnecessary since `v1.2.2`
66
- Avoid empty lasso events
77
- Fix incorrectly initialized `pointConnectionColorBy`, `pointConnectionOpacityBy`, and `pointConnectionSizeBy`
8+
- Fix an issue with the color conversion to RGBA
89

910
## v0.16.1
1011

src/constants.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,17 @@ export const DEFAULT_WIDTH = 100;
7979
export const DEFAULT_HEIGHT = 100;
8080

8181
// Default styles
82-
export const DEFAULT_POINT_SIZE = [6];
82+
export const DEFAULT_POINT_SIZE = 6;
8383
export const DEFAULT_POINT_SIZE_SELECTED = 2;
8484
export const DEFAULT_POINT_OUTLINE_WIDTH = 2;
8585
export const DEFAULT_SIZE_BY = null;
86-
export const DEFAULT_POINT_CONNECTION_SIZE = [2];
86+
export const DEFAULT_POINT_CONNECTION_SIZE = 2;
8787
export const DEFAULT_POINT_CONNECTION_SIZE_ACTIVE = 2;
8888
export const DEFAULT_POINT_CONNECTION_SIZE_BY = null;
8989
export const DEFAULT_POINT_CONNECTION_OPACITY = null;
9090
export const DEFAULT_POINT_CONNECTION_OPACITY_BY = null;
9191
export const DEFAULT_POINT_CONNECTION_OPACITY_ACTIVE = 0.66;
92-
export const DEFAULT_OPACITY = [1];
92+
export const DEFAULT_OPACITY = 1;
9393
export const DEFAULT_OPACITY_BY = null;
9494

9595
// Default colors

src/index.js

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,9 @@ const createScatterplot = (initialProperties = {}) => {
292292
if (pointConnectionColor === 'inherit') {
293293
pointConnectionColor = [...pointColor];
294294
} else {
295-
pointConnectionColor =
296-
pointConnectionColor === isMultipleColors(pointConnectionColor)
297-
? [...pointConnectionColor]
298-
: [pointConnectionColor];
295+
pointConnectionColor = isMultipleColors(pointConnectionColor)
296+
? [...pointConnectionColor]
297+
: [pointConnectionColor];
299298
pointConnectionColor = pointConnectionColor.map((color) =>
300299
toRgba(color, true)
301300
);
@@ -304,11 +303,9 @@ const createScatterplot = (initialProperties = {}) => {
304303
if (pointConnectionColorActive === 'inherit') {
305304
pointConnectionColorActive = [...pointColorActive];
306305
} else {
307-
pointConnectionColorActive =
308-
pointConnectionColorActive ===
309-
isMultipleColors(pointConnectionColorActive)
310-
? [...pointConnectionColorActive]
311-
: [pointConnectionColorActive];
306+
pointConnectionColorActive = isMultipleColors(pointConnectionColorActive)
307+
? [...pointConnectionColorActive]
308+
: [pointConnectionColorActive];
312309
pointConnectionColorActive = pointConnectionColorActive.map((color) =>
313310
toRgba(color, true)
314311
);
@@ -317,10 +314,9 @@ const createScatterplot = (initialProperties = {}) => {
317314
if (pointConnectionColorHover === 'inherit') {
318315
pointConnectionColorHover = [...pointColorHover];
319316
} else {
320-
pointConnectionColorHover =
321-
pointConnectionColorHover === isMultipleColors(pointConnectionColorHover)
322-
? [...pointConnectionColorHover]
323-
: [pointConnectionColorHover];
317+
pointConnectionColorHover = isMultipleColors(pointConnectionColorHover)
318+
? [...pointConnectionColorHover]
319+
: [pointConnectionColorHover];
324320
pointConnectionColorHover = pointConnectionColorHover.map((color) =>
325321
toRgba(color, true)
326322
);
@@ -2027,7 +2023,8 @@ const createScatterplot = (initialProperties = {}) => {
20272023
return lassoInitiatorParentElement;
20282024
if (property === 'keyMap') return { ...keyMap };
20292025
if (property === 'mouseMode') return mouseMode;
2030-
if (property === 'opacity') return opacity;
2026+
if (property === 'opacity')
2027+
return opacity.length === 1 ? opacity[0] : opacity;
20312028
if (property === 'opacityBy') return opacityBy;
20322029
if (property === 'pointColor')
20332030
return pointColor.length === 1 ? pointColor[0] : pointColor;
@@ -2040,22 +2037,36 @@ const createScatterplot = (initialProperties = {}) => {
20402037
? pointColorHover[0]
20412038
: pointColorHover;
20422039
if (property === 'pointOutlineWidth') return pointOutlineWidth;
2043-
if (property === 'pointSize') return pointSize;
2040+
if (property === 'pointSize')
2041+
return pointSize.length === 1 ? pointSize[0] : pointSize;
20442042
if (property === 'pointSizeSelected') return pointSizeSelected;
20452043
if (property === 'pointSizeMouseDetection') return pointSizeMouseDetection;
20462044
if (property === 'showPointConnections') return showPointConnections;
2047-
if (property === 'pointConnectionColor') return pointConnectionColor;
2045+
if (property === 'pointConnectionColor')
2046+
return pointConnectionColor.length === 1
2047+
? pointConnectionColor[0]
2048+
: pointConnectionColor;
20482049
if (property === 'pointConnectionColorActive')
2049-
return pointConnectionColorActive;
2050+
return pointConnectionColorActive.length === 1
2051+
? pointConnectionColorActive[0]
2052+
: pointConnectionColorActive;
20502053
if (property === 'pointConnectionColorHover')
2051-
return pointConnectionColorHover;
2054+
return pointConnectionColorHover.length === 1
2055+
? pointConnectionColorHover[0]
2056+
: pointConnectionColorHover;
20522057
if (property === 'pointConnectionColorBy') return pointConnectionColorBy;
2053-
if (property === 'pointConnectionOpacity') return pointConnectionOpacity;
2058+
if (property === 'pointConnectionOpacity')
2059+
return pointConnectionOpacity.length === 1
2060+
? pointConnectionOpacity[0]
2061+
: pointConnectionOpacity;
20542062
if (property === 'pointConnectionOpacityBy')
20552063
return pointConnectionOpacityBy;
20562064
if (property === 'pointConnectionOpacityActive')
20572065
return pointConnectionOpacityActive;
2058-
if (property === 'pointConnectionSize') return pointConnectionSize;
2066+
if (property === 'pointConnectionSize')
2067+
return pointConnectionSize.length === 1
2068+
? pointConnectionSize[0]
2069+
: pointConnectionSize;
20592070
if (property === 'pointConnectionSizeActive')
20602071
return pointConnectionSizeActive;
20612072
if (property === 'pointConnectionSizeBy') return pointConnectionSizeBy;

src/utils.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,16 +299,17 @@ export const normNumArray = (a) =>
299299
* @return {array} Quadruple defining an RGBA color.
300300
*/
301301
export const toRgba = (color, isNormalize) => {
302-
if (isRgba(color))
302+
if (isRgba(color)) {
303+
const base = 255 ** !isNormalize;
303304
return isNormalize && !isNormFloatArray(color)
304305
? normNumArray(color)
305-
: color;
306+
: normNumArray(color).map((x) => x * base);
307+
}
306308

307-
if (isRgb(color))
308-
return [
309-
...(isNormalize ? normNumArray(color) : color),
310-
255 ** !isNormalize,
311-
];
309+
if (isRgb(color)) {
310+
const base = 255 ** !isNormalize;
311+
return [...normNumArray(color).map((x) => Math.round(x * base)), base];
312+
}
312313

313314
if (isHex(color)) return hexToRgba(color, isNormalize);
314315

0 commit comments

Comments
 (0)