Skip to content

Commit

Permalink
Bring variableName to sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
OAGr committed Jan 10, 2024
1 parent 157abc4 commit 829d58e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ export const ListView: FC = () => {
<div className="sticky top-4 bg-slate-50 px-2 py-4 ml-4 rounded-sm border-gray-200 border">
<ItemSideBar
model={model}
variableName={model.variableName}
numeratorItem={sidebarItems[0]}
denominatorItem={sidebarItems[1]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ const TableRow: React.FC<TableRowProps> = ({ label, number }) => (
let buildurl = (
model: ModelEvaluator,
numeratorItem: Item,
denominatorItem: Item
denominatorItem: Item,
variableName: string
) => {
const toVarName = (id: string) => id.replace(/-/g, "_");
const numeratorItemName = toVarName(numeratorItem.id);
const denominatorItemName = toVarName(denominatorItem.id);
return `${model.modelCode}
// ------- AUTOGENERATED CODE -------
dists = fn("${numeratorItem.id}", "${denominatorItem.id}")
dists = ${variableName}("${numeratorItem.id}", "${denominatorItem.id}")
value_${numeratorItemName} = Dist(dists[0])
value_${denominatorItemName} = Dist(dists[1])
valueRatio = value_${numeratorItemName} / value_${denominatorItemName}
Expand Down Expand Up @@ -84,9 +85,7 @@ debug = [
ratio = Plot.dist(
{
dist: valueRatio,
xScale: Scale.symlog(
{ tickFormatObj }
),
xScale: Scale.symlog(tickFormatObj),
yScale: Scale.symlog(tickFormatObj),
showSummary: false,
}
Expand All @@ -100,19 +99,26 @@ type Props = {
model: ModelEvaluator;
numeratorItem: Item;
denominatorItem: Item;
variableName: string;
};

export const ItemSideBar: FC<Props> = ({
model,
numeratorItem,
variableName,
denominatorItem,
}) => {
const result = model.compare(numeratorItem.id, denominatorItem.id);
if (!result.ok) {
return <div>Result not found</div>;
} else {
let item = result.value;
const squggleCode = buildurl(model, numeratorItem, denominatorItem);
const squggleCode = buildurl(
model,
numeratorItem,
denominatorItem,
variableName
);

// It would be better to not load SquiggleChart, but rather, a lower-level compontent. That can be refactored later.
return (
Expand Down
8 changes: 7 additions & 1 deletion packages/hub/src/relative-values/values/ModelEvaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function buildRelativeValue({
export class ModelEvaluator {
private constructor(
public modelCode: string,
public variableName: string,
private fn: SqLambda,
private cache?: RelativeValuesCacheRecord
) {}
Expand Down Expand Up @@ -154,7 +155,12 @@ export class ModelEvaluator {

return {
ok: true,
value: new ModelEvaluator(modelCode, result.value.value, cacheRecord),
value: new ModelEvaluator(
modelCode,
variableName,
result.value.value,
cacheRecord
),
};
}

Expand Down

0 comments on commit 829d58e

Please sign in to comment.