Javascript 覆盖一个地平线实例的范围

Javascript 覆盖一个地平线实例的范围,javascript,d3.js,cubism.js,Javascript,D3.js,Cubism.js,我有一系列的地平线图,它们是这样创建的: d3.select("body") .selectAll(".horizon") .data(metrics) .enter() .append("div") .attr("class", "horizon") .attr("id", function(d){return d.toString();}) .call(context.horizon().height(['75'])); d3.select("body")

我有一系列的地平线图,它们是这样创建的:

d3.select("body")
  .selectAll(".horizon")
  .data(metrics)
  .enter()
  .append("div")
  .attr("class", "horizon")
  .attr("id", function(d){return d.toString();})
  .call(context.horizon().height(['75']));
d3.select("body")
  .selectAll(".horizon")
  .data(metrics)
  .enter()
  .append("div")
  .attr("class", "horizon")
  .attr("id", function(d){return d.toString();})
  .call(context.horizon()  
             .height(['75'])
             .extent(function(d,i){  //use this function to change extents
                   if (d.toString() == 'Whatever the name is'){
                        return [0,1000];
                   } else {
                        return [ <default min>, <default max>]
                   }
              })
 )
其中
metrics
metric
对象的数组

我想为其中一个
地平线
对象重新定义
范围。

我尝试在一个图形上调用
区段
函数,但我不确定是否正确调用它,甚至选择它:

d3.select("#id-attribute")
  .call(context.horizon().extent(function(d,i){return([0,1000]);}));
这种方式似乎可行,但图形显示变得混乱,在图形下方添加了额外的空白,图形的运动没有考虑到这一点,并使图形顶部未激活。我怀疑这在某种程度上是由于它是
extent
对象的一个新实例,所以我尝试了以下方法:

d3.select("#id-attribute")
  .call(extent(function(d,i){return([0,1000]);}));
但这会生成:“
ReferenceError:extent未定义”

我已尝试重新定义
度量
范围
函数,有效地:

metrics[3].extent = function(d,i) {return([0,100]);};
但这会导致图形为空白(尽管鼠标悬停在其上会显示读数中的数字),并且当鼠标未悬停在任何图形上时,会导致其读数和显示在其下方的图形的读数为空白


老实说,我不理解这些东西是如何组合在一起的,也没有特别的JavaScript经验,所以我不确定我的错误在哪里。我完全不懂。任何提示都将不胜感激。

您是否需要在初始调用后重新定义生成地平线的范围

如果没有,请尝试以下方法:

d3.select("body")
  .selectAll(".horizon")
  .data(metrics)
  .enter()
  .append("div")
  .attr("class", "horizon")
  .attr("id", function(d){return d.toString();})
  .call(context.horizon().height(['75']));
d3.select("body")
  .selectAll(".horizon")
  .data(metrics)
  .enter()
  .append("div")
  .attr("class", "horizon")
  .attr("id", function(d){return d.toString();})
  .call(context.horizon()  
             .height(['75'])
             .extent(function(d,i){  //use this function to change extents
                   if (d.toString() == 'Whatever the name is'){
                        return [0,1000];
                   } else {
                        return [ <default min>, <default max>]
                   }
              })
 )
d3.选择(“主体”)
.selectAll(“.horizon”)
.数据(指标)
.输入()
.附加(“div”)
.attr(“类”、“地平线”)
.attr(“id”,函数(d){返回d.toString();})
.call(context.horizon())
.高度(['75'])
.extent(函数(d,i){//使用此函数更改范围
if(d.toString()=='无论名称是什么'){
返回[01000];
}否则{
返回[,]
}
})
)
您可以设置自己的默认范围,也可以使用类似于d3.min()/d3.max()的函数来获取地平线的值。您只需要返回一个包含两个元素的数组