GoJs1つの図に複数のレイアウトを含めることは可能ですか

NAS

同じ図に縦と横のレイアウトの図が欲しいのですが。gojsでこれをどのように達成できますか?

ここに画像の説明を入力してください

ウォルターノースウッズ

あなたがあなたの目標を達成することができる多くの方法があります。私は3つのオフハンドを考えることができます。作業の降順:

  • 必要なことを実行するカスタムレイアウト作成しますこれは最も一般的であり、結合する2つの既存の図で使用したデータ構造と最も互換性があります。
  • In your case you might be able to use the TableLayout that is in the extensions directory: http://gojs.net/latest/extensions/Table.html. You probably could continue to use Groups, but you would set their Group.layout to null so that they are completely ignored when the layout is performed.
  • Put everything in one of your existing diagrams into a Group and put everything from your other existing diagram into another Group. The Diagram.layout of the first would be the Group.layout of the first group, and the Diagram.layout of the second diagram would be the Group.layout of the second group.

Note that each Diagram can have exactly one Model (the Diagram.model), so for all three techniques you would need to add all of the data into a single model without getting references between them confused. That means you need to make sure the keys for the nodes are all unique.

Here's an example of how you can put two separate diagrams into a single diagram using the third technique. I'll start with two copies of the Minimal sample, http://gojs.net/latest/samples/minimal.html, where the only change is that one has a ForceDirectedLayout and the other one has a LayeredDigraphLayout. So one will be defined:

myDiagram = $(go.Diagram, "myDiagramDiv",
              {
                initialContentAlignment: go.Spot.Center,
                layout: $(go.ForceDirectedLayout),
                "undoManager.isEnabled": true
              });

and the other will be defined:

myDiagram = $(go.Diagram, "myDiagramDiv",
              {
                initialContentAlignment: go.Spot.Center,
                layout: $(go.LayeredDigraphLayout),
                "undoManager.isEnabled": true
              });

But otherwise these two diagrams are exactly like the Minimal sample.

Initially each model of Minimal is created by:

myDiagram.model = new go.GraphLinksModel(
[
  { key: "Alpha", color: "lightblue" },
  { key: "Beta", color: "orange" },
  { key: "Gamma", color: "lightgreen" },
  { key: "Delta", color: "pink" }
],
[
  { from: "Alpha", to: "Beta" },
  { from: "Alpha", to: "Gamma" },
  { from: "Beta", to: "Beta" },
  { from: "Gamma", to: "Delta" },
  { from: "Delta", to: "Alpha" }
]);

So, we first need to create a combined model that is the two models added together. One way to put them together is:

myDiagram.model = new go.GraphLinksModel(
[
  { key: "Alpha", color: "lightblue" },
  { key: "Beta", color: "orange" },
  { key: "Gamma", color: "lightgreen" },
  { key: "Delta", color: "pink" },
  { key: "Alpha2", color: "lightblue" },
  { key: "Beta2", color: "orange" },
  { key: "Gamma2", color: "lightgreen" },
  { key: "Delta2", color: "pink" }
],
[
  { from: "Alpha", to: "Beta" },
  { from: "Alpha", to: "Gamma" },
  { from: "Beta", to: "Beta" },
  { from: "Gamma", to: "Delta" },
  { from: "Delta", to: "Alpha" },
  { from: "Alpha2", to: "Beta2" },
  { from: "Alpha2", to: "Gamma2" },
  { from: "Beta2", to: "Beta2" },
  { from: "Gamma2", to: "Delta2" },
  { from: "Delta2", to: "Alpha2" }
]);

Again, I'll mention that this is work you would need to do no matter which technique you used. Presumably you have already done this and are just wondering how to handle two layouts.

The third technique I suggested uses Groups to encapsulate what had originally been in a whole Diagram. So let us add two groups to the model and assign each of the original nodes to the corresponding group:

myDiagram.model = new go.GraphLinksModel(
[
  { key: "FD", isGroup: true, category: "FD" },  // NEW
  { key: "LD", isGroup: true, category: "LD" },  // NEW
  { key: "Alpha", color: "lightblue", group: "FD" },
  { key: "Beta", color: "orange", group: "FD" },
  { key: "Gamma", color: "lightgreen", group: "FD" },
  { key: "Delta", color: "pink", group: "FD" },
  { key: "Alpha2", color: "lightblue", group: "LD" },
  { key: "Beta2", color: "orange", group: "LD" },
  { key: "Gamma2", color: "lightgreen", group: "LD" },
  { key: "Delta2", color: "pink", group: "LD" }
],
[
  { from: "Alpha", to: "Beta" },
  { from: "Alpha", to: "Gamma" },
  { from: "Beta", to: "Beta" },
  { from: "Gamma", to: "Delta" },
  { from: "Delta", to: "Alpha" },
  { from: "Alpha2", to: "Beta2" },
  { from: "Alpha2", to: "Gamma2" },
  { from: "Beta2", to: "Beta2" },
  { from: "Gamma2", to: "Delta2" },
  { from: "Delta2", to: "Alpha2" }
]);

Now we just need to define each group/category/template:

