Skip to content

Repository files navigation

A network weathermap UI Library built with SVG.

screenshot

The configuration can be done by:

  • a JSON file which is load from the server
  • a Javascript object
  • using the API

It is possible to inject a custom UI to aid the user when creating the networkmap directly in the browser. Most of the configuration of the networkmap can be done directly in the browser and in addion the JSON format makes it easy to parse and update the configuration.

A minimal setup is done by:

varmap;window.addEvent('load',function(){map=newnetworkMap.Graph('paper').load('/spec/weathermap.json');});
<divid="paper"></div>

An example configuration file is found in spec/weathermap.json

networkmap.Graph class

This class extends networkMap.Observable and networkMap.Mediator.

Constructor

ConstructorDescription
Graph(target:Node, options:GraphOptions)Creates a new graph inside the given HTML container

Methods

MethodsReturn valueDescription
setRefreshInterval(interval:numer)selfSets the periodic refresh interval in seconds. O to disable.
getSvg()SVG.docReturns the SVG node where the graph is rendered.
getPaintArea()SVG.GReturn the SVG group where the graph is rendered.
grid(options:GridOptions)selfSet drag-grid size
load(obj:string|GraphConfiguration)selfLoad a map from configuration. If string is given it is assumed to be an URL to do an GET request from
getGraphConfiguration()GraphConfigurationGet the current GraphConfiguration
save(SaveOptions)selfSave the current GraphConfiguration
setOptions(options:GraphOptions)self
registerLinkGenerator(component:string, f:function)noneRegister a function that generates an href string for either Node or Link.
getNode(id:string)Node
getLinks(node:string|Node, sibling:string|Node)ArrayReturns an array of links that are connected to the nodes.
update()selfThis will force the graph to fetch data from the server and update the colors
enableEditor
disableEditor
enableDraggableNodes
disableDraggableNodes

Properties

PropertiesTypeDescription
defaults.nodePropertiesThe default node options for the graph instance. Inherits defaults from Node.defaults
defaults.linkPropertiesThe default link options for the graph instance. Inherits defaults from Link.defaults

Events

EventsArguemntsDescription
loadnoneThis event is fired when a graph has loaded configuration

networkMap.GraphOptions object specification

PropertiesTypeDescription
datasourcestringThe name of the datasource to load data with
colormapstringThe name of the colormap (legend) to use in the map.
editorbooleanThe enabled/disabled state of the graph editor. Default value is true.
enableEditor
draggableNodesbooleanIf true, nodes can be dragged. Default value is false.
enableDraggableNodes
updatebooleanThe enable/disable state for automatic updates of graph values
updateOptionsUpdateOptionsThe graph update options.
refreshInterval
gridbooleanThe enable/disable of the snap to grid when dragging objects
gridOptionsGridOptionsThe snap-to-grid options
nodeOptionsNodeOptionsThe default node options to use for the graph instance
linkOptionsLinkOptionsThe default link options to use for the graph instance
savebooleanThe enable/disable if it is possible to save the graph
SaveOptionsSaveOptionsThe options that controls how the graph configuration is dumped and saved.

networkMap.GridOptions object specification

PropertiesTypeDescription
xnumberThe width of the grid in horizontal direction
ynumberThe hight of the grid in vertical direction

networkMap.UpdateOptions object specification

PropertiesTypeDescription
intervalnumericThe interval, in seconds, to control how often the graph updates (fetch) data from the server. Default value is 300.
batchUpdatebooleanThe enable/disable state of batch updates of data from the server. Default value is true.

networkMap.GraphConfiguration object specification

PropertiesTypeDescription

networkMap.NodeOptions object specification

PropertiesTypeDescription

networkMap.LinkOptions object specification

PropertiesTypeDescription

networkMap.SaveOptions object specification

PropertiesTypeDescription

networkmap.Node class

This class extends Observable

Constructor

ConstructorDescription
Node(options:NodeOptions)Creates a new node. If a graph is specified the node is added to the graph. Note that the possition must be set for the node to display.

Methods

MethodsReturn valueDescription
getConfiguration()NodeConfigurationGet the current node configuration.
setGraph(graph:Graph)selfRenders the node on the specified graph. If graph is set to null the node will be removed.

Events

EventsArguemntsDescription
dragstart
drag
dragend
requestHref

|

Node.defaults object specifications

This object is an instance of Properties. Note: the properties must be accessed with get/set methods.

PropertiesTypeDefault value
idstringundefined
namestringundefined
commentstringundefined
xnumeric10
ynumeric10
latnumericnull
lngnumericnull
fontFamilystring'Helvetica'
fontSizenumeric16
bgColorstring'#dddddd'
strokeColorstring'#000000'
strokeWidthnumeric2
labelNodeLabelOptions-
rendererNodeRedererIdRECT
paddingnumeric10
hrefstringnull
draggablebooleanfalse

