Merge remote-tracking branch 'origin/develop' into log-score-attempt
This commit is contained in:
commit
13804dda7a
|
@ -18,27 +18,45 @@ type DistributionChartProps = {
|
||||||
distribution: Distribution;
|
distribution: Distribution;
|
||||||
width?: number;
|
width?: number;
|
||||||
height: number;
|
height: number;
|
||||||
|
/** Whether to show the user graph controls (scale etc) */
|
||||||
|
showControls?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const DistributionChart: React.FC<DistributionChartProps> = ({
|
export const DistributionChart: React.FC<DistributionChartProps> = ({
|
||||||
distribution,
|
distribution,
|
||||||
height,
|
height,
|
||||||
width,
|
width,
|
||||||
|
showControls = false,
|
||||||
}: DistributionChartProps) => {
|
}: DistributionChartProps) => {
|
||||||
let [isLogX, setLogX] = React.useState(false);
|
let [isLogX, setLogX] = React.useState(false);
|
||||||
let [isExpY, setExpY] = React.useState(false);
|
let [isExpY, setExpY] = React.useState(false);
|
||||||
let shape = distribution.pointSet();
|
let shape = distribution.pointSet();
|
||||||
const [sized, _] = useSize((size) => {
|
const [sized, _] = useSize((size) => {
|
||||||
var disableLog = false;
|
|
||||||
if (shape.tag === "Ok") {
|
if (shape.tag === "Ok") {
|
||||||
let massBelow0 =
|
let massBelow0 =
|
||||||
shape.value.continuous.some((x) => x.x <= 0) ||
|
shape.value.continuous.some((x) => x.x <= 0) ||
|
||||||
shape.value.discrete.some((x) => x.x <= 0);
|
shape.value.discrete.some((x) => x.x <= 0);
|
||||||
if (massBelow0) {
|
|
||||||
disableLog = true;
|
|
||||||
}
|
|
||||||
let spec = buildVegaSpec(isLogX, isExpY);
|
let spec = buildVegaSpec(isLogX, isExpY);
|
||||||
let widthProp = width ? width - 20 : size.width - 10;
|
let widthProp = width ? width - 20 : size.width - 10;
|
||||||
|
|
||||||
|
// Check whether we should disable the checkbox
|
||||||
|
var logCheckbox = (
|
||||||
|
<CheckBox label="Log X scale" value={isLogX} onChange={setLogX} />
|
||||||
|
);
|
||||||
|
if (massBelow0) {
|
||||||
|
logCheckbox = (
|
||||||
|
<CheckBox
|
||||||
|
label="Log X scale"
|
||||||
|
value={isLogX}
|
||||||
|
onChange={setLogX}
|
||||||
|
disabled={true}
|
||||||
|
tooltip={
|
||||||
|
"Your distribution has mass lower than or equal to 0. Log only works on strictly positive values."
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
var result = (
|
var result = (
|
||||||
<div>
|
<div>
|
||||||
<Vega
|
<Vega
|
||||||
|
@ -48,6 +66,12 @@ export const DistributionChart: React.FC<DistributionChartProps> = ({
|
||||||
height={height}
|
height={height}
|
||||||
actions={false}
|
actions={false}
|
||||||
/>
|
/>
|
||||||
|
{showControls && (
|
||||||
|
<div>
|
||||||
|
{logCheckbox}
|
||||||
|
<CheckBox label="Exp Y scale" value={isExpY} onChange={setExpY} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -57,27 +81,8 @@ export const DistributionChart: React.FC<DistributionChartProps> = ({
|
||||||
</ErrorBox>
|
</ErrorBox>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return (
|
|
||||||
<>
|
return result;
|
||||||
{result}
|
|
||||||
<div>
|
|
||||||
{disableLog ? (
|
|
||||||
<CheckBox
|
|
||||||
label="Log X scale"
|
|
||||||
value={isLogX}
|
|
||||||
onChange={setLogX}
|
|
||||||
disabled={true}
|
|
||||||
tooltip={
|
|
||||||
"Your distribution has mass lower than or equal to 0. Log only works on strictly positive values."
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<CheckBox label="Log X scale" value={isLogX} onChange={setLogX} />
|
|
||||||
)}
|
|
||||||
<CheckBox label="Exp Y scale" value={isExpY} onChange={setExpY} />
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
return sized;
|
return sized;
|
||||||
};
|
};
|
||||||
|
|
|
@ -67,6 +67,8 @@ export interface SquiggleItemProps {
|
||||||
height: number;
|
height: number;
|
||||||
/** Whether to show type information */
|
/** Whether to show type information */
|
||||||
showTypes?: boolean;
|
showTypes?: boolean;
|
||||||
|
/** Whether to show users graph controls (scale etc) */
|
||||||
|
showControls?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SquiggleItem: React.FC<SquiggleItemProps> = ({
|
const SquiggleItem: React.FC<SquiggleItemProps> = ({
|
||||||
|
@ -74,6 +76,7 @@ const SquiggleItem: React.FC<SquiggleItemProps> = ({
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
showTypes = false,
|
showTypes = false,
|
||||||
|
showControls = false,
|
||||||
}: SquiggleItemProps) => {
|
}: SquiggleItemProps) => {
|
||||||
switch (expression.tag) {
|
switch (expression.tag) {
|
||||||
case "number":
|
case "number":
|
||||||
|
@ -100,6 +103,7 @@ const SquiggleItem: React.FC<SquiggleItemProps> = ({
|
||||||
distribution={expression.value}
|
distribution={expression.value}
|
||||||
height={height}
|
height={height}
|
||||||
width={width}
|
width={width}
|
||||||
|
showControls={showControls}
|
||||||
/>
|
/>
|
||||||
</VariableBox>
|
</VariableBox>
|
||||||
);
|
);
|
||||||
|
@ -185,6 +189,8 @@ export interface SquiggleChartProps {
|
||||||
jsImports?: jsImports;
|
jsImports?: jsImports;
|
||||||
/** Whether to show type information about returns, default false */
|
/** Whether to show type information about returns, default false */
|
||||||
showTypes?: boolean;
|
showTypes?: boolean;
|
||||||
|
/** Whether to show graph controls (scale etc)*/
|
||||||
|
showControls?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ChartWrapper = styled.div`
|
const ChartWrapper = styled.div`
|
||||||
|
@ -203,6 +209,7 @@ export const SquiggleChart: React.FC<SquiggleChartProps> = ({
|
||||||
jsImports = defaultImports,
|
jsImports = defaultImports,
|
||||||
width,
|
width,
|
||||||
showTypes = false,
|
showTypes = false,
|
||||||
|
showControls = false,
|
||||||
}: SquiggleChartProps) => {
|
}: SquiggleChartProps) => {
|
||||||
let samplingInputs: samplingParams = {
|
let samplingInputs: samplingParams = {
|
||||||
sampleCount: sampleCount,
|
sampleCount: sampleCount,
|
||||||
|
@ -224,6 +231,7 @@ export const SquiggleChart: React.FC<SquiggleChartProps> = ({
|
||||||
width={width}
|
width={width}
|
||||||
height={height}
|
height={height}
|
||||||
showTypes={showTypes}
|
showTypes={showTypes}
|
||||||
|
showControls={showControls}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -42,6 +42,8 @@ export interface SquiggleEditorProps {
|
||||||
jsImports?: jsImports;
|
jsImports?: jsImports;
|
||||||
/** Whether to show detail about types of the returns, default false */
|
/** Whether to show detail about types of the returns, default false */
|
||||||
showTypes?: boolean;
|
showTypes?: boolean;
|
||||||
|
/** Whether to give users access to graph controls */
|
||||||
|
showControls: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Input = styled.div`
|
const Input = styled.div`
|
||||||
|
@ -64,6 +66,7 @@ export let SquiggleEditor: React.FC<SquiggleEditorProps> = ({
|
||||||
bindings = defaultBindings,
|
bindings = defaultBindings,
|
||||||
jsImports = defaultImports,
|
jsImports = defaultImports,
|
||||||
showTypes = false,
|
showTypes = false,
|
||||||
|
showControls = false,
|
||||||
}: SquiggleEditorProps) => {
|
}: SquiggleEditorProps) => {
|
||||||
let [expression, setExpression] = React.useState(initialSquiggleString);
|
let [expression, setExpression] = React.useState(initialSquiggleString);
|
||||||
return (
|
return (
|
||||||
|
@ -91,6 +94,7 @@ export let SquiggleEditor: React.FC<SquiggleEditorProps> = ({
|
||||||
bindings={bindings}
|
bindings={bindings}
|
||||||
jsImports={jsImports}
|
jsImports={jsImports}
|
||||||
showTypes={showTypes}
|
showTypes={showTypes}
|
||||||
|
showControls={showControls}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -149,6 +153,8 @@ export interface SquigglePartialProps {
|
||||||
bindings?: bindings;
|
bindings?: bindings;
|
||||||
/** Variables imported from js */
|
/** Variables imported from js */
|
||||||
jsImports?: jsImports;
|
jsImports?: jsImports;
|
||||||
|
/** Whether to give users access to graph controls */
|
||||||
|
showControls?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export let SquigglePartial: React.FC<SquigglePartialProps> = ({
|
export let SquigglePartial: React.FC<SquigglePartialProps> = ({
|
||||||
|
|
|
@ -43,6 +43,8 @@ function FieldFloat(Props: FieldFloatProps) {
|
||||||
interface Props {
|
interface Props {
|
||||||
initialSquiggleString?: string;
|
initialSquiggleString?: string;
|
||||||
height?: number;
|
height?: number;
|
||||||
|
showTypes?: boolean;
|
||||||
|
showControls?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Props2 {
|
interface Props2 {
|
||||||
|
@ -55,10 +57,6 @@ const ShowBox = styled.div<Props2>`
|
||||||
height: ${(props) => props.height};
|
height: ${(props) => props.height};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const MyComponent = styled.div`
|
|
||||||
color: ${(props) => props.theme.colors.main};
|
|
||||||
`;
|
|
||||||
|
|
||||||
interface TitleProps {
|
interface TitleProps {
|
||||||
readonly maxHeight: number;
|
readonly maxHeight: number;
|
||||||
}
|
}
|
||||||
|
@ -81,6 +79,8 @@ const Col = styled.div``;
|
||||||
let SquigglePlayground: FC<Props> = ({
|
let SquigglePlayground: FC<Props> = ({
|
||||||
initialSquiggleString = "",
|
initialSquiggleString = "",
|
||||||
height = 300,
|
height = 300,
|
||||||
|
showTypes = false,
|
||||||
|
showControls = false,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
let [squiggleString, setSquiggleString] = useState(initialSquiggleString);
|
let [squiggleString, setSquiggleString] = useState(initialSquiggleString);
|
||||||
let [sampleCount, setSampleCount] = useState(1000);
|
let [sampleCount, setSampleCount] = useState(1000);
|
||||||
|
@ -112,6 +112,8 @@ let SquigglePlayground: FC<Props> = ({
|
||||||
diagramCount={diagramCount}
|
diagramCount={diagramCount}
|
||||||
pointDistLength={pointDistLength}
|
pointDistLength={pointDistLength}
|
||||||
height={150}
|
height={150}
|
||||||
|
showTypes={showTypes}
|
||||||
|
showControls={showControls}
|
||||||
/>
|
/>
|
||||||
</Display>
|
</Display>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user