2016-08-23 1 views
0

参考:https://bl.ocks.org/mbostock/4063318d3 Bl.ocks要点の例でHTML5ページのコードが不完全なのはなぜですか?

この広範なライブラリの例を使用しようとしていますが、ほとんどの例では不完全なコードがあります。欠けているHTMLタグがたくさんあるだけでなく、終了スクリプトタグの後ろに「切り捨てられた」ように見えます。特定のライブラリを参照することはできません。私はいくつか試した、推測、そして運がない。私は "About Page"に行きました。そこには運がありませんでした。例えば、上記のものは、ページ内に与えられた次のコードを

があります

<!DOCTYPE html> 
<meta charset="utf-8"> 
<style> 

body { 
    font: 10px sans-serif; 
    shape-rendering: crispEdges; 
} 

.day { 
    fill: #fff; 
    stroke: #ccc; 
} 

.month { 
    fill: none; 
    stroke: #000; 
    stroke-width: 2px; 
} 

.RdYlGn .q0-11{fill:rgb(165,0,38)} 
.RdYlGn .q1-11{fill:rgb(215,48,39)} 
.RdYlGn .q2-11{fill:rgb(244,109,67)} 
.RdYlGn .q3-11{fill:rgb(253,174,97)} 
.RdYlGn .q4-11{fill:rgb(254,224,139)} 
.RdYlGn .q5-11{fill:rgb(255,255,191)} 
.RdYlGn .q6-11{fill:rgb(217,239,139)} 
.RdYlGn .q7-11{fill:rgb(166,217,106)} 
.RdYlGn .q8-11{fill:rgb(102,189,99)} 
.RdYlGn .q9-11{fill:rgb(26,152,80)} 
.RdYlGn .q10-11{fill:rgb(0,104,55)} 

</style> 
<body> 
<script src="//d3js.org/d3.v3.min.js"></script> 
<script> 

var width = 960, 
    height = 136, 
    cellSize = 17; // cell size 

var percent = d3.format(".1%"), 
    format = d3.time.format("%Y-%m-%d"); 

var color = d3.scale.quantize() 
    .domain([-.05, .05]) 
    .range(d3.range(11).map(function(d) { return "q" + d + "-11"; })); 

var svg = d3.select("body").selectAll("svg") 
    .data(d3.range(1990, 2011)) 
    .enter().append("svg") 
    .attr("width", width) 
    .attr("height", height) 
    .attr("class", "RdYlGn") 
    .append("g") 
    .attr("transform", "translate(" + ((width - cellSize * 53)/2) + 
    ","  + (height - cellSize * 7 - 1) + ")"); 

svg.append("text") 
    .attr("transform", "translate(-6," + cellSize * 3.5 + ")rotate(-90)") 
    .style("text-anchor", "middle") 
    .text(function(d) { return d; }); 

var rect = svg.selectAll(".day") 
    .data(function(d) { return d3.time.days(new Date(d, 0, 1), 
    new Date(d  + 1, 0, 1)); }) 
    .enter().append("rect") 
    .attr("class", "day") 
    .attr("width", cellSize) 
    .attr("height", cellSize) 
    .attr("x", function(d) { return d3.time.weekOfYear(d) * cellSize; }) 
    .attr("y", function(d) { return d.getDay() * cellSize; }) 
    .datum(format); 

rect.append("title") 
    .text(function(d) { return d; }); 

svg.selectAll(".month") 
    .data(function(d) { return d3.time.months(new Date(d, 0, 1), 
new Date(d + 1, 0, 1)); }) 
    .enter().append("path") 
    .attr("class", "month") 
    .attr("d", monthPath); 

d3.csv("dji.csv", function(error, csv) { 
    if (error) throw error; 

    var data = d3.nest() 
    .key(function(d) { return d.Date; }) 
    .rollup(function(d) { return (d[0].Close - d[0].Open)/d[0].Open; }) 
    .map(csv); 

    rect.filter(function(d) { return d in data; }) 
     .attr("class", function(d) { return "day " + color(data[d]); }) 
    .select("title") 
     .text(function(d) { return d + ": " + percent(data[d]); }); 
}); 

function monthPath(t0) { 
    var t1 = new Date(t0.getFullYear(), t0.getMonth() + 1, 0), 
     d0 = t0.getDay(), w0 = d3.time.weekOfYear(t0), 
     d1 = t1.getDay(), w1 = d3.time.weekOfYear(t1); 
    return "M" + (w0 + 1) * cellSize + "," + d0 * cellSize 
     + "H" + w0 * cellSize + "V" + 7 * cellSize 
     + "H" + w1 * cellSize + "V" + (d1 + 1) * cellSize 
     + "H" + (w1 + 1) * cellSize + "V" + 0 
     + "H" + (w0 + 1) * cellSize + "Z"; 
} 
</script> 
+0

あなたの意見では、どのタグが欠けていますか? –

答えて

0

私は私が最初にこのつまずい同じ質問尋ねる覚えている:なぜ地球上を誰でも例を出すでしょう不完全なコードですか?最後に何かが欠落しているかのように、実際には外れて見えます。スペックに潜入し、それに第二の考えを与えると、物事はクリアされます。

index.html

は完全なHTML 5ファイルにする

</body> 
</html> 

終了タグが欠落しているようです。

8.1.2.4オプションタグ

html要素の終了:しかし、人はこれが唯一の目にそれが喜ばせるだろうということに気付き、specを見ると、何もこれらのタグのための技術的な要件はありませんhtml要素の直後にコメントがない場合は、タグを省略することができます。

body要素の終了タグは、body要素の直後にコメントが続くと省略される場合があります。

言われているように、そのままコードは完全であり、有効です。スタイル、コード、外部参照のすべてがそこにあります。あなたは、あなたが見るものを超えて何かを必要としません。

+0

ありがとうございます。確かに、前提を作るハンドルを飛ばす前に、html仕様を厳密に見ていく必要があります。ところで、私がCodeLobsterで初めて読み込んだときは、「プレビュー」でレンダリングされませんでしたが、AptanaStudio3で試したときにうまくいきました。とにかく、私は何を考えていたのですか? ;-) 再度、感謝します! –

+0

私はこれを「ラップ」と呼びますか?そして私は自分の疑問に答えますか?それはどのように機能するのですか? –

関連する問題