Giter Club home page Giter Club logo

forcelayout's Introduction

Force layout

Android Arsenal License Download

Forcelayout is an Android library for visualizing data. You can drawing graph with spring-like attractive forces.

Demo

image image

Usage

Usage in kotlin

1. Gradle

repositories {
    jcenter()
}

dependencies {
    compile 'jp.kai:forcelayout:1.0.9'
}

2. Definitions of nodes

val nodes = ArrayList <Pair<String,Int>>()
nodes.add(Pair("nodeName1", R.drawable.example1))
nodes.add(Pair("nodeName2", R.drawable.example2))
nodes.add(Pair("nodeName3", R.drawable.example3))

or

val nodes: Nodes = Nodes()
nodes.add(NodePair("nodeName1", R.drawable.example1))
nodes.add(NodePair("nodeName2", R.drawable.example2))
nodes.add(NodePair("nodeName3", R.drawable.example3))

If you don't use image. You can just write node name.

val nodes: Array<String> = arrayOf( "nodeName1", "nodeName2", "nodeName3")

image

3. Definitions of links

val links = Arrays.asList("nodeName1-nodeName2", "nodeName1-nodeName3")

or

val links: Links = Links()
links.add(LinkPair("nodeName1", "nodeName2"))
links.add(LinkPair("nodeName1", "nodeName3"))

4. Set node and link style (optional)

val forcelayout = Forcelayout(applicationContext)

forcelayout.node()
    .size(100)
    .style(Color.argb(100,200,30,50))

forcelayout.link()
    .style(Color.argb(60,50,30,200), 5.0f)

5. Set nodes and links

You can set node's size and link-strength, and so on. Please use anko if you write in kotlin.

val forcelayout = Forcelayout(applicationContext) 

forcelayout.with(this)
	.size(200)
	.distance(200)
	.gravity(0.04)
	.friction(0.04)
	.nodes(nodes)
	.links(links)
	.start()
Params Description
size To set image width.
distance To set distance between each nodes.
gravity To set gravitation.
friction To set gravitation between pair of nodes.
nodes To set nodes that contain node name and image.
links To set pairs that contain node names.

Thanks

Inspired by force layout in D3.js.

License


Copyright 2016 kai0masanari

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

forcelayout's People

Watchers

James Cloos avatar Antonio López Marín avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.