项目作者: mbaez

项目描述 :
Zoomable treemap
高级语言: JavaScript
项目地址: git://github.com/mbaez/map3.git
创建时间: 2016-05-19T18:47:49Z
项目社区:https://github.com/mbaez/map3

开源协议:

下载


Map3

Javascript library to implement a interactive zoomable treemap.

Usage

Below is quick example how to use :

Download the latest version library and include it in your html.

  1. <script src="js/jquery.js"></script>
  2. <script src="js/d3.min.js"></script>
  3. <script src="js/d3plus.min.js"></script>
  4. <script src="js/map3.js"></script>
  5. <link href="map3.css" rel="stylesheet">

Add a container in your html :

  1. ...
  2. <div id="treemap"></div>

This code build a simple treemap

  1. ...
  2. var viz = new Map3({
  3. container: "#treemap",
  4. label: "value",
  5. size: "size"
  6. });
  7. viz.data(vizData);

Options

The available configuration options from a treemap:

options.container

Type: String

Container where the list will build.

options.label

Type: Array|String

The json attribute name that determines the label of the box.

options.size

Type: Array

The json attribute name that determines the size of the box.

options[levels]

Type: Array|String

The Array of attributes that define the hierarchy of treemap.

options[time]

Type: d3plus.time

Define the timeline of the treemap. See d3plus

options[locale]

Type: Options

Support specifying a locale to use for translating common interface words and phrases into a different language.

  1. var viz = new Map3({
  2. container: "#treemap",
  3. ...
  4. locale: {
  5. region: "es_ES",
  6. translate: {
  7. "size": "Monto"
  8. }
  9. }
  10. });

Functions

The available functions to interact with the treemap:

Map3.data(data)

Type: Function

  • {Array}data: the visualization data.

Sets the data associated with your visualization.

  1. var vizData = [{
  2. "value": "Data1",
  3. "size": 2065724632,
  4. }, {
  5. "value": "Data2",
  6. "size": 141765766652,
  7. }, {
  8. "value": "Data3",
  9. "size": 48130171902,
  10. }];
  11. var viz = new Map3({
  12. container: "#treemap",
  13. label: "value",
  14. size: "size"
  15. });
  16. //do something
  17. //setting data
  18. viz.data(vizData);

Map3.redraw(data)

Type: Function

  • {Array}data: the visualization data.

Redraw the visualization with new data.

Map3.config(options)

Type: Function

  • {Object} options: the value to format.

Wrapper method for d3plus.config.

  1. var viz = new Map3({...});
  2. viz.config({
  3. color: {
  4. scale: [
  5. "#fdae6b",
  6. "#EACE3F",
  7. ...
  8. "#e099cf",
  9. "#889ca3"
  10. ]
  11. }
  12. });
  13. //setting data
  14. viz.data(vizData);

Map3.on(event, handler)

Type: Function

  • {String}event: the name of the event.
  • {Function}handler: handler function.

The events available are:

  • drill-down : triggered when a box of the multilevel treemap is clicked.
  • drill-up : triggered when a element of breadcrumb is clicked.
  1. var viz = new Map3({...});
  2. viz.on("drill-down", function (d) {
  3. //do something
  4. console.log(d);
  5. });
  6. viz.on("drill-up", function (d) {
  7. //do something
  8. console.log(d);
  9. });
  10. //setting data
  11. viz.data(vizData);

Want to contribute?

If you’ve found a bug or have a great idea for new feature let me know by [adding your suggestion]
(http://github.com/mbaez/3map/issues/new) to issues list.