简体   繁体   English

检测圆的重叠并将xaxis域从(0,max)更改为(min,max)

[英]detect overlapping of circle and change xaxis domain from (0,max) to (min,max)

I created a scatter plot bubble chart. 我创建了一个散点图气泡图。 these are two scenarios 这是两种情况

first because the difference between total customer is very less both circle are overlapped 首先是因为总客户之间的差异非常小,两个圆圈重叠

首先是因为总客户之间的差异非常小,两个圆圈重叠

second domain is from 0,max 第二个域从0,max开始 第二个域从0,max开始

I want a way so that it automatically reads if any two circle are overlapping then domain of xaxis should be min,max else it should be 0,max 我想要一种方法,以便它自动读取是否有任何两个圆圈重叠,则xaxis的域应为min,max,否则应为0,max

I am creating the bubble chart like this 我正在这样创建气泡图

var gnodes = svg.selectAll('g.node')
                    .data(this.options.data.events)
                    .enter()
                    .append('g')
                    .classed('gnode', true)
                    .attr("transform", function(d) { return "translate(" +  x(d.Total_Customers) + "," +  y(d.TotalSales) + ")"; })
                    .on('mouseover', tip.show)
                    .on('mouseout', tip.hide);
        var circles = gnodes.append("circle").transition().duration(transTime).style("filter","url(#drop-shadow)")
                        .attr("class", "node").style("fill", function(d) { return color(d.Total_visits);})
                        .attr("r", function(d,i){ return r(d.Total_visits);});

here is my xaxis 这是我的xaxis

getX: function(){
        var temp = 0//this.getMinX();
        return d3.scale.linear().range([0, this.options.width]).domain([temp,this.getMaxX()]);
    }

!! !! NOTE: my bubble chart implementation is not based on cx and cy. 注意:我的气泡图实现不是基于cx和cy。 its g being translated. 它的g正在翻译。 in this implementation I want to know the way to find out overlapping. 在此实现中,我想知道找出重叠的方法。

https://stackoverflow.com/a/8367547/3513695 https://stackoverflow.com/a/8367547/3513695

The above algorithm will solve your problem.The following is a function that will find the min value of the domain required as per your requirements 上面的算法将解决您的问题。下面的函数将根据您的要求查找所需域的最小值

var getDomainMinValue = function(data){
   var radiiDiff, radiiSum, centreDist; 
    for (var i =0 ; i < data.length ; i++) {
       for (var j = i+1; j < data.length; j++) {
           radiiDiff = Math.pow(r(data[i].Total_visits) - r(data[j].Total_visits),2)
           radiiSum = Math.pow(r(data[i].Total_visits) + r(data[j].Total_visits),2)
           centreDist = Math.pow(x(data[i].Total_Customers) - x(data[j].Total_Customers),2) + Math.pow(y(data[i].TotalSales) - y(data[j].TotalSales),2)
           if((radiiDiff <= centreDist) && (centreDist <= radiiSum)) {
              //return the min value
              return d3.min(data.map(function(d) { return d.TotalSales }));
            }
        }
     }
     // return 0 otherwise
     return 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM