Skip to content

Commit 03fded2

Browse files
author
Chris Maurer
committed
moved duplicate code for margin, height, width into one method.
1 parent 4c92135 commit 03fded2

File tree

9 files changed

+255
-152
lines changed

9 files changed

+255
-152
lines changed

bower.json

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@
22
"name": "angularjs-nvd3-directives",
33
"version": "0.0.0",
44
"description": "Angular.js directives for nvd3.js.",
5-
"author": "https://github.com/cmaurer/angularjs-nvd3-directives/graphs/contributors",
6-
"license": "Apache",
5+
"authors": [
6+
"Christian Maurer"
7+
],
8+
"license": "Apache License, v2.0",
79
"homepage": "http://cmaurer.github.io/angularjs-nvd3-directives/",
810
"main": "./dist/angularjs-nvd3-directives.js",
9-
"ignore": [
11+
"keywords": [
12+
"d3",
13+
"nvd3",
14+
"angular",
15+
"directives",
16+
"visualization",
17+
"svg",
18+
"charts"
19+
],
20+
"ignore": [
1021
"**/.*",
1122
"node_modules",
1223
"bower_components",
@@ -15,8 +26,8 @@
1526
],
1627
"dependencies": {
1728
"angular": "~1.0.8",
18-
"nvd3": "*",
19-
"d3": "~3.3.6",
20-
"moment": "~2.2.1"
29+
"d3": "~3.3.5",
30+
"nvd3": "~v1.1.13-beta",
31+
"moment": "~2.3.0"
2132
}
2233
}

dist/angularjs-nvd3-directives.js

Lines changed: 33 additions & 69 deletions
Large diffs are not rendered by default.

examples/bulletChart.html

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@
1414

1515
function ExampleCtrl($scope){
1616

17-
$scope.exampleData = {"title":"Revenue","subtitle":"US$, in thousands","ranges":[150,225,300],"measures":[220],"markers":[250]};
17+
// $scope.exampleData = {"title":"Revenue","subtitle":"US$, in thousands","ranges":[50,200,275],"measures":[220],"markers":[250]};
18+
$scope.exampleData = {"title":"Revenue","subtitle":"US$, in thousands","measures":[220],"markers":[250]};
19+
20+
$scope.rangesFunction = function(){
21+
console.log('rangesFunction called');
22+
return function(d){
23+
return [50,100,200];
24+
}
25+
}
1826

1927
}
2028
</script>
@@ -29,7 +37,8 @@
2937
width="800"
3038
height="100"
3139
tooltips="true"
32-
margin="{left:150,top:10,bottom:10,right:10}">
40+
margin="{left:150,top:10,bottom:10,right:10}"
41+
ranges="rangesFunction()">
3342
<svg></svg>
3443
</nvd3-bullet-chart>
3544

