Skip to content

add read-only prop for axis range #398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/components/plotControls/AxisRangeControl.tsx
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;
/** set read-only prop */
readOnly?: boolean;
}

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,
readOnly = false,
}: AxisRangeControlProps) {
const validator = useCallback(
(
Expand Down Expand Up @@ -76,6 +79,7 @@ export default function AxisRangeControl({
validator={validator}
// add disabled prop to disable input fields
disabled={disabled}
readOnly={readOnly}
/>
) : (
<NumberRangeInput
Expand All @@ -87,6 +91,7 @@ export default function AxisRangeControl({
validator={validator}
// add disabled prop to disable input fields
disabled={disabled}
readOnly={readOnly}
/>
)
) : null;
Expand Down
5 changes: 4 additions & 1 deletion src/components/widgets/NumberAndDateInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type BaseProps<M extends NumberOrDate> = {
displayRangeViolationWarnings?: boolean;
/** Disabled? Default is false */
disabled?: boolean;
/** set read-only prop */
readOnly?: boolean;
};

export type NumberInputProps = BaseProps<number>;
Expand Down Expand Up @@ -81,6 +83,7 @@ function BaseInput({
containerStyles,
displayRangeViolationWarnings = true,
disabled = false,
readOnly = false,
}: BaseInputProps) {
if (validator && (required || minValue != null || maxValue != null))
console.log(
Expand Down Expand Up @@ -197,7 +200,7 @@ function BaseInput({
)}
<div style={{ display: 'flex', flexDirection: 'row' }}>
<TextField
InputProps={{ classes }}
InputProps={{ classes, readOnly: readOnly }}
value={
localValue == null
? ''
Expand Down
7 changes: 7 additions & 0 deletions src/components/widgets/NumberAndDateRangeInputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export type BaseProps<M extends NumberOrDateRange> = {
clearButtonLabel?: string;
/** add disabled prop to disable input fields */
disabled?: boolean;
/** set read-only prop */
readOnly?: boolean;
};

export type NumberRangeInputProps = BaseProps<NumberRange>;
Expand Down Expand Up @@ -84,6 +86,7 @@ function BaseInput({
clearButtonLabel = 'Clear',
// add disabled prop to disable input fields
disabled = false,
readOnly = false,
}: BaseInputProps) {
if (validator && required)
console.log(
Expand Down Expand Up @@ -188,6 +191,7 @@ function BaseInput({
}}
// add disabled prop to disable input fields
disabled={disabled}
readOnly={readOnly}
/>
) : (
<DateInput
Expand All @@ -204,6 +208,7 @@ function BaseInput({
}}
// add disabled prop to disable input fields
disabled={disabled}
readOnly={readOnly}
/>
)}
<div style={{ display: 'flex', flexDirection: 'row' }}>
Expand Down Expand Up @@ -236,6 +241,7 @@ function BaseInput({
}}
// add disabled prop to disable input fields
disabled={disabled}
readOnly={readOnly}
/>
) : (
<DateInput
Expand All @@ -252,6 +258,7 @@ function BaseInput({
}}
// add disabled prop to disable input fields
disabled={disabled}
readOnly={readOnly}
/>
)}
{showClearButton && (
Expand Down
62 changes: 42 additions & 20 deletions src/stories/plots/LinePlot.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import React, { useEffect, useState } from 'react';
import React, { useState } from 'react';
import { Story, Meta } from '@storybook/react/types-6-0';
import LinePlot, { LinePlotProps } from '../../plots/LinePlot';
import { FacetedData, LinePlotData } from '../../types/plots';
import FacetedLinePlot from '../../plots/facetedPlots/FacetedLinePlot';
import AxisRangeControl from '../../components/plotControls/AxisRangeControl';
import {
NumberRange,
NumberOrDateRange,
NumberOrTimeDelta,
TimeDelta,
} from '../../types/general';
import { NumberOrDateRange } from '../../types/general';
import { Toggle } from '@veupathdb/coreui';

export default {
Expand Down Expand Up @@ -164,7 +159,7 @@ Faceted.args = {
},
};

//DKDK testing log scale
// testing log scale
const dataSetLog = {
series: [
{
Expand All @@ -181,20 +176,30 @@ const TemplateWithSelectedRangeControls: Story<Omit<LinePlotProps, 'data'>> = (
const [dependentAxisRange, setDependentAxisRange] = useState<
NumberOrDateRange | undefined
>({ min: 1, max: 80 });
const [dependentAxisLogScale, setDependentAxisLogScale] = useState<
boolean | undefined
>(false);
const [dependentAxisLogScale, setDependentAxisLogScale] = useState<boolean>(
false
);
const [readOnly, setReadOnly] = useState<boolean>(false);
const [disabled, setDisabled] = useState<boolean>(false);

const handleDependentAxisRangeChange = async (
newRange?: NumberOrDateRange
) => {
setDependentAxisRange(newRange);
};

const onDependentAxisLogScaleChange = async (value?: boolean) => {
const onDependentAxisLogScaleChange = async (value: boolean) => {
setDependentAxisLogScale(value);
};

const onReadOnlyChange = async (value: boolean) => {
setReadOnly(value);
};

const onDisabledChange = async (value: boolean) => {
setDisabled(value);
};

return (
<div style={{ display: 'flex', flexDirection: 'column' }}>
<LinePlot
Expand All @@ -203,25 +208,42 @@ const TemplateWithSelectedRangeControls: Story<Omit<LinePlotProps, 'data'>> = (
dependentAxisRange={dependentAxisRange}
dependentAxisLogScale={dependentAxisLogScale}
/>
<Toggle
label="Log scale (will exclude values &le; 0):"
value={dependentAxisLogScale ?? false}
onChange={onDependentAxisLogScaleChange}
styleOverrides={{ container: { marginLeft: '5em' } }}
/>
<div style={{ display: 'flex' }}>
<Toggle
label="Log scale (will exclude values &le; 0):"
value={dependentAxisLogScale ?? false}
onChange={onDependentAxisLogScaleChange}
styleOverrides={{ container: { marginLeft: '6.2em' } }}
/>
<Toggle
label="read-only"
value={readOnly}
onChange={onReadOnlyChange}
styleOverrides={{ container: { marginLeft: '5em' } }}
/>
<Toggle
label="disabled"
value={disabled}
onChange={onDisabledChange}
styleOverrides={{ container: { marginLeft: '5em' } }}
/>
</div>
<div style={{ height: 25 }} />
<AxisRangeControl
label="Y-axis range control"
range={dependentAxisRange}
onRangeChange={handleDependentAxisRangeChange}
containerStyles={{ marginLeft: '5em' }}
// set readOnly and disabled with toggle
readOnly={readOnly}
disabled={disabled}
/>
</div>
);
};

export const LogScale = TemplateWithSelectedRangeControls.bind({});
LogScale.args = {
export const LogscaleAndReadonly = TemplateWithSelectedRangeControls.bind({});
LogscaleAndReadonly.args = {
containerStyles: {
height: '450px',
width: '750px',
Expand Down