diff --git a/Makefile b/Makefile index 13dfff4..2a43ebf 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ JS_FILES = \ - src/nvtooltip.js \ src/intro.js \ src/core.js \ + src/tooltip.js \ + src/utils.js \ src/models/legend.js \ src/models/xaxis.js \ src/models/yaxis.js \ diff --git a/build.bat b/build.bat new file mode 100644 index 0000000..22d4a67 --- /dev/null +++ b/build.bat @@ -0,0 +1,6 @@ +@echo off +copy src\intro.js /B + src\core.js /B + src\tooltip.js /B temp1.js /B +copy src\models\*.js /B + src\charts\*.js /B temp2.js /B +copy temp1.js /B + temp2.js /B + src\outro.js /B nv.d3.js /B +del temp1.js +del temp2.js diff --git a/examples/bar.html b/examples/bar.html index 18a979d..9f5ca2a 100644 --- a/examples/bar.html +++ b/examples/bar.html @@ -17,7 +17,6 @@ text { - - - + @@ -61,8 +60,8 @@ var cumulativeMonthEndTestData = [ nv.addGraph({ generate: function() { - var width = $(window).width() - 40, - height = $(window).height() - 40; + var width = nv.utils.windowSize().width - 40, + height = nv.utils.windowSize().height - 40; var chart = nv.models.cumulativeLine() .width(width) @@ -95,9 +94,9 @@ nv.addGraph({ callback: function(graph) { graph.dispatch.on('tooltipShow', function(e) { - var offset = $('#test1').offset(), - left = e.pos[0] + offset.left, - top = e.pos[1] + offset.top, + var offsetElement = document.getElementById("test1"), + left = e.pos[0] + offsetElement.offsetLeft, + top = e.pos[1] + offsetElement.offsetTop, formatterY = d3.format(",.2%"), formatterX = function(d) { return d3.time.format('%x')(new Date(d)) @@ -108,20 +107,19 @@ nv.addGraph({ formatterY(graph.y()(e.point)) + ' on ' + formatterX(graph.x()(e.point)) + '
'; - //$('#positionTest').css({'left': left, 'top': top}); - nvtooltip.show([left, top], content); + nv.tooltip.show([left, top], content); }); graph.dispatch.on('tooltipHide', function(e) { - nvtooltip.cleanup(); + nv.tooltip.cleanup(); }); - $(window).resize(function() { - var width = $(window).width() - 40, - height = $(window).height() - 40, - margin = graph.margin(); + window.onresize = function() { + var width = nv.utils.windowSize().width - 40, + height = nv.utils.windowSize().height - 40, + margin = graph.margin(); if (width < margin.left + margin.right + 20) @@ -140,7 +138,7 @@ nv.addGraph({ .attr('height', height) .call(graph); - }); + }; } }); diff --git a/examples/legend.html b/examples/legend.html index 3241992..cc2ddf8 100644 --- a/examples/legend.html +++ b/examples/legend.html @@ -9,7 +9,6 @@ - - @@ -24,8 +23,8 @@ body { //Format A nv.addGraph({ generate: function() { - var width = $(window).width() - 40, - height = $(window).height() - 40; + var width = nv.utils.windowSize().width - 40, + height = nv.utils.windowSize().height - 40; var chart = nv.models.line() .width(width) @@ -42,11 +41,11 @@ nv.addGraph({ return chart; }, callback: function(graph) { - $(window).resize(function() { - var width = $(window).width() - 40, - height = $(window).height() - 40, + window.onresize = function() { + var width = nv.utils.windowSize().width - 40, + height = nv.utils.windowSize().height - 40, margin = graph.margin(), - animate = graph.animate(); + animate = graph.animate(); if (width < margin.left + margin.right + 20) @@ -64,7 +63,7 @@ nv.addGraph({ .attr('width', width) .attr('height', height) .call(graph); - }); + }; } }); diff --git a/examples/lineChart.html b/examples/lineChart.html index f7ec53d..034e738 100644 --- a/examples/lineChart.html +++ b/examples/lineChart.html @@ -32,10 +32,10 @@ text { - + - + diff --git a/examples/lineWithFocus.html b/examples/lineWithFocus.html index b1465d2..0bc4c05 100644 --- a/examples/lineWithFocus.html +++ b/examples/lineWithFocus.html @@ -22,9 +22,8 @@ text { - - + @@ -42,10 +41,10 @@ text { nv.addGraph({ generate: function() { - var width = $(window).width() - 40, - height = $(window).height() - 40; + var width = nv.utils.windowSize().width - 40, + height = nv.utils.windowSize().height - 40; - var chart = nv.models.lineWithFocus() + var chart = nv.models.lineWithFocus() .width(width) .height(height) //.dotRadius(1) //TODO: fix this setting @@ -65,29 +64,29 @@ nv.addGraph({ callback: function(graph) { graph.dispatch.on('tooltipShow', function(e) { - var offset = $('#test1').offset(), - left = e.pos[0] + offset.left, - top = e.pos[1] + offset.top, - formatter = d3.format('.2r'); + var offsetElement = document.getElementById("test1"), + left = e.pos[0] + offsetElement.offsetLeft, + top = e.pos[1] + offsetElement.offsetTop, + formatter = d3.format('.2r'); var content = '' + formatter(graph.y()(e.point)) + ', ' + formatter(graph.x()(e.point)) + '
'; - nvtooltip.show([left, top], content); + nv.tooltip.show([left, top], content); }); graph.dispatch.on('tooltipHide', function(e) { - nvtooltip.cleanup(); + nv.tooltip.cleanup(); }); - $(window).resize(function() { - var width = $(window).width() - 40, - height = $(window).height() - 40, - margin = graph.margin(); + window.onresize = function() { + var width = nv.utils.windowSize().width - 40, + height = nv.utils.windowSize().height - 40, + margin = graph.margin(); if (width < margin.left + margin.right + 20) @@ -106,7 +105,7 @@ nv.addGraph({ .attr('height', height) .call(graph); - }); + }; } }); diff --git a/examples/lineWithLegend.html b/examples/lineWithLegend.html index 5d200f9..cc280ae 100644 --- a/examples/lineWithLegend.html +++ b/examples/lineWithLegend.html @@ -32,9 +32,8 @@ text { - - + @@ -86,33 +85,34 @@ nv.addGraph({ }, callback: function(chart) { var showTooltip = function(e) { - var offset = $(selector).offset(), - left = e.pos[0] + offset.left, - top = e.pos[1] + offset.top, - formatY = chart.yAxis.tickFormat(), //Assumes using same format as axis, can customize to show higher precision, etc. + var offsetElement = document.getElementById(selector.substr(1)), + left = e.pos[0] + offsetElement.offsetLeft, + top = e.pos[1] + offsetElement.offsetTop, + + formatY = chart.yAxis.tickFormat(), //Assumes using same format as axis, can customize to show higher precision, etc. formatX = chart.xAxis.tickFormat(); - // uses the chart's getX and getY, you may customize if x position is not the same as the value you want + // uses the chart's getX and getY, you may customize if x position is not the same as the value you want // ex. daily data without weekends, x is the index, while you want the date var content = '' + formatY(chart.y()(e.point)) + ' at ' + formatX(chart.x()(e.point)) + '
'; - nvtooltip.show([left, top], content); + nv.tooltip.show([left, top], content); }; chart.dispatch.on('tooltipShow', showTooltip); - chart.dispatch.on('tooltipHide', nvtooltip.cleanup); + chart.dispatch.on('tooltipHide', nv.tooltip.cleanup); - $(window).resize(function() { + window.onresize= function() { // now that width and height are functions, should be automatic..of course you can always override them d3.select('#chart1 svg') .attr('width', chart.width()()) //need to set SVG dimensions, chart is not aware of the SVG component .attr('height', chart.height()()) .call(chart); - }); + }; } }); diff --git a/examples/monthendAxis.html b/examples/monthendAxis.html index 0017d85..7f9a89a 100644 --- a/examples/monthendAxis.html +++ b/examples/monthendAxis.html @@ -9,7 +9,6 @@ - - @@ -23,10 +22,10 @@ body { //Format A nv.addGraph({ generate: function() { - var width = $(window).width() - 40, - height = $(window).height() - 40; + var width = nv.utils.windowSize().width - 40, + height = nv.utils.windowSize().height - 40; - var chart = nv.models.scatter() + var chart = nv.models.scatter() .width(width) .height(height) .margin({top: 20, right: 20, bottom: 20, left: 20}) @@ -42,10 +41,10 @@ nv.addGraph({ return chart; }, callback: function(graph) { - $(window).resize(function() { - var width = $(window).width() - 40, - height = $(window).height() - 40, - margin = graph.margin(); + window.onresize = function() { + var width = nv.utils.windowSize().width - 40, + height = nv.utils.windowSize().height - 40, + margin = graph.margin(); if (width < margin.left + margin.right + 20) @@ -64,7 +63,7 @@ nv.addGraph({ .attr('height', height) .call(graph); - }); + }; } }); diff --git a/examples/scatterWithLegend.html b/examples/scatterWithLegend.html index e0081f2..b893add 100644 --- a/examples/scatterWithLegend.html +++ b/examples/scatterWithLegend.html @@ -41,9 +41,8 @@ div { - - + @@ -56,10 +55,10 @@ div { //Format A nv.addGraph({ generate: function() { - var width = $(window).width() - 20, - height = $(window).height() - 20; + var width = nv.utils.windowSize().width - 40, + height = nv.utils.windowSize().height - 40; - var chart = nv.models.scatterWithLegend() + var chart = nv.models.scatterWithLegend() .width(width) .height(height) //.width(width) @@ -87,10 +86,10 @@ nv.addGraph({ callback: function(graph) { graph.dispatch.on('tooltipShow', function(e) { - var offset = $('#test1').offset(), - left = e.pos[0] + offset.left, - top = e.pos[1] + offset.top, - formatter = d3.format(".2f"); + var offsetElement = document.getElementById("test1"), + left = e.pos[0] + offsetElement.offsetLeft, + top = e.pos[1] + offsetElement.offsetTop, + formatter = d3.format(".2f"); /* @@ -105,20 +104,22 @@ nv.addGraph({ var contentX = '' + formatter(e.point.x) + ''; var contentY = '' + formatter(e.point.y) + ''; - nvtooltip.show([left, $(window).height() - 30], contentX, 'n', 1); - nvtooltip.show([5, top], contentY, 'w', 1); + var height = nv.utils.windowSize().height - 40; + + nv.tooltip.show([left, height - 50], contentX, 'n', 1); + nv.tooltip.show([5, top], contentY, 'w', 1); }); graph.dispatch.on('tooltipHide', function(e) { - nvtooltip.cleanup(); + nv.tooltip.cleanup(); }); - $(window).resize(function() { - var width = $(window).width() - 20, - height = $(window).height() - 20, - margin = graph.margin(), - animate = graph.animate(); + window.onresize = function() { + var width = nv.utils.windowSize().width - 40, + height = nv.utils.windowSize().height - 40, + margin = graph.margin(), + animate = graph.animate(); if (width < margin.left + margin.right + 20) @@ -137,7 +138,7 @@ nv.addGraph({ .attr('height', height) .call(graph); - }); + }; } }); diff --git a/examples/sparkline.html b/examples/sparkline.html index bc78b69..835cbf4 100644 --- a/examples/sparkline.html +++ b/examples/sparkline.html @@ -18,7 +18,6 @@ text {' + formatterY(chart.y()(e.point)) + ' on ' + formatterX(chart.x()(e.point)) + '
'; - nvtooltip.show([left, top], content); + nv.tooltip.show([left, top], content); }); chart.dispatch.on('tooltipHide', function(e) { - nvtooltip.cleanup(); + nv.tooltip.cleanup(); }); -$(window).resize(function() { +window.onresize = function() { d3.select('#chart svg') .attr('width', width()) .attr('height', height()) .call(chart); -}); +}; diff --git a/lib/d3.v2.min.js b/lib/d3.v2.min.js index dddd929..521c420 100644 --- a/lib/d3.v2.min.js +++ b/lib/d3.v2.min.js @@ -1,4 +1,4 @@ -(function(){function e(a,b){try{for(var c in b)Object.defineProperty(a.prototype,c,{value:b[c],enumerable:!1})}catch(d){a.prototype=b}}function g(a){var b=-1,c=a.length,d=[];while(++bt |