Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: packages/charted/examples/layout/treemap_demo.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2015 Google Inc. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style
5 * license that can be found in the LICENSE file or at
6 * https://developers.google.com/open-source/licenses/bsd
7 */
8
9 library charted.demo.treemap;
10
11 import 'dart:html';
12
13 import '../../lib/layout/layout.dart';
14 import '../../lib/selection/selection.dart';
15 import '../../lib/charts/charts.dart';
16 import 'dart:math';
17
18 main() {
19
20 // Label, parent column, value
21 var rows = [
22 ['aaa', 3, 25], // p = ddd
23 ['bbb', 2, 10], // p = ccc, leaf
24 ['ccc', -1, 145], // root
25 ['ddd', 2, 125], // p = ccc
26 ['eee', 3, 30], // p = ddd
27 ['fff', 4, 10], // p = eee, leaf
28 ['ggg', 3, 30], // p = ddd, leaf
29 ['hhh', 2, 10], // p = ccc, leaf
30 ['iii', 3, 20], // p = ddd, leaf
31 ['jjj', 3, 13], // p = ddd, leaf
32 ['kkk', 3, 7], // p = ddd, leaf
33 ['lll', 4, 15], // p = eee, leaf
34 ['mmm', 4, 5], // p = eee, leaf
35 ['nnn', 0, 13], // p = aaa, leaf
36 ['ooo', 0, 12], // p = aaa, leaf
37 ];
38
39 var width = 400,
40 height = 300;
41
42 var theme = new QuantumChartTheme();
43 var host = querySelector('.demos-container');
44 var scope = new SelectionScope.element(host);
45 var root = scope.selectElements([host]);
46
47 void _createTreeMap(var host, var mode) {
48 var tree = new TreeMapLayout();
49 tree.mode = mode;
50 tree.size = [width, height];
51 List nodes = tree.layout(rows, 1, 0, 2);
52 var treemap = root.select(host);
53 var div = treemap.append('div')
54 ..style('position', 'relative')
55 ..style('width', '${width}px')
56 ..style('height', '${height}px');
57
58 var node = div.selectAll(".node").data(nodes);
59 node.enter.append("div")
60 ..styleWithCallback('left', (d, i, e) => '${d.x}px')
61 ..styleWithCallback('top', (d, i, e) => '${d.y}px')
62 ..styleWithCallback('width', (d, i, e) => '${max(0, d.dx - 1)}px')
63 ..styleWithCallback('height', (d, i, e) => '${max(0, d.dy - 1)}px')
64 ..styleWithCallback('background', (d, i, e) => d.children.isNotEmpty ?
65 theme.getColorForKey(d.label, ChartTheme.STATE_NORMAL) : null)
66 ..textWithCallback((d, i, e) => d.children.isNotEmpty ? null : d.label)
67 ..classed('node');
68
69 }
70 _createTreeMap('.squarify', TreeMapLayout.TREEMAP_LAYOUT_SQUARIFY);
71 _createTreeMap('.slice', TreeMapLayout.TREEMAP_LAYOUT_SLICE);
72 _createTreeMap('.dice', TreeMapLayout.TREEMAP_LAYOUT_DICE);
73 _createTreeMap('.slicedice', TreeMapLayout.TREEMAP_LAYOUT_SLICE_DICE);
74 }
75
76
OLDNEW
« no previous file with comments | « packages/charted/examples/index.html ('k') | packages/charted/examples/layout/treemap_demo.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698