[Pkg-javascript-commits] [d3-tip.js] 246/277: add requirejs example

bhuvan krishna bhuvan-guest at moszumanska.debian.org
Thu Dec 8 06:57:35 UTC 2016


This is an automated email from the git hooks/post-receive script.

bhuvan-guest pushed a commit to branch master
in repository d3-tip.js.

commit 4bbc12d146fd65393e6394783feb1e1d5ec63366
Author: Justin Palmer <justin at github.com>
Date:   Tue Oct 21 07:58:43 2014 -0600

    add requirejs example
---
 examples/requirejs.html | 111 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 111 insertions(+)

diff --git a/examples/requirejs.html b/examples/requirejs.html
new file mode 100644
index 0000000..8886d02
--- /dev/null
+++ b/examples/requirejs.html
@@ -0,0 +1,111 @@
+<!DOCTYPE html>
+<html>
+<head>
+  <title>d3.tip.js - Tooltips for D3</title>
+  <meta charset="utf-8" />
+  <title>require.js</title>
+  <link rel="stylesheet" type="css" href="example-styles.css">
+  <style type="text/css">
+  body {
+    padding: 40px;
+    font-family: "Helvetica Neue", Helvetica, sans-serif;
+    font-size: 12px;
+    height: 1000px;
+  }
+
+  .d3-tip span {
+    color: #ff00c7;
+  }
+
+  .domain {
+    display: none;
+  }
+
+  .axis line {
+    stroke-width: 1px;
+    stroke: #eee;
+    shape-rendering: crispedges;
+  }
+
+  .axis text {
+    fill: #888;
+  }
+
+  rect {
+    fill: #339cff;
+    fill-opacity: 0.7;
+  }
+
+  rect:hover {
+    fill-opacity: 1;
+  }
+  </style>
+  <script type="text/javascript">
+    data = [{"total":225,"days":[12,51,60,26,38,31,7]},{"total":279,"days":[42,33,34,72,61,12,25]},{"total":212,"days":[12,59,24,70,36,5,6]},{"total":335,"days":[17,43,38,58,67,72,40]},{"total":329,"days":[40,53,62,48,38,36,52]},{"total":234,"days":[15,25,41,66,35,37,15]},{"total":175,"days":[2,40,23,40,23,34,13]},{"total":308,"days":[20,22,63,55,51,66,31]},{"total":401,"days":[20,64,42,62,88,79,46]},{"total":214,"days":[24,27,25,48,38,28,24]},{"total":332,"days":[26,43,20,109,74,29,31]} [...]
+  </script>
+  <script src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.15/require.min.js" charset="utf-8"></script>
+  <script charset="utf-8">
+    // Mostly used for development.  Point to proper location of d3 and d3tip.
+    require.config({
+      baseUrl: '/',
+      paths: {
+          d3: 'bower_components/d3/d3',
+          d3tip: 'index'
+      }
+    });
+
+    // Require d3 and d3tip
+    require(['d3', 'd3tip'], function(d3, d3tip) {
+      var tip = d3tip()
+        .attr('class', 'd3-tip')
+        .html(function(d) { return '<span>' + d.total + '</span>' + ' entries' })
+        .offset([-12, 0])
+
+      var w = 800,
+          h = 300,
+          padt = 20, padr = 20, padb = 60, padl = 30,
+          x  = d3.scale.ordinal().rangeRoundBands([0, w - padl - padr], 0.1),
+          y  = d3.scale.linear().range([h, 0]),
+          yAxis = d3.svg.axis().scale(y).orient('left').tickSize(-w + padl + padr),
+          xAxis = d3.svg.axis().scale(x).orient('bottom')
+
+      vis = d3.select('#graph')
+        .append('svg')
+        .attr('width', w)
+        .attr('height', h + padt + padb)
+      .append('g')
+        .attr('transform', 'translate(' + padl + ',' + padt + ')')
+
+      var max = d3.max(data, function(d) { return d.total })
+      x.domain(d3.range(data.length))
+      y.domain([0, max])
+
+      vis.call(tip)
+      vis.append("g")
+        .attr("class", "y axis")
+        .call(yAxis)
+
+      vis.append("g")
+        .attr("class", "x axis")
+        .attr('transform', 'translate(0,' + h + ')')
+        .call(xAxis)
+        .selectAll('.x.axis g')
+          .style('display', function (d, i) { return i % 3 != 0  ? 'none' : 'block' })
+
+      var bars = vis.selectAll('g.bar')
+        .data(data)
+      .enter().append('g')
+        .attr('class', 'bar')
+        .attr('transform', function (d, i) { return "translate(" + x(i) + ", 0)" })
+
+      bars.append('rect')
+        .attr('width', function() { return x.rangeBand() })
+        .attr('height', function(d) { return h - y(d.total) })
+        .attr('y', function(d) { return y(d.total) })
+        .on('mouseover', tip.show)
+        .on('mouseout', tip.hide)
+    });
+  </script>
+  <div id="graph"></div>
+</body>
+</html>

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/d3-tip.js.git



More information about the Pkg-javascript-commits mailing list