Last active
August 7, 2020 04:13
-
-
Save EdSv/e274a4d12ad3491c383fb4fe76ee671e to your computer and use it in GitHub Desktop.
adapter visjs for dart lang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta name="scaffolded-by" content="https://github.com/google/stagehand"> | |
<title>visjs_adapter</title> | |
<link rel="stylesheet" href="styles.css"> | |
<!-- <link rel="stylesheet" href="./vis/dist/vis.css" type="text/css" /> | |
<script src="./vis/dist/vis.js" type="text/javascript"></script>--> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/4.15.1/vis.js" type="text/javascript"></script> | |
<link href="https://cdnjs.cloudflare.com/ajax/libs/vis/4.15.1/vis.css" type="text/css" /> | |
<script defer src="main.dart" type="application/dart"></script> | |
<script defer src="packages/browser/dart.js"></script> | |
<style type="text/css"> | |
#mynetwork { | |
width: 600px; | |
height: 400px; | |
border: 1px solid lightgray; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="mynetwork"></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library visjs.example; | |
import 'dart:html'; | |
import 'package:visjs_adapter/visjs.dart' as vis; | |
void main() { | |
List<Node> nodes = new List(); | |
List<Edge> edges = new List(); | |
for (int i = 0; i < 5; i++) { | |
nodes.add(new Node(id: i, label: 'Node ${i}')); | |
} | |
edges.add(new Edge(from: 1, to: 3)); | |
edges.add(new Edge(from: 1, to: 2)); | |
edges.add(new Edge(from: 2, to: 4)); | |
edges.add(new Edge(from: 2, to: 5)); | |
DataSet nodesData = new DataSet(nodes: nodes); | |
DataSet edgesData = new DataSet(edges: edges); | |
Data data = new Data(nodes: nodesData, edges: edgesData); | |
Options options = new Options(); | |
Element container = document.getElementById('mynetwork'); | |
Network network = | |
new Network(container: container, data: data, options: options); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 'visjs_adapter' | |
version: 0.0.1 | |
description: An absolute bare-bones web app. | |
#author: Your Name <email@example.com> | |
#homepage: https://www.example.com | |
environment: | |
sdk: '>=1.0.0 <2.0.0' | |
dependencies: | |
browser: '>=0.10.0 <0.11.0' | |
dart_to_js_script_rewriter: '^1.0.1' | |
js: ^0.6.0 | |
func: "^0.1.0" | |
transformers: | |
- dart_to_js_script_rewriter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library visjs; | |
import 'package:js/js.dart'; | |
import 'dart:html'; | |
@JS() | |
@anonymous | |
class Network { | |
external Element get container; | |
external set container(Element v); | |
external Data get data; | |
external set data(Data v); | |
external Object get options; | |
external set options(Object v); | |
external factory Network({Element container, Data data, Options options}); | |
} | |
@JS() | |
@anonymous | |
class Node { | |
external String get id; | |
external set id(String v); | |
external String get label; | |
external set label(String v); | |
external factory Node({int id, String label}); | |
} | |
@JS() | |
@anonymous | |
class Edge { | |
external int get from; | |
external set from(int v); | |
external int get to; | |
external set to(int v); | |
external factory Edge({int from, int to}); | |
} | |
@JS() | |
@anonymous | |
class Data { | |
external DataSet get nodes; | |
external DataSet get edges; | |
external set edges(DataSet v); | |
external set nodes(DataSet v); | |
external factory Data({DataSet nodes, DataSet edges}); | |
} | |
@JS() | |
@anonymous | |
class DataSet { | |
external List<Node> get nodes; | |
external set nodes(List<Node> v); | |
external List<Edge> get edges; | |
external set edges(List<Edge> v); | |
external factory DataSet({List<Node> nodes, List<Edge> edges}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment