Skip to content

Commit

Permalink
fix(layout): correct seed types, docs and validation (#727)
Browse files Browse the repository at this point in the history
* fix(layout): allow string seeds

We switched to string seeds with the switch to Alea (way better rng than
what we used before). The input validation however still required
numbers only. This allows string seeds and with it the return value of
`network.getSeed()` to be used as a seed.

* docs: update seed type

* fix(layout): update seed type in d.ts
  • Loading branch information
Thomaash authored May 19, 2020
1 parent 15f4193 commit 9b3f671
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs-kr/network/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ <h2 id="methods">메소드</h2>
<tr class="hidden" parent="clusterByHubsize">
</tr>
<tr class="hidden" parent="getSeed">
<td class="midMethods">반환값: Number</td>
<td class="midMethods">반환값: Number or String</td>
<td>네트워크 레이아웃을 좋아하고 다음에 같은 방식으로 시작하려면이 방법을 사용하여 시드를 요청하고
<code>layout.randomSeed</code>에 옵션을 넣으십시오.
</td>
Expand Down
2 changes: 1 addition & 1 deletion docs-kr/network/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ <h3>옵션</h3>
<p>hierarchical layout을 사용하도록 설정한다면, 다른 옵션 중 일부를 재정의합니다. physics는 hierarchical repulsion solver로 설정되고 동적 곡선 Edge는 정적 곡선 Edge로 변환됩니다.</p>
<table class="options" id="optionTable">
<tr><th>이름</th><th>Type</th><th>Default</th><td>설명</td></tr>
<tr><td>randomSeed</td><td>Number</td><td><code>undefined</code></td> <td>hierarchical layout을 사용하지 않는 경우, Node들은 처음에 랜덤하게 배치됩니다. 매번 결과가 다르다는 의미입니다. 랜덤 시드를 수동으로 제공하는 경우 layout이 매번 동일합니다. 정의되지 않은 시드로 시도하고 layout이 마음에 들면 <code>getSeed()</code>를 이용해 시드를 확인하는 것이 좋습니다.</td></tr>
<tr><td>randomSeed</td><td>Number or String</td><td><code>undefined</code></td> <td>hierarchical layout을 사용하지 않는 경우, Node들은 처음에 랜덤하게 배치됩니다. 매번 결과가 다르다는 의미입니다. 랜덤 시드를 수동으로 제공하는 경우 layout이 매번 동일합니다. 정의되지 않은 시드로 시도하고 layout이 마음에 들면 <code>getSeed()</code>를 이용해 시드를 확인하는 것이 좋습니다.</td></tr>
<tr id="layout"><td>improvedLayout</td><td>Boolean</td><td><code>true</code></td> <td>활성화가 되면 Network는 초기 layout에 Kamada Kawai 알고리즘을 사용합니다. Node가 100개 이상인 Network의 경우 Node를 줄이기 위해 클러스터링이 자동으로 수행됩니다. (리프 Node가 적거나 없음), 이것이 작동하지 않을 수 있으며 이전 메소드로 돌아갑니다. 이는 개선될 것입니다.</td></tr>
<tr><td>clusterThreshold</td><td>Number</td><td><code>150</code></td> <td><code>improvedLayout</code>이 적용되는 클러스터 임계값입니다.</td></tr>
<tr class='toggle collapsible' onclick="toggleTable('optionTable','hierarchical', this);"><td><span parent="repulsion" class="right-caret"></span> hierarchical</td><td>Object or Boolean</td><td><code>Object</code></td> <td>True이면, layout 엔진은 기본 설정을 사용하여 Node를 hierarchical 방식으로 배치합니다. 사용자 설정을 위해 object를 제공할 수 있습니다.</td></tr>
Expand Down
2 changes: 1 addition & 1 deletion docs/network/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ <h2 id="methods">Methods</h2>
<tr class="hidden" parent="clusterByHubsize">
</tr>
<tr class="hidden" parent="getSeed">
<td class="midMethods">Returns: Number</td>
<td class="midMethods">Returns: Number or String</td>
<td>If you like the layout of your network and would like it to start in the same way next time, ask for
the
seed using this method and put it in the <code>layout.randomSeed</code> option.
Expand Down
2 changes: 1 addition & 1 deletion docs/network/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ <h3>Options</h3>
<p>When enabling the hierarchical layout, it overrules some of the other options. The physics is set to the hierarchical repulsion solver and dynamic smooth edges are converted to static smooth edges.</p>
<table class="options" id="optionTable">
<tr><th>Name</th><th>Type</th><th>Default</th><td>Description</td></tr>
<tr><td>randomSeed</td><td>Number</td><td><code>undefined</code></td> <td>When NOT using the hierarchical layout, the nodes are randomly positioned initially. This means that the settled result is different every time. If you provide a random seed manually, the layout will be the same every time. Ideally you try with an undefined seed, reload until you are happy with the layout and use the <code>getSeed()</code> method to ascertain the seed.</td></tr>
<tr><td>randomSeed</td><td>Number or String</td><td><code>undefined</code></td> <td>When NOT using the hierarchical layout, the nodes are randomly positioned initially. This means that the settled result is different every time. If you provide a random seed manually, the layout will be the same every time. Ideally you try with an undefined seed, reload until you are happy with the layout and use the <code>getSeed()</code> method to ascertain the seed.</td></tr>
<tr id="layout"><td>improvedLayout</td><td>Boolean</td><td><code>true</code></td> <td>When enabled, the network will use the Kamada Kawai algorithm for initial layout. For networks larger than 100 nodes, clustering will be performed automatically to reduce the amount of nodes. This can greatly improve the stabilization times. If the network is very interconnected (no or few leaf nodes), this may not work and it will revert back to the old method. Performance will be improved in the future.</td></tr>
<tr><td>clusterThreshold</td><td>Number</td><td><code>150</code></td> <td>Cluster threshold to which <code>improvedLayout</code> applies.</td></tr>
<tr class='toggle collapsible' onclick="toggleTable('optionTable','hierarchical', this);"><td><span parent="repulsion" class="right-caret"></span> hierarchical</td><td>Object or Boolean</td><td><code>Object</code></td> <td>When true, the layout engine positions the nodes in a hierarchical fashion using default settings. For customization you can supply an object.</td></tr>
Expand Down
2 changes: 1 addition & 1 deletion lib/network/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ let allOptions = {
__type__: { object }
},
layout: {
randomSeed: { 'undefined': 'undefined', number },
randomSeed: { 'undefined': 'undefined', number, string },
improvedLayout: { boolean: bool },
clusterThreshold: { number },
hierarchical: {
Expand Down
2 changes: 1 addition & 1 deletion types/network/Network.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export class Network {
*
* @returns the current seed of the network.
*/
getSeed(): number;
getSeed(): number | string;

/**
* Programatically enable the edit mode.
Expand Down

0 comments on commit 9b3f671

Please sign in to comment.