GithubHelp home page GithubHelp logo

d3js_array_to_flare's Introduction

Python array to d3js hierarchical json flare

For those types of visualization tools:
https://observablehq.com/@d3/gallery
https://observablehq.com/@d3/collapsible-tree
https://observablehq.com/@d3/zoomable-treemap

Python script to convert sorted array of nested data to d3js json flare

array=[['00001', '00004'], ['00001', '00004'], ['00002', '00008'], ['00002', '00008'], ['00002', '00008'], ['00002', '00014'], ['00002', '00014'], ['00003', '00092'], ['00003', '00092'], ['00003', '01004']]

value_is_count=True
value_is_lastColumn=False

  • Either array contains values in its last column, set value_is_lastColumn=True
  • Either array has no provided values but has duplicates to count, set value_is_count=True
  • Either array has single lines, values bill be set to 1

dict=asr_array_to_d3js_flare(array=array, value_is_count=value_is_count, value_is_lastColumn=value_is_lastColumn)

Will give a python dict like this:

{'name': 'flare', 'children': [{'name': '00001', 'children': [{'name': '00004', 'value': 2}]}, {'name': '00002', 'children': [{'name': '00008', 'value': 3}, {'name': '00014', 'value': 2}]}, {'name': '00003','children': [{'name': '00092', 'value': 2}, {'name': '01004', 'value': 1}]}]}

To obtain JSON string:
import json
json.dumps(d)

Will give this string:
{"name": "flare", "children": [{"name": "00001", "children": [{"name": "00004", "value": 2}]}, {"name": "00002", "children": [{"name": "00008", "value": 3}, {"name": "00014", "value": 2}]}, {"name": "00003", "children": [{"name": "00092", "value": 2}, {"name": "01004", "value": 1}]}]}

Et voilà !

d3js_array_to_flare's People

Contributors

jmasclef avatar

Watchers

 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.