forked from TomNeyland/angular-dc
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more name fixes, basic implementation of directive
- Loading branch information
1 parent
a236978
commit f3c5f1a
Showing
10 changed files
with
200 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
{ | ||
"name": "angular-dcjs", | ||
"name": "angular-dc", | ||
"version": "0.0.1", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"angular": "latest", | ||
"angular-mocks": "latest", | ||
"jquery": "latest", | ||
"lodash": "~2.4.1" | ||
"lodash": "~2.4.1", | ||
"dcjs": "master", | ||
"crossfilter": "~1.3.0" | ||
}, | ||
"resolutions": { | ||
"crossfilter": "~1.3.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
angular.module('angulaDc', []).directive('dcChart', function () { | ||
return { | ||
restrict: 'EAC', | ||
scope: {}, | ||
link: function (scope, iElement, iAttrs) { | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
/** | ||
* angular-dcjs | ||
* angular-dc | ||
* @version v0.0.1 - 2013-12-27 | ||
* @link https://github.com/TomNeyland/angular-dcjs | ||
* @link https://github.com/TomNeyland/angular-dc | ||
* @author Tom Neyland <> | ||
* @license Apache License, http://www.opensource.org/licenses/Apache | ||
*/ | ||
"use strict";angular.module("angulaDc",[]).directive("dcChart",function(){return{restrict:"EAC",scope:{},link:function(){}}}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
'use strict'; | ||
|
||
angular.module('angulaDc', []) | ||
|
||
.directive('dcChart', function() { | ||
|
||
var defaultOptions = { | ||
width: 200, | ||
height: 200 | ||
}; | ||
|
||
function setupChart(scope, iElement, iAttrs) { | ||
|
||
|
||
var chartElement = iElement[0], | ||
chartTypeName = iAttrs.dcChart || iAttrs.chartType, | ||
chartGroupName = iAttrs.chartGroup || undefined; | ||
|
||
var chartFactory = dc[chartTypeName]; | ||
|
||
var chart = chartFactory(chartElement, chartGroupName); | ||
|
||
// all chart options are exposed via a function | ||
var validOptions = _(chart).functions().value(); | ||
console.log(validOptions); | ||
|
||
var objOptions = getOptionsFromObject(scope, validOptions); | ||
var attrOptions = getOptionsFromAttrs(scope, iAttrs, validOptions); | ||
var scopeOptions = getOptionsFromScope(scope, validOptions); | ||
|
||
var options = _({}) | ||
.extend(defaultOptions, | ||
objOptions, | ||
attrOptions, | ||
scopeOptions) | ||
.value(); | ||
|
||
console.log(_.keys(options), options); | ||
chart.options(options); | ||
|
||
return chart; | ||
|
||
} | ||
|
||
function getOptionsFromObject(scope, validOptions) { | ||
var config = scope.config(); | ||
if (!_.isObject(config)) { | ||
config = {}; | ||
} | ||
return config; | ||
} | ||
|
||
function getOptionsFromAttrs(scope, iAttrs, validOptions) { | ||
return _(iAttrs.$attr) | ||
.keys() | ||
.intersection(validOptions) | ||
.map(function(key) { | ||
var value; | ||
try { | ||
value = scope.$parent.$eval(iAttrs[key]); | ||
} catch (e) { | ||
value = iAttrs[key]; | ||
} | ||
return [key, value]; | ||
}) | ||
.zipObject() | ||
.value(); | ||
} | ||
|
||
function getOptionsFromScope(scope, validOptions) { | ||
return _(scope).keys() | ||
.intersection(validOptions) | ||
.map(function(key) { | ||
return [key, _.result(scope, key)] | ||
}) | ||
.zipObject() | ||
.value(); | ||
} | ||
|
||
return { | ||
restrict: 'EAC', | ||
scope: { | ||
group: '&', | ||
dimension: '&', | ||
width: '=', | ||
height: '=', | ||
config: '&', | ||
}, | ||
template: '<svg></svg>', | ||
link: function(scope, iElement, iAttrs) { | ||
|
||
var chart = setupChart(scope, iElement, iAttrs); | ||
|
||
scope.$watch('options', function(oldValue, newValue) { | ||
if (oldValue === newValue) { | ||
return; | ||
} | ||
chart.options(newValue); | ||
}); | ||
|
||
chart.render(); | ||
|
||
} | ||
}; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
|
||
describe('Module: angulaDc', function () { | ||
var scope, $sandbox, $compile, $timeout; | ||
|
||
// load the controller's module | ||
beforeEach(module('angulaDc')); | ||
|
||
beforeEach(inject(function ($injector, $rootScope, _$compile_, _$timeout_) { | ||
scope = $rootScope; | ||
$compile = _$compile_; | ||
$timeout = _$timeout_; | ||
|
||
$sandbox = $('<div id="sandbox"></div>').appendTo($('body')); | ||
})); | ||
|
||
afterEach(function() { | ||
$sandbox.remove(); | ||
scope.$destroy(); | ||
}); | ||
|
||
var cf = crossfilter(); | ||
var d = cf.dimension(function(){return "test"}); | ||
var g = d.group(function(){return "bar"}); | ||
var templates = { | ||
'default': { | ||
scope: {d:d, g:g}, | ||
element: '<div width="200" config="222" dc-chart="pieChart" dimension="d" group="g"></div>' | ||
} | ||
}; | ||
|
||
function compileDirective(template) { | ||
template = template ? templates[template] : templates['default']; | ||
angular.extend(scope, template.scope || templates['default'].scope); | ||
var $element = $(template.element).appendTo($sandbox); | ||
$element = $compile($element)(scope); | ||
scope.$digest(); | ||
return $element; | ||
} | ||
|
||
it('chart elements should contain a single svg element', function () { | ||
var elm = compileDirective(); | ||
expect(elm.children().length).toBe(1); | ||
}); | ||
|
||
// it('chart elements should be 350px wide', function () { | ||
// var elm = compileDirective(); | ||
// expect(elm[0].children()).toBe(350); | ||
// }); | ||
|
||
}); |