Skip to content

Commit

Permalink
make label optional for scatterplot data
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafasaifee42 committed Jul 25, 2024
1 parent 8589d2e commit 5c0de64
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@undp-data/undp-visualization-library",
"version": "0.0.28",
"version": "0.0.29",
"main": "./dist/index.umd.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
15 changes: 8 additions & 7 deletions src/Components/Graphs/ScatterPlot/Graph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export function Graph(props: Props) {
left: leftMargin,
right: rightMargin,
};
const dataWithId = data.map((d, i) => ({ ...d, id: `${i}` }));
const graphWidth = width - margin.left - margin.right;
const graphHeight = height - margin.top - margin.bottom;
const radiusScale =
Expand All @@ -101,10 +102,10 @@ export function Graph(props: Props) {
.nice()
: undefined;
const dataOrdered =
data.filter(d => d.radius !== undefined).length === 0
? data
dataWithId.filter(d => d.radius !== undefined).length === 0
? dataWithId
: orderBy(
data.filter(d => d.radius !== undefined),
dataWithId.filter(d => d.radius !== undefined),
'radius',
'desc',
);
Expand Down Expand Up @@ -350,11 +351,11 @@ export function Graph(props: Props) {
: 0.3
: 0.3
: mouseOverData
? mouseOverData.label === d.label
? mouseOverData.id === d.id
? 1
: 0.3
: highlightedDataPoints.length !== 0
? highlightedDataPoints.indexOf(d.label) !== -1
? highlightedDataPoints.indexOf(d.label || '') !== -1
? 1
: 0.3
: 1
Expand All @@ -381,7 +382,7 @@ export function Graph(props: Props) {
}}
fillOpacity={0.6}
/>
{showLabels ? (
{showLabels && d.label ? (
<text
fontSize={10}
style={{
Expand All @@ -402,7 +403,7 @@ export function Graph(props: Props) {
>
{d.label}
</text>
) : highlightedDataPoints.length !== 0 ? (
) : highlightedDataPoints.length !== 0 && d.label ? (
highlightedDataPoints.indexOf(d.label) !== -1 ? (
<text
fontSize={10}
Expand Down
6 changes: 5 additions & 1 deletion src/Components/Graphs/ScatterPlot/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,11 @@ export function ScatterPlot(props: Props) {
highlightAreaSettings={
highlightAreaSettings || [null, null, null, null]
}
highlightedDataPoints={highlightedDataPoints || []}
highlightedDataPoints={
data.filter(el => el.label).length === 0
? []
: highlightedDataPoints || []
}
highlightAreaColor={highlightAreaColor || 'var(--gray-300)'}
selectedColor={selectedColor}
pointRadiusMaxValue={pointRadiusMaxValue}
Expand Down
2 changes: 1 addition & 1 deletion src/Types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export interface ScatterPlotDataType {
y: number;
radius?: number;
color?: string;
label: string;
label?: string;
data?: object;
}

Expand Down

0 comments on commit 5c0de64

Please sign in to comment.