Permalink
Browse files

Accept arbitrary scale function -- todo file issue

1 parent f889d40 commit 815373f836cf5e702044b292d3535492c5b49c77 @almossawi almossawi committed Dec 20, 2016
Showing with 34 additions and 12 deletions.
  1. +15 −4 dist/metricsgraphics.js
  2. +4 −4 dist/metricsgraphics.min.js
  3. +5 −3 src/js/common/scales.js
  4. +6 −1 src/js/common/y_axis.js
  5. +4 −0 src/js/misc/utility.js
@@ -459,6 +459,10 @@ function mg_is_array(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
}
+function mg_is_function(obj) {
+ return Object.prototype.toString.call(obj) === '[object Function]';
+}
+
// deep copy
// http://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object
MG.clone = function(obj) {
@@ -1622,9 +1626,11 @@ function MGScale(args) {
args.scales[scaleArgs.scale_name] = (scaleArgs.is_time_series)
? time_scale
- : (args[scaleArgs.namespace + '_scale_type'] === 'log')
- ? d3.scaleLog()
- : d3.scaleLinear();
+ : (mg_is_function(args[scaleArgs.namespace + '_scale_type']))
+ ? args.y_scale_type()
+ : (args[scaleArgs.namespace + '_scale_type'] === 'log')
+ ? d3.scaleLog()
+ : d3.scaleLinear();
args.scales[scaleArgs.scale_name].domain([args.processed['min_' + scaleArgs.namespace], args.processed['max_' + scaleArgs.namespace]]);
scaleArgs.scaleType = 'numerical';
@@ -2777,7 +2783,12 @@ function mg_y_domain_range (args, scale) {
}
function mg_define_y_scales (args) {
- var scale = args.y_scale_type === 'log' ? d3.scaleLog() : d3.scaleLinear();
+ var scale = (mg_is_function(args.y_scale_type))
+ ? args.y_scale_type()
+ : (args.y_scale_type === 'log')
+ ? d3.scaleLog()
+ : d3.scaleLinear();
+
if (args.y_scale_type === 'log') {
if (args.chart_type === 'histogram') {
// log histogram plots should start just below 1
Oops, something went wrong.
@@ -90,9 +90,11 @@ function MGScale(args) {
args.scales[scaleArgs.scale_name] = (scaleArgs.is_time_series)
? time_scale
- : (args[scaleArgs.namespace + '_scale_type'] === 'log')
- ? d3.scaleLog()
- : d3.scaleLinear();
+ : (mg_is_function(args[scaleArgs.namespace + '_scale_type']))
+ ? args.y_scale_type()
+ : (args[scaleArgs.namespace + '_scale_type'] === 'log')
+ ? d3.scaleLog()
+ : d3.scaleLinear();
args.scales[scaleArgs.scale_name].domain([args.processed['min_' + scaleArgs.namespace], args.processed['max_' + scaleArgs.namespace]]);
scaleArgs.scaleType = 'numerical';
@@ -907,7 +907,12 @@ function mg_y_domain_range (args, scale) {
}
function mg_define_y_scales (args) {
- var scale = args.y_scale_type === 'log' ? d3.scaleLog() : d3.scaleLinear();
+ var scale = (mg_is_function(args.y_scale_type))
+ ? args.y_scale_type()
+ : (args.y_scale_type === 'log')
+ ? d3.scaleLog()
+ : d3.scaleLinear();
+
if (args.y_scale_type === 'log') {
if (args.chart_type === 'histogram') {
// log histogram plots should start just below 1
@@ -448,6 +448,10 @@ function mg_is_array(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
}
+function mg_is_function(obj) {
+ return Object.prototype.toString.call(obj) === '[object Function]';
+}
+
// deep copy
// http://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object
MG.clone = function(obj) {

0 comments on commit 815373f

Please sign in to comment.