networkmap.Link class

This class extends networkMap.Observable.

Constructor

ConstructorDescription
Link(options:LinkOptions)Creates a new graph. Creates a new node. If a graph is specified the node is added to the graph. Note that two nodes must be set for the link to display.

Methods

MethodsReturn valueDescription
getNode(link:SubLink)NodeGet the node that the sublink is associated with
connectedTo(node:string|Node, sibling:string|Node)boolean
getConfiguration()NodeConfigurationGet the current link configuration.
setGraph(graph:Graph)selfRenders the link on the specified graph. If graph is set to null the node will be removed.
showPath()selfShow the link
hidePath()selfHide the link
showShadowPathselfShow the links shaddow path
hideShadowPathselfHide the links shaddow path
update(force:boolean)selfThe link will call the datasource to update on the screen.

Properties

PropertiesTypeDescription

Events

EventsArguemntsDescription
requestHref

Link.defaults object specification

This object is an instance of Properties. Note: the properties must be accessed with get/set methods.

PropertiesTypeDefault value
insetnumeric10
connectionDistancenumeric10
staticConnectionDistancenumeric30
arrowHeadLengthnumeric10
widthnumeric10
backgroundstring'#777'
update**booleantrue
updateOptionsLink.UpdateOptions
datasourcestring'simulate'
colormapstring'flat5'

networkmap.Link class

This class extends networkMap.Observable and networkMap.Mediator.

Constructor

ConstructorDescription
Graph(target:Node, options:GraphOptions)Creates a new graph inside the given HTML container

Methods

MethodsReturn valueDescription

Properties

PropertiesTypeDescription

Events

EventsArguemntsDescription

GraphOptions object specification

PropertiesTypeDescription

Integration

As weathermaps are usually integrated in other tools there is no backend in NetworkMap.js. There is however an example implementation in spec/update.php that is used in development to test the save functionality. Use it in production at your own risk!!!

Populating data in the weathermap

To fetch data you need to register a datasource with networkMap.registerDatasource(name, function)

The function can takes two parameters

url

This is the requestUrl that is defined in the configuration.

requests

This is an array of objects that containing two properties (data and callback). The property data contains the information from requestData in the configuration and the property callback contains a function that should be called when the data is retreived.

The request array structure

[{data: {...},callback: function(url,request,value,realvalue)}]

A simple dummy example of the simulations datasource that is included

networkMap.registerDatasource('simulate',function(url,requests){requests.each(function(request){vardataPoint=Math.random();request.callback({url: url,request: request.data,value: dataPoint,realValue: Math.round(dataPoint*100)+'Mbps'});});});

Saving changes

To enable users change and create network maps there is an interface to handle this. This is done by networkMap.SettingsManager, however the only configuration that is needed is to setup the onSave block in the configuration.

method

This is the method the data is sent to the server. Valid values are:

  • post (default)
  • get

url

The url to send the reqest to.

data

Here you are free to populate whatever information you are required to handle this on the backend.

Example configurtion:

"onSave": {"method": "post","url": "update.php","data": {"id": "weathermap.json"}}

The server should return an JSON envoded object

Status for a save that worked

{"status": "ok","error": null}

If an error occurred

{"status": "nok","error": "error string"}

GridOptions

Test

Build

Set up build envionment

This installation assumes that node.js and npm is installed

  • npm install

Build from source

  • grunt

Development

  • grunt watch

Installing packages for development

This will automaticly add files to package.json

  • npm install --save-dev

Adding New Javascript Files

To make the concatenation work you need to add the file to Gruntfile.js

networkMap

The only object that will polute the global object

networkMap.datasorce

Internal object that keeps track of datasources. The project ships with one datasource simulate which is used for testing. To add new datasources use networkMap.registerDatasource(name, datasouce)

networkMap.registerDatasource(name, datasouce)

name

The name of the datasource to register.

datasource

The datasource is a function that takes to values, url and requests. Where requests is an object containing the datapropertyand acallback` property. As the interface between the link renderer and datasource is not specified please see documentation for the datasource you whish to integrate against.

networkMap.colormap

networkMap.registerColormap(name, colormap)

Predefined colormaps

rasta5

flat5

networkMap.ColorLegend

Internal object that creates and inserts the legend for colors in the graph

networkMap.Graph

Example:

<divid="paper"></div>
newnetworkMap.Graph('paper').load('/weathermap.json')

About

A network weathermap written in Javascript and SVG with editing capabilities.

Resources

Stars

141 stars

Watchers

20 watching

Forks

Releases

Packages

Used by

Contributors

Languages