Skip to content

Commit

Permalink
fixes w3c#601. Removing clip path entirely from points for the moment…
Browse files Browse the repository at this point in the history
…. The clip path tends to cut off parts of points that are within the bounds but whose radius extends beyond the plot area.
  • Loading branch information
hamilton committed Feb 9, 2016
1 parent 8f59aa3 commit 8c02a48
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
24 changes: 20 additions & 4 deletions dist/metricsgraphics.js
Expand Up @@ -2051,8 +2051,8 @@ function mg_add_clip_path_for_plot_area (svg, args) {
.append('clipPath')
.attr('id', 'mg-plot-window-' + mg_target_ref(args.target))
.append('svg:rect')
.attr('x', args.left)
.attr('y', args.top)
.attr('x', mg_get_left(args))
.attr('y', mg_get_top(args))
.attr('width', args.width - args.left - args.right - args.buffer)
.attr('height', args.height - args.top - args.bottom - args.buffer + 1);
}
Expand Down Expand Up @@ -3877,6 +3877,19 @@ MG.button_layout = function(target) {
(function() {
'use strict';

function mg_filter_out_plot_bounds (data, args) {
// max_x, min_x, max_y, min_y;
var x = args.x_accessor;
var y = args.y_accessor;
var new_data = data.filter(function(d){
return (args.min_x === null || d[x] >= args.min_x) &&
(args.max_x === null || d[x] <= args.max_x) &&
(args.min_y === null || d[y] >= args.min_y) &&
(args.max_y === null || d[y] <= args.max_y);
})
return new_data;
}

function pointChart(args) {
this.init = function(args) {
this.args = args;
Expand Down Expand Up @@ -3908,6 +3921,8 @@ MG.button_layout = function(target) {
var svg = mg_get_svg_child_of(args.target);
var g;

var data = mg_filter_out_plot_bounds(args.data[0], args);
// console.log(data);
//remove the old points, add new one
svg.selectAll('.mg-points').remove();

Expand All @@ -3916,9 +3931,10 @@ MG.button_layout = function(target) {
.classed('mg-points', true);

var pts = g.selectAll('circle')
.data(args.data[0])
.data(data)
.enter().append('svg:circle')
.attr('class', function(d, i) { return 'path-' + i; })
//.attr('clip-path', 'url(#mg-plot-window-' + mg_target_ref(args.target) + ')')
.attr('cx', args.scalefns.xf)
.attr('cy', args.scalefns.yf);

Expand Down Expand Up @@ -3966,7 +3982,7 @@ MG.button_layout = function(target) {
.attr('class', 'mg-voronoi');

paths.selectAll('path')
.data(voronoi(args.data[0]))
.data(voronoi(mg_filter_out_plot_bounds(args.data[0], args)))
.enter().append('path')
.attr('d', function(d) {
if (d === undefined) {
Expand Down
4 changes: 2 additions & 2 deletions dist/metricsgraphics.min.js

Large diffs are not rendered by default.

20 changes: 18 additions & 2 deletions src/js/charts/point.js
Expand Up @@ -2,6 +2,19 @@
(function() {
'use strict';

function mg_filter_out_plot_bounds (data, args) {
// max_x, min_x, max_y, min_y;
var x = args.x_accessor;
var y = args.y_accessor;
var new_data = data.filter(function(d){
return (args.min_x === null || d[x] >= args.min_x) &&
(args.max_x === null || d[x] <= args.max_x) &&
(args.min_y === null || d[y] >= args.min_y) &&
(args.max_y === null || d[y] <= args.max_y);
})
return new_data;
}

function pointChart(args) {
this.init = function(args) {
this.args = args;
Expand Down Expand Up @@ -33,6 +46,8 @@
var svg = mg_get_svg_child_of(args.target);
var g;

var data = mg_filter_out_plot_bounds(args.data[0], args);
// console.log(data);
//remove the old points, add new one
svg.selectAll('.mg-points').remove();

Expand All @@ -41,9 +56,10 @@
.classed('mg-points', true);

var pts = g.selectAll('circle')
.data(args.data[0])
.data(data)
.enter().append('svg:circle')
.attr('class', function(d, i) { return 'path-' + i; })
//.attr('clip-path', 'url(#mg-plot-window-' + mg_target_ref(args.target) + ')')
.attr('cx', args.scalefns.xf)
.attr('cy', args.scalefns.yf);

Expand Down Expand Up @@ -91,7 +107,7 @@
.attr('class', 'mg-voronoi');

paths.selectAll('path')
.data(voronoi(args.data[0]))
.data(voronoi(mg_filter_out_plot_bounds(args.data[0], args)))
.enter().append('path')
.attr('d', function(d) {
if (d === undefined) {
Expand Down
4 changes: 2 additions & 2 deletions src/js/common/init.js
Expand Up @@ -69,8 +69,8 @@ function mg_add_clip_path_for_plot_area (svg, args) {
.append('clipPath')
.attr('id', 'mg-plot-window-' + mg_target_ref(args.target))
.append('svg:rect')
.attr('x', args.left)
.attr('y', args.top)
.attr('x', mg_get_left(args))
.attr('y', mg_get_top(args))
.attr('width', args.width - args.left - args.right - args.buffer)
.attr('height', args.height - args.top - args.bottom - args.buffer + 1);
}
Expand Down

0 comments on commit 8c02a48

Please sign in to comment.