Skip to content
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

New parameters #14

Open
wants to merge 7 commits into
base: dashboard
Choose a base branch
from
Open
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
170 changes: 140 additions & 30 deletions packages/dashboard/src/components/Configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const parameterFormItem = (
childLevel,
layoutParameters,
onChangeLayoutParams,
updateLayoutParameters
updateLayoutParameters,
fatherParam,//新增,存储的有两类:①该项父module的构造函数new出来的对象;②null
) => {
if (params.type === "switch") {
//console.log('key:', key, 'layoutParameters:', layoutParameters)
if (params.type === "BOOL") {
return (
<div key={key}>
<ConfigContainer key={key} childLevel={childLevel}>
<ConfigContainer key={key} childLevel={childLevel} fatherParam={fatherParam} >
<span>{key}: </span>
<Switch
defaultChecked={
Expand All @@ -28,55 +28,81 @@ const parameterFormItem = (
}
size="small"
onChange={(value) => {
onChangeLayoutParams({ [key]: value });
console.log(layoutParameters[key]);
}}
if (fatherParam != null) {
fatherParam[key] = value;
}
else
onChangeLayoutParams({ [key]: value });
}
}
>
{" "}
</Switch>
</ConfigContainer>
{params.children && layoutParameters[key] === true
? Object.entries(params.children).map(([child_key, child_value]) => {
return parameterFormItem(
child_key,
child_value,
childLevel + 1,
layoutParameters,
onChangeLayoutParams,
updateLayoutParameters
);
})
: null}
</div>
);
} else if (params.type === "float" || params.type === "integer") {
} else if (params.type === "DOUBLE") {
return (
<ConfigContainer key={key} childLevel={childLevel} fatherParam={fatherParam} >
<span>{key}: </span>
<InputSlider
step={0.0001}
//step={1}
size="small"
defaultValue={params.default}
min={params.range[0] == "-Infinity" ? (params.default==0?-100:(-1)*Math.abs(params.default) * 5) : params.range[0]}
max={params.range[1] == "Infinity" ? (params.default==0?100:Math.abs(params.default) * 5): params.range[1]}
// min={0}
// max={100}
onChange={(value) => {
if (fatherParam != null) {
fatherParam[key] = value;
}
else
onChangeLayoutParams({ [key]: value });
}}
/>
</ConfigContainer>
);
} else if (params.type === "INT") {
return (
<ConfigContainer key={key} childLevel={childLevel}>
<ConfigContainer key={key} childLevel={childLevel} fatherParam={fatherParam} >
<span>{key}: </span>
<InputSlider
step={1}
size="small"
defaultValue={params.default}
min={params.min}
max={params.max}
min={params.range[0] == "-Infinity" ? (params.default==0?-100:(-1)*Math.abs(params.default) * 5) : params.range[0]}
max={params.range[1] == "Infinity" ? (params.default==0?100:Math.abs(params.default) * 5): params.range[1]}
// min={0}
// max={100}
onChange={(value) => {
onChangeLayoutParams({ [key]: value });
if (fatherParam != null) {
fatherParam[key] = value;
console.log(fatherParam);
}
else
onChangeLayoutParams({ [key]: value });
}}
/>
</ConfigContainer>
);
} else if (params.type === "select") {
} else if (params.type === "CATEGORICAL") {
return (
<ConfigContainer key={key} childLevel={childLevel}>
<ConfigContainer key={key} childLevel={childLevel} fatherParam={fatherParam} >
<span>{key}: </span>
<Select
size={"small"}
defaultValue={params.default}
onChange={(value) => {
onChangeLayoutParams({ [key]: value });
if (fatherParam != null) {
fatherParam[key] = value;
}
else
onChangeLayoutParams({ [key]: value });
}}
>
{params.options.map((option) => {
{params.range.map((option) => {
return (
<Select.Option key={option} value={option}>
{option}
Expand All @@ -86,6 +112,86 @@ const parameterFormItem = (
</Select>
</ConfigContainer>
);
} else if (params.type === "MODULE") {
return (
<div key={key}>
<ConfigContainer key={key} childLevel={childLevel} fatherParam={fatherParam} >
<span>{key}: </span>
{layoutParameters[key + "Module"] == true ?
<Select
size={"small"}
defaultValue={() => {
return params.default.name;
}}
onChange={(value) => {
if (fatherParam != null) {
fatherParam[key] = new params.range[value].constructor();
onChangeLayoutParams({});
console.log(fatherParam[key].configs().value);
}
else {
console.log(params.range[value]);
onChangeLayoutParams({ [key]: new params.range[value].constructor() });
}
}}
>
{params.range.map((option, index) => {
return (
<Select.Option key={option.name} value={index}>
{option.name}
</Select.Option>
);
})}
</Select>
: <Switch
defaultChecked={false}
size="small"
onChange={(value) => {
if (fatherParam != null) {
fatherParam[key] = new params.default.constructor();
onChangeLayoutParams({ [key + "Module"]: value });
}
else {
onChangeLayoutParams({ [key + "Module"]: value, [key]: new params.default.constructor() });
}
}
}
>
{""};
</Switch>
}

</ConfigContainer>
{fatherParam == null && layoutParameters[key] !== undefined && layoutParameters[key + "Module"] == true
? Object.entries(layoutParameters[key].configs().value.parameters).map(([child_key, child_value]) => {
return parameterFormItem(
child_key,
child_value,
childLevel + 1,
layoutParameters,
onChangeLayoutParams,
updateLayoutParameters,
fatherParam == null ? layoutParameters[key] : fatherParam[key]
);
})
: null
}
{fatherParam != null && layoutParameters[key + "Module"] == true
? Object.entries(fatherParam[key].configs().value.parameters).map(([child_key, child_value]) => {
return parameterFormItem(
child_key,
child_value,
childLevel + 1,
layoutParameters,
onChangeLayoutParams,
updateLayoutParameters,
fatherParam[key]
);
})
: null
}
</div>
);
}
};

Expand Down Expand Up @@ -130,12 +236,13 @@ function Configs({
}) {
const onChangeLayoutParams = (newParam) => {
updateLayoutParameters({ ...layoutParameters, ...newParam });
console.log(layoutParameters);
};

return (
<div
style={{
width: 350,
width: 450,//350
backgroundColor: "#f8f8f8",
padding: "10px 5px 10px 5px",
borderRadius: 5,
Expand All @@ -147,9 +254,11 @@ function Configs({
<Select
defaultValue={LAYOUT_CONFIG.layout.default}
value={layoutType}
style={{width:"250px"}}
size={"small"}
onChange={(val) => {
updateLayout(val);
updateLayoutParameters({});
}}
>
{LAYOUT_CONFIG.layout.options.map((option) => {
Expand Down Expand Up @@ -239,7 +348,8 @@ function Configs({
1,
layoutParameters,
onChangeLayoutParams,
updateLayoutParameters
updateLayoutParameters,
null,
);
}
)}
Expand Down
21 changes: 18 additions & 3 deletions packages/dashboard/src/components/MainCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,25 @@ import * as ogdf from 'ogdfjs'
import React, { useEffect, useRef } from 'react'

const LAYOUT_MAP = {
DavidsonHarel:ogdf.layouts.energybased.DavidsonHarelLayout,
fm3: ogdf.layouts.energybased.FMMMLayout,
sugi: ogdf.layouts.layered.SugiyamaLayout
}
FastMultipoleEmbedder:ogdf.layouts.energybased.FastMultipoleEmbedder,
FastMultipoleMultilevelEmbedder:ogdf.layouts.energybased.FastMultipoleMultilevelEmbedder,
gem: ogdf.layouts.energybased.GEMLayout,
NodeRespecter: ogdf.layouts.energybased.NodeRespecterLayout,
PivotMDS: ogdf.layouts.energybased.PivotMDS,
SpringEmbedderGridVariant:ogdf.layouts.energybased.SpringEmbedderGridVariant,
SpringEmbedderKK:ogdf.layouts.energybased.SpringEmbedderKK,
StressMinimization:ogdf.layouts.energybased.StressMinimization,
TutteLayout:ogdf.layouts.energybased.TutteLayout,

sugi: ogdf.layouts.layered.SugiyamaLayout,

Planarization:ogdf.layouts.planarity.PlanarizationLayout,
PlanarizationGrid:ogdf.layouts.planarity.PlanarizationGridLayout
}

function MainCanvas({ layoutType, data, layoutParameters, changeFlag }) {
function MainCanvas({ layoutType, data, layoutParameters, changeFlag}) {
const ref = useRef(null)
// console.log('layoutParameters:', layoutParameters)
useEffect(() => {
Expand Down Expand Up @@ -36,6 +50,7 @@ function MainCanvas({ layoutType, data, layoutParameters, changeFlag }) {
graph: data,
parameters: layoutParameters
})
console.log(layout.configs());
layout.run().then((graph) => {
// netv.data(graph)
netv.data(
Expand Down
Loading