examples/js/nv.d3.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,6 +2405,7 @@ nv.models.bulletChart = function() {
24052405

24062406
// ranges (bad, satisfactory, good)
24072407
chart.ranges = function(x) {
2408+
console.log('bullet chart ranges', x);
24082409
if (!arguments.length) return ranges;
24092410
ranges = x;
24102411
return chart;

examples/legendDirective.html

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<html>
4+
<head>
5+
<title>Angular.js nvd3.js Legend Directive</title>
6+
<meta http-equiv="content-type" content="text/html; charset=UTF8">
7+
<script src="js/angular.js"></script>
8+
<script src="js/d3.js"></script>
9+
<script src="js/nv.d3.js"></script>
10+
<script src="js/moment.js"></script>
11+
<script src="../dist/angularjs-nvd3-directives.js"></script>
12+
<script src="../src/directives/legendDirectives.js"></script>
13+
<link rel="stylesheet" href="stylesheets/nv.d3.css"/>
14+
<style>
15+
16+
.legend-bullet-1 {
17+
fill: gray;
18+
}
19+
.legend-bullet-2 {
20+
fill: blue;
21+
}
22+
.legend-bullet-3 {
23+
fill: red;
24+
}
25+
</style>
26+
<script>
27+
var app = angular.module("legendTestApp", ['legendDirectives']);
28+
29+
function LegendController($scope){
30+
31+
32+
33+
}
34+
35+
</script>
36+
37+
</head>
38+
<body ng-app='legendTestApp'>
39+
<div ng-controller="LegendController">
40+
<simple-svg-legend
41+
width="50"
42+
height="20"
43+
labels="['label1', 'label2', 'label 3']"
44+
classes="['legend-bullet-1','legend-bullet-2','legend-bullet-3']"
45+
shapes="['circle','circle', 'circle']"
46+
columns="3"
47+
x="10"
48+
y="0">
49+
</simple-svg-legend>
50+
</div>
51+
52+
</body>
53+
</html>

examples/lineChart.d3.native.html

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<!DOCTYPE html>
2+
<meta charset="utf-8">
3+
<html>
4+
<head>
5+
<title>Line Chart d3.js Native</title>
6+
<meta http-equiv="content-type" content="text/html; charset=UTF8">
7+
<script src="js/d3.js"></script>
8+
<script src="js/nv.d3.js"></script>
9+
<script src="js/moment.js"></script>
10+
<link rel="stylesheet" href="stylesheets/nv.d3.css"/>
11+
12+
<style>
13+
14+
path {
15+
stroke: steelblue;
16+
stroke-width: 2;
17+
fill: none;
18+
}
19+
20+
.axis path,
21+
.axis line {
22+
fill: none;
23+
stroke: grey;
24+
stroke-width: 1;
25+
shape-rendering: crispEdges;
26+
}
27+
28+
</style>
29+
30+
31+
</head>
32+
<body>
33+
34+
<script>
35+
var data = [[ 1025409600000 , 0] , [ 1028088000000 , -6.3382185140371] , [ 1030766400000 , -5.9507873460847] , [ 1033358400000 , -11.569146943813] , [ 1036040400000 , -5.4767332317425] , [ 1038632400000 , 0.50794682203014] , [ 1041310800000 , -5.5310285460542] , [ 1043989200000 , -5.7838296963382] , [ 1046408400000 , -7.3249341615649] , [ 1049086800000 , -6.7078630712489] , [ 1051675200000 , 0.44227126150934] , [ 1054353600000 , 7.2481659343222] , [ 1056945600000 , 9.2512381306992] , [ 1059624000000 , 11.341210982529] , [ 1062302400000 , 14.734820409020] , [ 1064894400000 , 12.387148007542] , [ 1067576400000 , 18.436471461827] , [ 1070168400000 , 19.830742266977] , [ 1072846800000 , 22.643205829887] , [ 1075525200000 , 26.743156781239] , [ 1078030800000 , 29.597478802228] , [ 1080709200000 , 30.831697585341] , [ 1083297600000 , 28.054068024708] , [ 1085976000000 , 29.294079423832] , [ 1088568000000 , 30.269264061274] , [ 1091246400000 , 24.934526898906] , [ 1093924800000 , 24.265982759406] , [ 1096516800000 , 27.217794897473] , [ 1099195200000 , 30.802601992077] , [ 1101790800000 , 36.331003758254] , [ 1104469200000 , 43.142498700060] , [ 1107147600000 , 40.558263931958] , [ 1109566800000 , 42.543622385800] , [ 1112245200000 , 41.683584710331] , [ 1114833600000 , 36.375367302328] , [ 1117512000000 , 40.719688980730] , [ 1120104000000 , 43.897963036919] , [ 1122782400000 , 49.797033975368] , [ 1125460800000 , 47.085993935989] , [ 1128052800000 , 46.601972859745] , [ 1130734800000 , 41.567784572762] , [ 1133326800000 , 47.296923737245] , [ 1136005200000 , 47.642969612080] , [ 1138683600000 , 50.781515820954] , [ 1141102800000 , 52.600229204305] , [ 1143781200000 , 55.599684490628] , [ 1146369600000 , 57.920388436633] , [ 1149048000000 , 53.503593218971] , [ 1151640000000 , 53.522973979964] , [ 1154318400000 , 49.846822298548] , [ 1156996800000 , 54.721341614650] , [ 1159588800000 , 58.186236223191] , [ 1162270800000 , 63.908065540997] , [ 1164862800000 , 69.767285129367] , [ 1167541200000 , 72.534013373592] , [ 1170219600000 , 77.991819436573] , [ 1172638800000 , 78.143584404990] , [ 1175313600000 , 83.702398665233] , [ 1177905600000 , 91.140859312418] , [ 1180584000000 , 98.590960607028] , [ 1183176000000 , 96.245634754228] , [ 1185854400000 , 92.326364432615] , [ 1188532800000 , 97.068765332230] , [ 1191124800000 , 105.81025556260] , [ 1193803200000 , 114.38348777791] , [ 1196398800000 , 103.59604949810] , [ 1199077200000 , 101.72488429307] , [ 1201755600000 , 89.840147735028] , [ 1204261200000 , 86.963597532664] , [ 1206936000000 , 84.075505208491] , [ 1209528000000 , 93.170105645831] , [ 1212206400000 , 103.62838083121] , [ 1214798400000 , 87.458241365091] , [ 1217476800000 , 85.808374141319] , [ 1220155200000 , 93.158054469193] , [ 1222747200000 , 65.973252382360] , [ 1225425600000 , 44.580686638224] , [ 1228021200000 , 36.418977140128] , [ 1230699600000 , 38.727678144761] , [ 1233378000000 , 36.692674173387] , [ 1235797200000 , 30.033022809480] , [ 1238472000000 , 36.707532162718] , [ 1241064000000 , 52.191457688389] , [ 1243742400000 , 56.357883979735] , [ 1246334400000 , 57.629002180305] , [ 1249012800000 , 66.650985790166] , [ 1251691200000 , 70.839243432186] , [ 1254283200000 , 78.731998491499] , [ 1256961600000 , 72.375528540349] , [ 1259557200000 , 81.738387881630] , [ 1262235600000 , 87.539792394232] , [ 1264914000000 , 84.320762662273] , [ 1267333200000 , 90.621278391889] , [ 1270008000000 , 102.47144881651] , [ 1272600000000 , 102.79320353429] , [ 1275278400000 , 90.529736050479] , [ 1277870400000 , 76.580859994531] , [ 1280548800000 , 86.548979376972] , [ 1283227200000 , 81.879653334089] , [ 1285819200000 , 101.72550015956] , [ 1288497600000 , 107.97964852260] , [ 1291093200000 , 106.16240630785] , [ 1293771600000 , 114.84268599533] , [ 1296450000000 , 121.60793322282] , [ 1298869200000 , 133.41437346605] , [ 1301544000000 , 125.46646042904] , [ 1304136000000 , 129.76784954301] , [ 1306814400000 , 128.15798861044] , [ 1309406400000 , 121.92388706072] , [ 1312084800000 , 116.70036100870] , [ 1314763200000 , 88.367701837033] , [ 1317355200000 , 59.159665765725] , [ 1320033600000 , 79.793568139753] , [ 1322629200000 , 75.903834028417] , [ 1325307600000 , 72.704218209157] , [ 1327986000000 , 84.936990804097] , [ 1330491600000 , 93.388148670744]];
36+
37+
var margin = {left:50, top:50, bottom:50, right:50}, width = 400 - (margin.left - margin.right), height = 200 - (margin.top - margin.bottom);
38+
var x = d3.time.scale().range([0,width]);
39+
var y = d3.scale.linear().range([height,0]);
40+
41+
var xAxis = d3.svg.axis().scale(x).orient('bottom').ticks(5);
42+
var yAxis = d3.svg.axis().scale(y).orient('left').ticks(5);
43+
44+
var valueLine = d3.svg.line()
45+
.x(function(d){ return x(d[0]); })
46+
.y(function(d){ return y(d[1]); });
47+
48+
var svg = d3.select('body')
49+
.append('svg')
50+
.attr('width', width + margin.left + margin.right)
51+
.attr('height', height + margin.top + margin.bottom)
52+
.append('g')
53+
.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')')
54+
55+
56+
x.domain(d3.extent(data, function(d){ return d[0]; } ));
57+
y.domain([0, d3.max(data, function(d){ return d[1]; } )]);
58+
59+
svg.selectAll('path').data(valueLine(data))
60+
.enter()
61+
.append('path')
62+
// .attr('d', function(d){
63+
// return d;
64+
// });
65+
66+
svg.append('g')
67+
.attr('class', 'x axis')
68+
.attr('transform', 'translate(0,' + height + ')')
69+
.call(xAxis);
70+
71+
svg.append('g')
72+
.attr('class', 'y axis')
73+
.call(yAxis);
74+
75+
76+
setInterval(function(){
77+
data.push([(data[data.length-1][0] + 2505600000), Math.random()]);
78+
data.shift()
79+
80+
d3.select('svg').datum(data);
81+
console.log('update');
82+
}, 5000)
83+
84+
85+
</script>
86+
87+
88+
</body>
89+
</html>

examples/lineChart.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
"values": [ [ 1025409600000 , 0] , [ 1028088000000 , -6.3382185140371] , [ 1030766400000 , -5.9507873460847] , [ 1033358400000 , -11.569146943813] , [ 1036040400000 , -5.4767332317425] , [ 1038632400000 , 0.50794682203014] , [ 1041310800000 , -5.5310285460542] , [ 1043989200000 , -5.7838296963382] , [ 1046408400000 , -7.3249341615649] , [ 1049086800000 , -6.7078630712489] , [ 1051675200000 , 0.44227126150934] , [ 1054353600000 , 7.2481659343222] , [ 1056945600000 , 9.2512381306992] , [ 1059624000000 , 11.341210982529] , [ 1062302400000 , 14.734820409020] , [ 1064894400000 , 12.387148007542] , [ 1067576400000 , 18.436471461827] , [ 1070168400000 , 19.830742266977] , [ 1072846800000 , 22.643205829887] , [ 1075525200000 , 26.743156781239] , [ 1078030800000 , 29.597478802228] , [ 1080709200000 , 30.831697585341] , [ 1083297600000 , 28.054068024708] , [ 1085976000000 , 29.294079423832] , [ 1088568000000 , 30.269264061274] , [ 1091246400000 , 24.934526898906] , [ 1093924800000 , 24.265982759406] , [ 1096516800000 , 27.217794897473] , [ 1099195200000 , 30.802601992077] , [ 1101790800000 , 36.331003758254] , [ 1104469200000 , 43.142498700060] , [ 1107147600000 , 40.558263931958] , [ 1109566800000 , 42.543622385800] , [ 1112245200000 , 41.683584710331] , [ 1114833600000 , 36.375367302328] , [ 1117512000000 , 40.719688980730] , [ 1120104000000 , 43.897963036919] , [ 1122782400000 , 49.797033975368] , [ 1125460800000 , 47.085993935989] , [ 1128052800000 , 46.601972859745] , [ 1130734800000 , 41.567784572762] , [ 1133326800000 , 47.296923737245] , [ 1136005200000 , 47.642969612080] , [ 1138683600000 , 50.781515820954] , [ 1141102800000 , 52.600229204305] , [ 1143781200000 , 55.599684490628] , [ 1146369600000 , 57.920388436633] , [ 1149048000000 , 53.503593218971] , [ 1151640000000 , 53.522973979964] , [ 1154318400000 , 49.846822298548] , [ 1156996800000 , 54.721341614650] , [ 1159588800000 , 58.186236223191] , [ 1162270800000 , 63.908065540997] , [ 1164862800000 , 69.767285129367] , [ 1167541200000 , 72.534013373592] , [ 1170219600000 , 77.991819436573] , [ 1172638800000 , 78.143584404990] , [ 1175313600000 , 83.702398665233] , [ 1177905600000 , 91.140859312418] , [ 1180584000000 , 98.590960607028] , [ 1183176000000 , 96.245634754228] , [ 1185854400000 , 92.326364432615] , [ 1188532800000 , 97.068765332230] , [ 1191124800000 , 105.81025556260] , [ 1193803200000 , 114.38348777791] , [ 1196398800000 , 103.59604949810] , [ 1199077200000 , 101.72488429307] , [ 1201755600000 , 89.840147735028] , [ 1204261200000 , 86.963597532664] , [ 1206936000000 , 84.075505208491] , [ 1209528000000 , 93.170105645831] , [ 1212206400000 , 103.62838083121] , [ 1214798400000 , 87.458241365091] , [ 1217476800000 , 85.808374141319] , [ 1220155200000 , 93.158054469193] , [ 1222747200000 , 65.973252382360] , [ 1225425600000 , 44.580686638224] , [ 1228021200000 , 36.418977140128] , [ 1230699600000 , 38.727678144761] , [ 1233378000000 , 36.692674173387] , [ 1235797200000 , 30.033022809480] , [ 1238472000000 , 36.707532162718] , [ 1241064000000 , 52.191457688389] , [ 1243742400000 , 56.357883979735] , [ 1246334400000 , 57.629002180305] , [ 1249012800000 , 66.650985790166] , [ 1251691200000 , 70.839243432186] , [ 1254283200000 , 78.731998491499] , [ 1256961600000 , 72.375528540349] , [ 1259557200000 , 81.738387881630] , [ 1262235600000 , 87.539792394232] , [ 1264914000000 , 84.320762662273] , [ 1267333200000 , 90.621278391889] , [ 1270008000000 , 102.47144881651] , [ 1272600000000 , 102.79320353429] , [ 1275278400000 , 90.529736050479] , [ 1277870400000 , 76.580859994531] , [ 1280548800000 , 86.548979376972] , [ 1283227200000 , 81.879653334089] , [ 1285819200000 , 101.72550015956] , [ 1288497600000 , 107.97964852260] , [ 1291093200000 , 106.16240630785] , [ 1293771600000 , 114.84268599533] , [ 1296450000000 , 121.60793322282] , [ 1298869200000 , 133.41437346605] , [ 1301544000000 , 125.46646042904] , [ 1304136000000 , 129.76784954301] , [ 1306814400000 , 128.15798861044] , [ 1309406400000 , 121.92388706072] , [ 1312084800000 , 116.70036100870] , [ 1314763200000 , 88.367701837033] , [ 1317355200000 , 59.159665765725] , [ 1320033600000 , 79.793568139753] , [ 1322629200000 , 75.903834028417] , [ 1325307600000 , 72.704218209157] , [ 1327986000000 , 84.936990804097] , [ 1330491600000 , 93.388148670744]]
2121
}];
2222

