// Generated by CoffeeScript 1.4.0 (function() { var __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; window.PcpView = (function(_super) { __extends(PcpView, _super); function PcpView() { return PcpView.__super__.constructor.apply(this, arguments); } PcpView.prototype.initialize = function() { var _this = this; if (!this.model.options.hidePCP) { this.render(); this.model.on("change:currentRowId", function() { return _this.showCurrentRow(); }); this.model.on("change:clickedRowId", function() { return _this.showClickedRow(); }); this.model.on("change:currentCluster", function() { return _this.showCurrentCluster(); }); return this.model.on("change:currentTag", function() { return _this.showCurrentTag(); }); } }; PcpView.prototype.events = function() { return { "mouseover .expression-line": "changeCurrentRowId", "mouseout .expression-line": "changeCurrentRowId", "click .expression-line": "changeClickedRowId", "click .expression-point": "showExpressionPointText" }; }; PcpView.prototype.render = function() { var columnName, _this = this; this.columnNamesMargin = d3.max((function() { var _i, _len, _ref, _results; _ref = this.model.columnNames; _results = []; for (_i = 0, _len = _ref.length; _i < _len; _i++) { columnName = _ref[_i]; _results.push(columnName.length); } return _results; }).call(this)); this.margin = { top: 300, right: 50, bottom: this.columnNamesMargin * 30, left: 150 }; this.width = d3.max([400, this.model.columnNames.length * 40]); this.height = 300; this.pcp = d3.select(this.el).attr("width", this.width + this.margin.right + this.margin.left).attr("height", this.height + this.margin.top + this.margin.bottom).attr("class", "pcp").append("g").attr("transform", "translate(" + this.margin.left + "," + this.margin.top + ")"); this.x = d3.scale.ordinal().domain(this.model.columnNames).rangePoints([0, this.width], .2); this.y = d3.scale.linear().domain(this.model.getLongitudinalValueExtent()).range([this.height, 0], .2); this.line = d3.svg.line().defined(function(d) { return _.isFinite(d.value); }).x(function(d) { return _this.x(d.condition); }).y(function(d) { return _this.y(d.value); }); this.xAxis = d3.svg.axis().scale(this.x).tickSize(6, 0); this.renderedXAxis = this.pcp.append("g").attr("class", "x axis").attr("transform", "translate(0," + this.height + ")").call(this.xAxis); this.renderedXAxis.selectAll("text").attr("dx", "-.5em").attr("dy", ".3em").attr("text-anchor", "end").attr("transform", "rotate(-45)"); this.yAxis = d3.svg.axis().scale(this.y).ticks(4).tickSize(6, 0).orient("left"); this.renderedYAxis = this.pcp.append("g").attr("class", "y axis").attr("transform", "translate(0,0)").call(this.yAxis); this.renderedYAxis.append("text").attr("text-anchor", "middle").attr("dy", "-.5em").text(this.model.options.yAxisName); this.addLongitudinalDataLines(); return this.pcp.append("line").attr("y1", this.y(0)).attr("y2", this.y(0)).attr("x2", this.width).attr("class", "axis zero"); }; PcpView.prototype.addLongitudinalDataLines = function() { var _this = this; this.pcp.selectAll(".expression-line").data(this.getLongitudinalData()).enter().append("path").attr("class", "expression-line").attr("row-id", function(d, i) { return _this.model.rowIds[i]; }).attr("stroke", "steelblue").attr("stroke-opacity", .5).attr("d", this.line); if (this.model.options.showClusters) { return this.pcp.selectAll(".expression-line").attr("cluster", function(d, i) { return _this.model.clusters[i]; }).attr("stroke", function(d, i) { return window.clusterColor(_this.model.clusters[i]); }); } }; PcpView.prototype.getLongitudinalData = function() { if (this.model.options.showGroups) { return this.model.groupedLongitudinalData; } else { return this.model.longitudinalData; } }; PcpView.prototype.changeCurrentRowId = function(e) { e.stopPropagation(); return this.model.set({ currentRowId: e.type === "mouseover" ? d3.select(e.target).attr("row-id") : null }); }; PcpView.prototype.changeClickedRowId = function(e) { e.stopPropagation(); return this.model.set({ clickedRowId: d3.select(e.target).attr("row-id") }); }; PcpView.prototype.showExpressionPointText = function(e) { var d; e.stopPropagation(); d = e.target.__data__; return this.pcp.append("text").attr("class", "expression-text").attr("x", this.x(d.condition)).attr("y", this.y(d.value)).attr("text-anchor", "middle").attr("dy", "-.8em").text(d3.round(d.value, 2)); }; PcpView.prototype.showCurrentRow = function() { var currentRow, currentRowId; this.pcp.selectAll(".expression-line").filter(":not(.clicked)").classed("current", 0); this.pcp.selectAll("text.title").filter(":not(.clicked)").remove(); currentRowId = this.model.get("currentRowId"); if (currentRowId != null) { currentRow = this.pcp.select("[row-id=" + currentRowId + "]"); currentRow.classed("current", 1); if (this.pcp.select(".clicked").empty()) { currentRow.node().parentNode.appendChild(currentRow.node()); } this.pcp.selectAll("text.title").filter(".clicked").style("display", "none"); return this.pcp.append("text").attr("class", "title").attr("x", this.width / 2).attr("y", -40).attr("text-anchor", "middle").text(this.model.getRowName(currentRowId)); } else { return this.pcp.selectAll("text.title").filter(".clicked").style("display", "block"); } }; PcpView.prototype.showClickedRow = function() { var clickedRow, clickedRowId, data; clickedRowId = this.model.get("clickedRowId"); if (clickedRowId != null) { clickedRow = this.pcp.select("[row-id=" + clickedRowId + "]"); clickedRow.node().parentNode.appendChild(clickedRow.node()); this.removeClickedRow(); clickedRow.classed("current clicked", 1); data = clickedRow.node().__data__; this.pcp.selectAll(".expression-point").data(data.filter(function(d) { return _.isFinite(d.value); })).enter().append("circle").attr("class", "expression-point").attr("cx", this.line.x()).attr("cy", this.line.y()).attr("r", 5); this.pcp.selectAll(".expression-text").data(data.filter(this.filterTextDatapoints)).enter().append("text").attr("class", "expression-text").attr("x", this.line.x()).attr("y", this.line.y()).attr("text-anchor", "middle").attr("dy", "-.8em").text(function(d, i) { return d3.round(d.value, 2); }); return this.pcp.select("text.title").classed("clicked", 1).text(this.model.getRowName(clickedRowId)); } else { return this.removeClickedRow(); } }; PcpView.prototype.filterTextDatapoints = function(item, i, arr) { var significantDifference; significantDifference = .5; return (i === 0 && _.isFinite(item.value)) || ((i === arr.length - 1) && _.isFinite(item.value)) || (arr[i - 1].value === null && _.isFinite(item.value)) || (arr[i + 1].value === null && _.isFinite(item.value)) || (_.isFinite(item.value) && item.value > arr[i - 1].value && item.value > arr[i + 1].value && (Math.abs(item.value - arr[i - 1].value) > significantDifference || Math.abs(item.value - arr[i + 1].value) > significantDifference)) || (_.isFinite(item.value) && item.value < arr[i - 1].value && item.value < arr[i + 1].value && (Math.abs(item.value - arr[i - 1].value) > significantDifference || Math.abs(item.value - arr[i + 1].value) > significantDifference)); }; PcpView.prototype.removeClickedRow = function() { this.pcp.selectAll(".expression-point").remove(); this.pcp.selectAll(".expression-text").remove(); this.pcp.selectAll(".expression-line").classed("current clicked", 0); return this.pcp.select("text.title").text(""); }; PcpView.prototype.showCurrentCluster = function() { var currentCluster, _this = this; currentCluster = this.model.get("currentCluster"); d3.select("#pcp").style("top", d3.select("body").node().scrollTop); if (currentCluster) { this.pcp.selectAll(".expression-line").attr("stroke", "#999"); return this.pcp.selectAll(".expression-line[cluster='" + currentCluster + "']").attr("stroke", function(d, i) { return window.clusterColor(currentCluster); }).each(function() { return this.parentNode.appendChild(this); }); } else { this.pcp.selectAll(".expression-line").remove(); return this.addLongitudinalDataLines(); } }; PcpView.prototype.showCurrentTag = function() { var currentTag, taggedRowIds; currentTag = this.model.get("currentTag"); d3.select("#pcp").style("top", 0); scroll(0, 0); if (currentTag) { taggedRowIds = _(d3.selectAll("#heatmap .row")).chain().first().filter(function(d) { return d.style.display !== "none"; }).map(function(d) { return d3.select(d).attr("row-id"); }).value(); return this.pcp.selectAll(".expression-line").attr("stroke", "#999").filter(function(d, i) { return _.include(taggedRowIds, d3.select(this).attr("row-id")); }).attr("stroke", function(d, i) { return window.clusterColor(d3.select(this).attr("cluster")); }).each(function() { return this.parentNode.appendChild(this); }); } else { this.pcp.selectAll(".expression-line").remove(); return this.addLongitudinalDataLines(); } }; return PcpView; })(Backbone.View); }).call(this);