Fixes for language and scaling

This commit is contained in:
Colin McLeod
2015-09-01 02:20:05 -07:00
parent bf217e7fdd
commit 65f53a3fa4
19 changed files with 696 additions and 568 deletions

View File

@@ -7,7 +7,8 @@ angular.module('app').directive('slider', ['$window', function($window) {
def: '=',
max: '=',
unit: '=',
change: '&onChange'
change: '&onChange',
ignoreResize: '='
},
link: function(scope, element) {
var unit = scope.unit,
@@ -16,7 +17,8 @@ angular.module('app').directive('slider', ['$window', function($window) {
h = height - margin.top,
fmt = d3.format('.2f'),
pct = d3.format('.1%'),
val = scope.def !== undefined ? scope.def : scope.max,
def = scope.def !== undefined ? scope.def : scope.max,
val = def,
svg = d3.select(element[0]).append('svg'),
vis = svg.append('g').attr('transform', 'translate(' + margin.left + ',' + margin.top + ')'),
xAxisContainer = vis.append('g').attr('class', 'x slider-axis').attr('transform', 'translate(0,' + h / 2 + ')'),
@@ -32,16 +34,6 @@ angular.module('app').directive('slider', ['$window', function($window) {
slider.select('.background').attr('height', h);
handle.attr('transform', 'translate(0,' + h / 2 + ')');
/**
* Watch for changes in the max, window size
*/
scope.$watch('max', function(newMax, oldMax) {
val = newMax * (val / oldMax); // Retain percentage filled
render();
});
//angular.element($window).bind('orientationchange resize', render);
function render() {
var width = element[0].offsetWidth, w = width - margin.left - margin.right;
svg.attr('width', width).attr('height', height);
@@ -51,16 +43,18 @@ angular.module('app').directive('slider', ['$window', function($window) {
xAxisContainer.call(xAxis.tickValues([0, scope.max / 4, scope.max / 2, (3 * scope.max) / 4, scope.max]));
lbl.attr('x', w + 20);
}
slider.call(brush.extent([val, val])).call(brush.event);
slider.call(brush.extent([val, val]));
drawBrush();
slider.selectAll('.extent,.resize').remove();
}
function brushed() {
val = brush.extent()[0];
if (d3.event.sourceEvent) { // not a programmatic event
val = x.invert(d3.mouse(this)[0]);
brush.extent([val, val]);
}
val = x.invert(d3.mouse(this)[0]);
brush.extent([val, val]);
drawBrush();
}
function drawBrush() {
if (unit) {
lbl.text(fmt(val) + ' ' + unit + ' ' + pct(val / scope.max));
}
@@ -69,6 +63,23 @@ angular.module('app').directive('slider', ['$window', function($window) {
filled.attr('d', 'M0,0V0H' + x(val) + 'V0');
}
/**
* Watch for changes in the max, window size
*/
scope.$watch('max', function(newMax, oldMax) {
val = newMax * (val / oldMax); // Retain percentage filled
render();
});
if (!scope.ignoreResize) {
angular.element($window).bind('orientationchange resize', render);
}
scope.$on('reset', function() {
val = def;
render();
});
scope.$on('$destroy', function() {
angular.element($window).unbind('orientationchange resize render', render);
});