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

Исправлен перенос на ts. Логика дерева отделена от изображения #4

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
94 changes: 76 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@types/react-dom": "16.8.2",
"d3": "^5.9.2",
"graphlabs.core.notifier": "0.0.29",
"graphlabs.core.template": "^0.1.41",
"graphlabs.core.template": "^0.1.42",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-scripts": "2.1.8",
Expand Down
26 changes: 12 additions & 14 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,44 @@ import {GraphVisualizer, TaskTemplate, TaskToolbar, ToolButtonList} from 'graphl
import Tree from "./tree";

class App extends TaskTemplate {
private readonly tree: Tree;
private tree?: Tree;

constructor() {
super({});
this.tree = new Tree();
}

public calculate() {
console.log("calculate (App.js)");
let res = 10;
return {success: res === 0, fee: res};
public componentDidMount(): void {
this.tree = new Tree();
}

// public calculate() {
// let res = 10;
// return {success: res === 0, fee: res};
// }

public task() {
console.log("task (App.js)");
return () => <GraphVisualizer />;
}

public getAres() {
public getArea() {
return (
() => <div id={'my-canvas'}></div>
() => <div id={'my-canvas'}/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Внести идентификатор my-canvas внутрь компонента, отрисовывающего дерево.
Предлагаю сделать ещё один класс-компонент, в котором в render будет возвращаться этот контейнер с внутренним идентификатором, плюс там же будет код который с помощью d3 отвечает за отрисовку.
И уже он будет использовать твой класс Tree.ts для работы с логикой, с моделью графа, который рисуется.

)
}

public getTaskToolbar() {
console.log("getTaskToolbar (App.js): возвращаем панель инструментов, начало");
TaskToolbar.prototype.getButtonList = () => {
ToolButtonList.prototype.help = () => `В данном задании вы должны построить дерево, посадить сына и срубить дом`;
ToolButtonList.prototype.toolButtons = {
'+': () => {
if (this.tree) this.tree.addLeaf()
if (this.tree) { this.tree.addLeaf() }
},
'-': () => {
if (this.tree) this.tree.removeLeaf()
if (this.tree) { this.tree.removeLeaf() }
}
};
console.log("getTaskToolbar (App.js): возвращаем список кнопок на пенли инструментов");
return ToolButtonList;
};
console.log("getTaskToolbar (App.js): возвращаем панель инструментов со всеми кнопками");
return TaskToolbar;
}
}
Expand Down
Loading