"use client"; import { useState } from "react"; import { CausalGraph, CausalProvider, useCausal, useCausalDocument, useCausalDocumentState } from "@cytocausal/react"; import type { CausalDataset, CausalResult } from "@cytocausal/core"; import type { LayoutOptions } from "cytoscape"; import type { TutorialTopic } from "../topics.ts"; import "@cytocausal/react/styles.css"; const dataset: CausalDataset = { id: "plant-water", snapshots: [{ id: "draft", nodes: [ { id: "rain", label: "Rain", metadata: { category: "weather" } }, { id: "water", label: "Soil water" }, { id: "stress", label: "Plant water stress" }, ], edges: [ { id: "rain-water", source: "rain", target: "water", polarity: "positive" }, { id: "water-stress", source: "water", target: "stress", polarity: "negative" }, ] }] }; const layout: LayoutOptions = { name: "breadthfirst", directed: true, padding: 40 }; export default function CommandsExample({ topic, lang }: { topic: TutorialTopic; lang: "en" | "zh-cn" }) { const document = useCausalDocument({ initialDataset: dataset }); return ; } function Commands({ topic, chinese }: { topic: TutorialTopic; chinese: boolean }) { const { document, edit, selection, snapshot, view, io, query } = useCausal(); const state = useCausalDocumentState(document!); const [message, setMessage] = useState(""); const [text, setText] = useState(""); const [dragging, setDragging] = useState(true); const t = (en: string, zh: string) => chinese ? zh : en; function report(result: CausalResult) { setMessage(result.ok ? t("Done", "已完成") : `${result.error.code}: ${result.error.message}`); } if (!edit) return null; const chosen = selection.current(); return <>

{t("Relationships are example assumptions. Editing the graph does not establish causation.", "关系是示例假设;编辑或显示图形不能证明因果关系。")}

{topic === "elements" && <> } {(topic === "elements" || topic === "events") && <> } {topic === "events" && <> }

{snapshot.nodes.length} {t("nodes", "个节点")} · {snapshot.edges.length} {t("links", "条关系")} · {chosen.nodes?.length ?? 0}/{chosen.edges?.length ?? 0} {t("selected nodes/links", "个选中节点/关系")} · {t("revision", "修订")} {state.revision}

{topic === "data" && <>