23+
$scope.$on('beforeUpdate.directive', function(event){
24+
25+
});
2326

24-
setInterval(function(){ console.log(nv) },5000);
2527
}
2628
</script>
2729

package.json

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "angularjs-nvd3-directives",
33
"version": "0.0.0",
4+
"homepage": "http://cmaurer.github.io/angularjs-nvd3-directives",
45
"description": "Angular.js directives for nvd3",
5-
"main": "index.js",
6+
"main": "dist/angularjs-nvd3-directives.js",
67
"directories": {
78
"example": "examples",
89
"test": "test"
@@ -18,12 +19,18 @@
1819
"angular.js",
1920
"nvd3.js",
2021
"d3.js",
21-
"directives"
22+
"directives",
23+
"d3",
24+
"nvd3",
25+
"angular",
26+
"visualization",
27+
"svg",
28+
"charts"
2229
],
2330
"author": {
2431
"name": "Christian Maurer"
2532
},
26-
"license": "Apache",
33+
"license": "Apache License, v2.0",
2734
"readmeFilename": "README.md",
2835
"gitHead": "82273b2c5a38c9e5841e767da4f3252ba31927e8",
2936
"bugs": {
@@ -32,9 +39,9 @@
3239
"devDependencies": {
3340
"grunt": "~0.4.1",
3441
"grunt-contrib-concat": "~0.3.0",
35-
"grunt-contrib-uglify": "~0.2.2",
36-
"grunt-contrib-jshint": "~0.6.2",
37-
"grunt-contrib-watch": "~0.5.1",
42+
"grunt-contrib-uglify": "~0.2.4",
43+
"grunt-contrib-jshint": "~0.6.4",
44+
"grunt-contrib-watch": "~0.5.3",
3845
"grunt-contrib-clean": "~0.5.0",
3946
"grunt-cli": "~0.1.9",
4047
"grunt-bower-task": "~0.3.2",

0 commit comments

Comments
 (0)