-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 66-volcano-plot-tooltips
- Loading branch information
Showing
42 changed files
with
2,305 additions
and
851 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,9 @@ dist | |
# TernJS port file | ||
.tern-port | ||
|
||
# VSCode config files | ||
.vscode | ||
|
||
.editorconfig | ||
|
||
.pnp.* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
packages/libs/components/src/components/plotControls/PlotBubbleLegend.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import React from 'react'; | ||
import { range } from 'd3'; | ||
import _ from 'lodash'; | ||
|
||
// set props for custom legend function | ||
export interface PlotLegendBubbleProps { | ||
legendMax: number; | ||
valueToDiameterMapper: ((value: number) => number) | undefined; | ||
} | ||
|
||
// legend ellipsis function for legend title and legend items (from custom legend work) | ||
// const legendEllipsis = (label: string, ellipsisLength: number) => { | ||
// return (label || '').length > ellipsisLength | ||
// ? (label || '').substring(0, ellipsisLength) + '...' | ||
// : label; | ||
// }; | ||
|
||
export default function PlotBubbleLegend({ | ||
legendMax, | ||
valueToDiameterMapper, | ||
}: PlotLegendBubbleProps) { | ||
if (valueToDiameterMapper) { | ||
// Declare constants | ||
const tickFontSize = '0.8em'; | ||
// const legendTextSize = '1.0em'; | ||
const circleStrokeWidth = 3; | ||
const padding = 5; | ||
const numCircles = 3; | ||
|
||
// The largest circle's value will be the first number that's larger than | ||
// legendMax and has only one significant digit. Each smaller circle will | ||
// be half the size of the last (rounded and >= 1) | ||
const legendMaxLog10 = Math.floor(Math.log10(legendMax)); | ||
const largestCircleValue = | ||
legendMax <= 10 | ||
? legendMax | ||
: (Number(legendMax.toPrecision(1)[0]) + 1) * 10 ** legendMaxLog10; | ||
const circleValues = _.uniq( | ||
range(numCircles) | ||
.map((i) => Math.round(largestCircleValue / 2 ** i)) | ||
.filter((value) => value >= 1) | ||
); | ||
|
||
const largestCircleDiameter = valueToDiameterMapper(largestCircleValue); | ||
const largestCircleRadius = largestCircleDiameter / 2; | ||
|
||
const tickLength = largestCircleRadius + 5; | ||
|
||
return ( | ||
<svg | ||
width={largestCircleDiameter + (tickLength - largestCircleRadius) + 50} | ||
height={largestCircleDiameter + circleStrokeWidth * 2 + padding * 2} | ||
> | ||
{circleValues.map((value, i) => { | ||
const circleDiameter = valueToDiameterMapper(value); | ||
const circleRadius = circleDiameter / 2; | ||
const tickY = | ||
padding + | ||
largestCircleDiameter + | ||
circleStrokeWidth - | ||
circleDiameter; | ||
|
||
return ( | ||
<> | ||
<circle | ||
cx={padding + largestCircleRadius + circleStrokeWidth} | ||
cy={ | ||
padding + | ||
largestCircleDiameter + | ||
circleStrokeWidth - | ||
circleRadius | ||
} | ||
r={circleRadius} | ||
stroke="black" | ||
strokeWidth={circleStrokeWidth} | ||
fill="white" | ||
/> | ||
<g | ||
className="axisTick" | ||
overflow="visible" | ||
key={'gradientTick' + i} | ||
> | ||
<line | ||
x1={padding + largestCircleRadius + circleStrokeWidth + 1} | ||
x2={ | ||
padding + | ||
largestCircleRadius + | ||
circleStrokeWidth + | ||
tickLength + | ||
1 | ||
} | ||
y1={tickY} | ||
y2={tickY} | ||
stroke="black" | ||
strokeDasharray="2 2" | ||
strokeWidth={2} | ||
/> | ||
<text | ||
x={padding + largestCircleRadius + tickLength + 5} | ||
y={tickY} | ||
dominantBaseline="middle" | ||
fontSize={tickFontSize} | ||
> | ||
{value} | ||
</text> | ||
</g> | ||
</> | ||
); | ||
})} | ||
</svg> | ||
); | ||
} else { | ||
return null; | ||
} | ||
|
||
// for display, convert large value with k (e.g., 12345 -> 12k): return original value if less than a criterion | ||
// const sumLabel = props.markerLabel ?? String(fullPieValue); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.