Skip to content

Commit

Permalink
Merge branch 'main' into map-collection-variable-map-type
Browse files Browse the repository at this point in the history
  • Loading branch information
dmfalke committed Aug 18, 2023
2 parents 85b4baf + b068ccb commit 8d9f506
Show file tree
Hide file tree
Showing 35 changed files with 1,206 additions and 222 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ jobs:
- uses: nrwl/nx-set-shas@v3
- run: yarn
- run: yarn nx affected --target=build-npm-modules --parallel=3
- run: yarn nx affected --target=compile:check
2 changes: 1 addition & 1 deletion packages/libs/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@visx/text": "^1.3.0",
"@visx/tooltip": "^1.3.0",
"@visx/visx": "^1.1.0",
"@visx/xychart": "^3.1.0",
"@visx/xychart": "https://github.com/jernestmyers/visx.git#visx-xychart",
"bootstrap": "^4.5.2",
"color-math": "^1.1.3",
"d3": "^7.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface AxisRangeControlProps
disabled?: boolean;
/** is this for a log scale axis? If so, we'll validate the min value to be > 0 */
logScale?: boolean;
/** specify step for increment/decrement buttons in MUI number inputs; MUI's default is 1 */
step?: number;
}

export default function AxisRangeControl({
Expand All @@ -33,6 +35,7 @@ export default function AxisRangeControl({
// add disabled prop to disable input fields: default is false
disabled = false,
logScale = false,
step = undefined,
}: AxisRangeControlProps) {
const validator = useCallback(
(
Expand Down Expand Up @@ -87,6 +90,7 @@ export default function AxisRangeControl({
validator={validator}
// add disabled prop to disable input fields
disabled={disabled}
step={step}
/>
)
) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { NumberInput, DateInput } from './NumberAndDateInputs';
import Button from './Button';
import Notification from './Notification';
import { NumberRange, DateRange, NumberOrDateRange } from '../../types/general';
import { propTypes } from 'react-bootstrap/esm/Image';

export type BaseProps<M extends NumberOrDateRange> = {
/** Externally controlled range. */
Expand Down Expand Up @@ -44,7 +45,7 @@ export type BaseProps<M extends NumberOrDateRange> = {
disabled?: boolean;
};

export type NumberRangeInputProps = BaseProps<NumberRange>;
export type NumberRangeInputProps = BaseProps<NumberRange> & { step?: number };

export function NumberRangeInput(props: NumberRangeInputProps) {
return <BaseInput {...props} valueType="number" />;
Expand Down Expand Up @@ -85,6 +86,7 @@ function BaseInput({
clearButtonLabel = 'Clear',
// add disabled prop to disable input fields
disabled = false,
...props
}: BaseInputProps) {
if (validator && required)
console.log(
Expand Down Expand Up @@ -161,6 +163,7 @@ function BaseInput({
]);

const { min, max } = localRange ?? {};
const step = 'step' in props ? props.step : undefined;

return (
<div style={{ ...containerStyles }}>
Expand Down Expand Up @@ -188,6 +191,7 @@ function BaseInput({
}}
// add disabled prop to disable input fields
disabled={disabled}
step={step}
/>
) : (
<DateInput
Expand Down Expand Up @@ -236,6 +240,7 @@ function BaseInput({
}}
// add disabled prop to disable input fields
disabled={disabled}
step={step}
/>
) : (
<DateInput
Expand Down
11 changes: 11 additions & 0 deletions packages/libs/components/src/components/widgets/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ import { DARK_GRAY, LIGHT_GRAY, MEDIUM_GRAY } from '../../constants/colors';
import { debounce } from 'lodash';
import { NumberOrDate } from '../../types/general';

// a color spec shared among plot components that implements the track gradient
export const plotsSliderOpacityGradientColorSpec: SliderWidgetProps['colorSpec'] =
{
type: 'gradient',
tooltip: '#aaa',
knobColor: '#aaa',
// normal slider color: e.g., from 0 to 1
trackGradientStart: '#fff',
trackGradientEnd: '#000',
};

export type SliderWidgetProps = {
/** The minimum value of the slider. */
minimum?: number;
Expand Down
106 changes: 106 additions & 0 deletions packages/libs/components/src/plots/Network.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { DefaultNode } from '@visx/network';
import { Text } from '@visx/text';
import { LinkData, NodeData } from '../types/plots/network';

interface NodeWithLabelProps {
/** Network node */
node: NodeData;
/** Function to run when a user clicks either the node or label */
onClick?: () => void;
/** Should the label be drawn to the left or right of the node? */
labelPosition?: 'right' | 'left';
/** Font size for the label. Ex. "1em" */
fontSize?: string;
/** Font weight for the label */
fontWeight?: number;
/** Color for the label */
labelColor?: string;
}

// NodeWithLabel draws one node and an optional label for the node. Both the node and
// label can be styled.
export function NodeWithLabel(props: NodeWithLabelProps) {
const DEFAULT_NODE_RADIUS = 4;
const DEFAULT_NODE_COLOR = '#aaa';
const DEFAULT_STROKE_WIDTH = 1;

const {
node,
onClick,
labelPosition = 'right',
fontSize = '1em',
fontWeight = 200,
labelColor = '#000',
} = props;

const { color, label, stroke, strokeWidth } = node;

const nodeRadius = node.r ?? DEFAULT_NODE_RADIUS;

// Calculate where the label should be posiitoned based on
// total size of the node.
let textXOffset: number;
let textAnchor: 'start' | 'end';

if (labelPosition === 'right') {
textXOffset = 4 + nodeRadius;
if (strokeWidth) textXOffset = textXOffset + strokeWidth;
textAnchor = 'start';
} else {
textXOffset = -4 - nodeRadius;
if (strokeWidth) textXOffset = textXOffset - strokeWidth;
textAnchor = 'end';
}

return (
<>
<DefaultNode
r={nodeRadius}
fill={color ?? DEFAULT_NODE_COLOR}
onClick={onClick}
stroke={stroke}
strokeWidth={strokeWidth ?? DEFAULT_STROKE_WIDTH}
/>
{/* Note that Text becomes a tspan */}
<Text
x={textXOffset}
textAnchor={textAnchor}
fontSize={fontSize}
verticalAnchor="middle"
onClick={onClick}
fontWeight={fontWeight}
fill={labelColor}
style={{ cursor: 'pointer' }}
>
{label}
</Text>
</>
);
}

export interface LinkProps {
link: LinkData;
// onClick?: () => void; To add in the future, maybe also some hover action
}

// Link component draws a linear edge between two nodes.
// Eventually can grow into drawing directed edges (edges with arrows) when the time comes.
export function Link(props: LinkProps) {
const DEFAULT_LINK_WIDTH = 1;
const DEFAULT_COLOR = '#222';
const DEFAULT_OPACITY = 0.95;

const { link } = props;

return (
<line
x1={link.source.x}
y1={link.source.y}
x2={link.target.x}
y2={link.target.y}
strokeWidth={link.strokeWidth ?? DEFAULT_LINK_WIDTH}
stroke={link.color ?? DEFAULT_COLOR}
strokeOpacity={link.opacity ?? DEFAULT_OPACITY}
/>
);
}
28 changes: 28 additions & 0 deletions packages/libs/components/src/plots/VolcanoPlot.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.visx-tooltip {
z-index: 1;
}

.VolcanoPlotTooltip {
padding: 5px 10px;
font-size: 12px;
border-radius: 2px;
box-shadow: 2px 2px 7px rgba(0, 0, 0, 0.5);
}

.VolcanoPlotTooltip > .pseudo-hr {
margin: 5px auto;
height: 1px;
width: 100%;
}

.VolcanoPlotTooltip > ul {
margin: 0;
padding: 0;
list-style: none;
line-height: 1.5em;
font-weight: normal;
}

.VolcanoPlotTooltip > ul > li > span {
font-weight: bold;
}
Loading

0 comments on commit 8d9f506

Please sign in to comment.