$(function(){ var $w = $(window), $html = $("html"), $body = $("body"), screenWidth = $body.width(), screenHeight = $body.height(), MIDDLE_FONT_SIZE = 20, TICK_FONT_SIZE = 8, BASE_WIDTH = 12, BASE_COLOR = "#249eb3", GRAYISH_BASE_COLOR = "#d5e0dc", BLACK_COLOR = "#333030", GRAY_COLOR = "#bfbeba", LIGHT_GRAY_COLOR = "#e5e5e4", PH_COLORS = [ "#bf1e2e", "#f13e37", "#fcb040", "#8cc63e", "#24a9e2", "#283890", "#93268f" ], SVG_START = ""; { // font size $(".text-size-adjust").each(function(){ var $this = $(this); $this.wrapInner(""); var $inner = $("span", $this); var w1 = $inner.width(); var w2 = screenWidth - 40; //window.console.log(w1+" / "+w2); if (w1 > w2) { var fontSize = parseInt($this.css("font-size")); //window.console.log("fontSize: "+fontSize); fontSize *= w2 / w1; fontSize = fontSize < 10 ? 10 : fontSize; $this.css("font-size", fontSize + "px"); } }) } { // extension try { if (NANO_STANZA && NANO_STANZA.EXTENSION && NANO_STANZA.EXTENSION.length) { //window.console.log(NANO_STANZA.EXTENSION); var html = "
"; for (var i = 0; i < NANO_STANZA.EXTENSION.length; i++) { var item = NANO_STANZA.EXTENSION[i]; html += "

" + item.label + "

"; } html += "
"; $body.append(html); var $extension = $("#extension"); var height = $("p", $extension).height() * NANO_STANZA.EXTENSION.length; var exHeight = $extension.height(); var padding = (exHeight - height) * .5; $extension.css("padding-top", padding + "px"); } } catch(e) { //window.console.log(e); } } { // growth temperature if ($body.has(".growth-temperature").length > 0) { var html = SVG_START; html += "\ \ \ 45°\ 20°\ \ \ \ \ \ " + $(".datum[data-temperature='thermophile']").text() + "\ " + $(".datum[data-temperature='mesophile']").text() + "\ " + $(".datum[data-temperature='psychrophile']").text() + ""; // close html += ""; $("#main-view").append(html); } } { // pie chart if ($body.has(".pie-chart").length > 0) { var data = [], html = SVG_START, sum = 0, currentRadian = -Math.PI * .5, centerX = screenWidth * .5, centerY = screenHeight * .5 + 7, $chart = $(".pie-chart"), RADIUS = 50; $(".datum").each(function(){ var $datum = $(this); data.push({ value: parseFloat($datum.text()), name: $datum.data("name") }); sum += data[data.length - 1].value; }); // chart html += "" for (var i = 0; i < data.length; i++) { var ratio = data[i].value / sum, radian = Math.PI * 2 * ratio, color = BASE_COLOR, largeArcFlag = ratio > .5; // color if ($chart.hasClass("gc-content")) { if (data[i].name == "at") color = GRAYISH_BASE_COLOR; } // arc html += ""; currentRadian += radian; } html += ""; // text html += "" + $(".datum[data-name='gc']").text() + "" + $chart.data("unit") + ""; // close html += ""; $("#main-view").append(html); } } { // bar chart if ($body.has(".bar-chart").length > 0) { var data = [], html = SVG_START, maxValue = 0, maxValueString = "", sum = 0, colWidth, barWidth, marginLeft, strokeColor, $chart = $(".bar-chart"), xGraduationsPar = parseFloat($chart.data("xGraduationsPar")); BASE_Y = 114, MARGIN_X = 16, MAX_HEIGHT = 88, BAR_MIN_SPACE = 1, FONT_SIZE_SMALL = 12, TICKS = { "0": [], "1": [.5, 1], "2": [1, 2], "3": [1, 2, 3], "4": [2, 4], "5": [2, 4], "6": [3, 6], "7": [3, 6], "8": [4, 8], "9": [4, 8] }; $(".datum").each(function(){ var $datum = $(this), value = parseFloat($datum.text()); data.push({ value: value, x: $datum.data("x") }); sum += data[data.length - 1].value; maxValue = maxValue < value ? value : maxValue; }); maxValueString = Math.ceil(maxValue) + ""; marginLeft = TICK_FONT_SIZE * maxValueString.length + TICK_FONT_SIZE; // background: x html += ""; colWidth = (screenWidth - MARGIN_X * 2 - marginLeft) / data.length; barWidth = (colWidth - BAR_MIN_SPACE) < BASE_WIDTH ? colWidth - BAR_MIN_SPACE : BASE_WIDTH; for (var i = 0; i <= data.length; i++) { var x = (MARGIN_X + marginLeft + colWidth * i), xGraduation; if (i < data.length) { xGraduation = data[i].x; } else { xGraduation = data[i - 1].x + (data[i - 1].x - data[i - 2].x); } if ((i % xGraduationsPar) == 0) { html += "\ \ " + xGraduation + ""; } } // background: y var ticks = TICKS[maxValueString.charAt(0)]; for (var i = 0; i < ticks.length; i++) { var tick = ticks[i]; var y = BASE_Y - MAX_HEIGHT * (tick / parseInt(maxValueString.charAt(0))); var tick2 = Math.pow(10, maxValueString.length) * tick * .1; html += "\ \ " + tick2 + ""; } // data strokeColor = BASE_COLOR; for (var i = 0; i < data.length; i++) { switch ($chart.data("xAxisUnit")) { case "pH": strokeColor = PH_COLORS[i]; break; } var x = (MARGIN_X + marginLeft + colWidth * i) + colWidth * .5; var barHeight = maxValue == 0 ? 0 : MAX_HEIGHT * (data[i].value / maxValue); html += "\ "; } // sum html += "" + sum + "" // close html += ""; $("#main-view").append(html); } } { // vertical-centering if ($body.has(".vertical-centering").length > 0) { $(".vertical-centering").each(function(){ $this = $(this); $this.css({ position: "relative", top: (screenHeight - $this.outerHeight()) * .5 + 8 }) }) } } });