2014-05-14 29 views
5

我愛cubism.js我們用它每天Cubism.js與窗口調整

我定義每個設備利用全屏幕尺寸(手機VS臺式機)的自定義大小的圖表,我真的很討厭

chart = $('#chart'); 
$(window).on('resize', function() { 
    var targetWidth = chart.parent().width(); 
    chart.attr('width', targetWidth); 
    // can we change cubism's context size too? 
}); 

,但我也知道這是不可能的立體主義,因爲我們的初始設置:

我從其他堆棧溢出的問題,你可以做以下調整大小的圖表,每當調整窗口的大小知道在上下文中的大小:

context = cubism.context().step(60 * 1000).size(780); 

這是它會如何看待預計:

enter image description here

我是否應該看看其他地方的代碼有什麼建議?或者如果我應該只處理自定義尺寸?

回答

0

我不確定這是否適用於您,但您可能需要試一試。

正如我剛纔所說,我一直在玩cubism.js,並發現我實際上能夠創作這一步,因此我也會假設/選擇相信在邏輯上它也有可能創作出通過這樣的立體派的大小:

JS:

// Initialize the step menu's selection. 
d3.selectAll("#step option").property("selected", function() { 
    return this.value == step; 
}); 

// Update the location on step change. 
d3.select("#step").on("change", function() { 
    window.location = "?step=" + this.value + "&" + location.search.replace(/[?&]step=[^&]*(&|$)/g, "$1").substring(1); 
}); 

//to alter the step 
var step = +cubism.option("step", 864e5); 

var context = cubism.context() // set the cubism context 
.step((step)) 
.size(1440); 

HTML:

<select id="step"> 
    <option value="36e5">Hours</option> 
    <option value="864e5">Days</option> 
</select> 

因此,所有你需要做的是與大小步驟,那麼它應該讓你動態地改變立體派的大小。