myDiagram.groupTemplateMap.add("FD",
  $(go.Group, "Auto",
    { layout: $(go.ForceDirectedLayout) },
    $(go.Shape, { fill: "white", stroke: "lightgray" }),
    $(go.Placeholder, { padding: 10 })
  ));
myDiagram.groupTemplateMap.add("LD",
  $(go.Group, "Auto",
    { layout: $(go.LayeredDigraphLayout) },
    $(go.Shape, { fill: "white", stroke: "lightgray" }),
    $(go.Placeholder, { padding: 10 })
  ));

For the purposes of this demonstration the details of the visual appearance of each kind of group does not matter, just as the details of the appearances of the nodes and links do not matter. What does matter to you is that one group template uses one layout and the other uses a different one, there are two group data objects, and all the node data is assigned to the appropriate group.

In this case each group template is being used as a singleton, but perhaps your requirements will result in using more than one of any or all of the group templates.

Now you just need to specify the Diagram.layout to control how the two groups are arranged relative to each other. Perhaps the simplest would be to use a GridLayout:

myDiagram = $(go.Diagram, "myDiagramDiv",
              {
                initialContentAlignment: go.Spot.Center,
                layout: $(go.GridLayout, { wrappingColumn: 1 }),
                "undoManager.isEnabled": true
              });

もちろん、まったく異なるレイアウトやカスタムレイアウトを使用するなど、必要に応じてレイアウトをカスタマイズできます。

これが完全なコードです。簡潔にするために、元のMinimalサンプルから一連のコメントを削除しました。

<!DOCTYPE html>
<html>
<head>
<title>Combining 2 Diagrams with Different Layouts</title>
<!-- Copyright 1998-2016 by Northwoods Software Corporation. -->
<meta charset="UTF-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/gojs/1.6.5/go.js"></script>
<script id="code">
  function init() {
    var $ = go.GraphObject.make;  // for conciseness in defining templates

    myDiagram = $(go.Diagram, "myDiagramDiv",
                  {
                    initialContentAlignment: go.Spot.Center,
                    layout: $(go.GridLayout, { wrappingColumn: 1 }),
                    "undoManager.isEnabled": true
                  });

    myDiagram.nodeTemplate =
      $(go.Node, "Auto",
        $(go.Shape, "RoundedRectangle",
          new go.Binding("fill", "color")),
        $(go.TextBlock, { margin: 3 },
          new go.Binding("text", "key"))
      );

    myDiagram.groupTemplateMap.add("FD",
      $(go.Group, "Auto",
        { layout: $(go.ForceDirectedLayout) },
        $(go.Shape, { fill: "white", stroke: "lightgray" }),
        $(go.Placeholder, { padding: 10 })
      ));

    myDiagram.groupTemplateMap.add("LD",
      $(go.Group, "Auto",
        { layout: $(go.LayeredDigraphLayout) },
        $(go.Shape, { fill: "white", stroke: "lightgray" }),
        $(go.Placeholder, { padding: 10 })
      ));

    myDiagram.model = new go.GraphLinksModel(
    [
      { key: "FD", isGroup: true, category: "FD" },
      { key: "LD", isGroup: true, category: "LD" },
      { key: "Alpha", color: "lightblue", group: "FD" },
      { key: "Beta", color: "orange", group: "FD" },
      { key: "Gamma", color: "lightgreen", group: "FD" },
      { key: "Delta", color: "pink", group: "FD" },
      { key: "Alpha2", color: "lightblue", group: "LD" },
      { key: "Beta2", color: "orange", group: "LD" },
      { key: "Gamma2", color: "lightgreen", group: "LD" },
      { key: "Delta2", color: "pink", group: "LD" }
    ],
    [
      { from: "Alpha", to: "Beta" },
      { from: "Alpha", to: "Gamma" },
      { from: "Beta", to: "Beta" },
      { from: "Gamma", to: "Delta" },
      { from: "Delta", to: "Alpha" },
      { from: "Alpha2", to: "Beta2" },
      { from: "Alpha2", to: "Gamma2" },
      { from: "Beta2", to: "Beta2" },
      { from: "Gamma2", to: "Delta2" },
      { from: "Delta2", to: "Alpha2" }
    ]);
  }
</script>
</head>
<body onload="init();">
<div id="sample">
  <div id="myDiagramDiv" style="border: solid 1px black; width:400px; height:600px"></div>
</div>
</body>
</html>

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Android、Java:ドラッグ可能なリストに複数のレイアウトを含めることは可能ですか?

分類Dev

Eclipseの1つのファイルに複数のクラスを含めることは可能ですか?

分類Dev

1つの未来にPythonで複数のウェイターを含めることはできますか?

分類Dev

1つのWebアプリに2つのASP.NETCoreサイトを含めることは可能ですか?

分類Dev

空手フレームワークの1つのJSファイル内に複数のJS関数を含めることは可能ですか?

分類Dev

Android jarにレイアウトやその他のリソースを含めることは可能ですか?

分類Dev

1つのkikアカウントに複数のボットを配置することは可能ですか?

分類Dev

複数の画像レイヤーを1つのキャンバスに集めることは可能ですか?

分類Dev

