-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change some syntax to ES6 & fix some obvious problems
- Loading branch information
Showing
5 changed files
with
107 additions
and
73 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
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,64 +1,71 @@ | ||
function mg_filter_in_range_data(args, range) { | ||
function is_data_in_range(data, range) { | ||
{ | ||
|
||
const filter_in_range_data = (args, range) => { | ||
const is_data_in_range = (data, range) => { | ||
return data > Math.min(range[0], range[1]) && data < Math.max(range[0], range[1]); | ||
} | ||
|
||
return function(d) { | ||
var x_in_range = ('x' in range) ? is_data_in_range(d[args.x_accessor], range.x) : true; | ||
var y_in_range = ('y' in range) ? is_data_in_range(d[args.y_accessor], range.y) : true; | ||
return d => { | ||
const x_in_range = !('x' in range) || is_data_in_range(d[args.x_accessor], range.x); | ||
const y_in_range = !('y' in range) || is_data_in_range(d[args.y_accessor], range.y); | ||
return x_in_range && y_in_range; | ||
} | ||
} | ||
|
||
function mg_zoom_to_data_domain(args, range) { | ||
var raw_data = args.raw_data || args.data; | ||
const zoom_to_data_domain = (args, range) => { | ||
const raw_data = args.raw_data || args.data; | ||
if (!('raw_data' in args)) { | ||
args.raw_domain = { | ||
x: args.scales.X.domain(), | ||
y: args.scales.Y.domain(), | ||
} | ||
}; | ||
args.raw_data = raw_data; | ||
} | ||
if (args.chart_type === 'point') { | ||
if (is_array_of_arrays(raw_data)) { | ||
args.data = raw_data.map(function(d) { | ||
return d.filter(mg_filter_in_range_data(args, range)); | ||
}) | ||
return d.filter(filter_in_range_data(args, range)); | ||
}); | ||
} else { | ||
args.data = raw_data.filter(mg_filter_in_range_data(args, range)); | ||
args.data = raw_data.filter(filter_in_range_data(args, range)); | ||
} | ||
} | ||
if ('x' in range) args.processed.zoom_x = range.x; | ||
else delete args.processed.zoom_x; | ||
if ('y' in range) args.processed.zoom_y = range.y; | ||
else delete args.processed.zoom_y; | ||
new MG.charts[args.chart_type || defaults.chart_type].descriptor(args); | ||
} | ||
|
||
function mg_zoom_to_raw_range(args) { | ||
const zoom_to_raw_range = args => { | ||
if (!('raw_domain' in args)) return; | ||
var range = args.raw_domain; | ||
mg_zoom_to_data_domain(args, range); | ||
const range = args.raw_domain; | ||
zoom_to_data_domain(args, range); | ||
delete args.raw_domain; | ||
delete args.raw_data; | ||
} | ||
|
||
function mg_convert_range_to_domain(args, range) { | ||
var domain = {}; | ||
const convert_range_to_domain = (args, range) => { | ||
const domain = {}; | ||
if ('x' in range) { | ||
var xScale = args.scales.X; | ||
domain.x = []; | ||
domain.x[0] = +xScale.invert(range.x[0]); | ||
domain.x[1] = +xScale.invert(range.x[1]); | ||
const xScale = args.scales.X; | ||
domain.x = range.x.map(v => +xScale.invert(v)); | ||
} | ||
if ('y' in range) { | ||
var yScale = args.scales.Y; | ||
domain.y = []; | ||
domain.y[0] = +yScale.invert(range.y[1]); | ||
domain.y[1] = +yScale.invert(range.y[0]); | ||
const yScale = args.scales.Y; | ||
domain.y = range.y.map(v => +yScale.invert(v)).reverse(); | ||
} | ||
return domain; | ||
} | ||
|
||
function mg_zoom_to_data_range(args, range) { | ||
var domain = mg_convert_range_to_domain(args, range) | ||
mg_zoom_to_data_domain(args, domain); | ||
const zoom_to_data_range = (args, range) => { | ||
const domain = convert_range_to_domain(args, range); | ||
zoom_to_data_domain(args, domain); | ||
} | ||
|
||
MG.convert_range_to_domain = convert_range_to_domain; | ||
MG.zoom_to_data_domain = zoom_to_data_domain; | ||
MG.zoom_to_data_range = zoom_to_data_range; | ||
MG.zoom_to_raw_range = zoom_to_raw_range; | ||
|
||
} |