aboutsummaryrefslogtreecommitdiff
path: root/src/stores/NodeCollectionStore.ts
blob: 7fac83d51a337c1d67054fcbbcc2bdab17d446ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { computed, observable, action } from "mobx";
import { NodeStore } from "./NodeStore";
import { Document } from "../fields/Document";

export class NodeCollectionStore extends NodeStore {

    @observable
    public Scale: number = 1;

    @observable
    public Nodes: NodeStore[] = new Array<NodeStore>();

    @observable
    public Docs: Document[] = [];

    @computed
    public get Transform(): string {
        const halfWidth = window.innerWidth / 2, halfHeight = window.innerHeight / 2;
        return `translate(${this.X + halfWidth}px, ${this.Y + halfHeight}px) scale(${this.Scale}) translate(${-halfWidth}px, ${-halfHeight}px)`;
    }

    @action
    public AddNodes(stores: NodeStore[]): void {
        stores.forEach(store => this.Nodes.push(store));
    }
}