BASH配列の1つの添え字に複数の値を含めることは可能ですか?

分類Dev

serverless-frameworkを使用してAppSyncAPIをセットアップする場合、1つのファイルに複数のVeliceテンプレートを含めることは可能ですか?

分類Dev

1つのGoogleChrome拡張機能に複数のブラウザアクションアイコンを含めることはできますか?

分類Dev

1つのディレクトリに同じ名前の複数のファイル/ディレクトリを含めることはできますか?

分類Dev

Angular NGRX:1つのEntityAdapterに複数のエンティティを含めることは可能ですか?

分類Dev

1つのソリューションに複数のNuGet構成を含めることは可能ですか?

分類Dev

Kotlin Android Extensionで特定のレイアウトをプログラムで含めることは可能ですか?

分類Dev

1つのプレハブスポナーに複数のスプライトを含めることはできますか?

分類Dev

1つのMySQLステートメント(SET)に複数のユーザー定義変数を含めることは可能ですか?

分類Dev

1つのmatplotlib図に複数のgridspecレイアウトを埋め込みますか?

分類Dev

1つのsqlplusselectステートメントに複数のCASEステートメントを含めることは可能ですか?

分類Dev

レイアウトは可能ですか?複数の列と行を持つFlexboxとFloatのレイアウト

分類Dev

MySQL:1つの列に複数の文字セットを含めることはできますか?

分類Dev

私のapplicationContextに複数のPropertyPlaceHolderConfigurerを含めることは可能ですか?

分類Dev

D3を使用して、子ノードに折りたたみ可能な力のレイアウトで複数の親ノードを含めることはできますか

分類Dev

自動レイアウトの代わりに、デバイスごとに1つのレイアウトを持つことは可能ですか?

分類Dev

1つのGPUに2つのコアを含めることは可能ですか?

分類Dev

1つのhtmlに2つのアプリを含めることは可能ですか?

分類Dev

単一のGoバイナリに複数のラムダ関数を含めることは可能ですか?

分類Dev

React.jsに複数の<Switch>を含めることは可能ですか?

分類Dev

システムに複数のMBRを含めることは可能ですか?

Related 関連記事

  1. 1

    Android、Java:ドラッグ可能なリストに複数のレイアウトを含めることは可能ですか?

  2. 2

    Eclipseの1つのファイルに複数のクラスを含めることは可能ですか?

  3. 3

    1つの未来にPythonで複数のウェイターを含めることはできますか?

  4. 4

    1つのWebアプリに2つのASP.NETCoreサイトを含めることは可能ですか?

  5. 5

    空手フレームワークの1つのJSファイル内に複数のJS関数を含めることは可能ですか?

  6. 6

    Android jarにレイアウトやその他のリソースを含めることは可能ですか?

  7. 7

    1つのkikアカウントに複数のボットを配置することは可能ですか?

  8. 8

    複数の画像レイヤーを1つのキャンバスに集めることは可能ですか?

  9. 9

    BASH配列の1つの添え字に複数の値を含めることは可能ですか?

  10. 10

    serverless-frameworkを使用してAppSyncAPIをセットアップする場合、1つのファイルに複数のVeliceテンプレートを含めることは可能ですか?

  11. 11

    1つのGoogleChrome拡張機能に複数のブラウザアクションアイコンを含めることはできますか?

  12. 12

    1つのディレクトリに同じ名前の複数のファイル/ディレクトリを含めることはできますか?

  13. 13

    Angular NGRX:1つのEntityAdapterに複数のエンティティを含めることは可能ですか?

  14. 14

    1つのソリューションに複数のNuGet構成を含めることは可能ですか?

  15. 15

    Kotlin Android Extensionで特定のレイアウトをプログラムで含めることは可能ですか?

  16. 16

    1つのプレハブスポナーに複数のスプライトを含めることはできますか?

  17. 17

    1つのMySQLステートメント(SET)に複数のユーザー定義変数を含めることは可能ですか?

  18. 18

    1つのmatplotlib図に複数のgridspecレイアウトを埋め込みますか?

  19. 19

    1つのsqlplusselectステートメントに複数のCASEステートメントを含めることは可能ですか?

  20. 20

    レイアウトは可能ですか?複数の列と行を持つFlexboxとFloatのレイアウト

  21. 21

    MySQL:1つの列に複数の文字セットを含めることはできますか?

  22. 22

    私のapplicationContextに複数のPropertyPlaceHolderConfigurerを含めることは可能ですか?

  23. 23

    D3を使用して、子ノードに折りたたみ可能な力のレイアウトで複数の親ノードを含めることはできますか

  24. 24

    自動レイアウトの代わりに、デバイスごとに1つのレイアウトを持つことは可能ですか?

  25. 25

    1つのGPUに2つのコアを含めることは可能ですか?

  26. 26

    1つのhtmlに2つのアプリを含めることは可能ですか?

  27. 27

    単一のGoバイナリに複数のラムダ関数を含めることは可能ですか?

  28. 28

    React.jsに複数の<Switch>を含めることは可能ですか?

  29. 29

    システムに複数のMBRを含めることは可能ですか?

ホットタグ

アーカイブ