diff --git a/Rickshaw.Graph.HoverDetail.js b/Rickshaw.Graph.HoverDetail.js new file mode 100644 index 0000000..30b9678 --- /dev/null +++ b/Rickshaw.Graph.HoverDetail.js @@ -0,0 +1,213 @@ +Rickshaw.namespace('Rickshaw.Graph.HoverDetail'); + +Rickshaw.Graph.HoverDetail = Rickshaw.Class.create({ + + initialize: function(args) { + + var graph = this.graph = args.graph; + + this.xFormatter = args.xFormatter || function(x) { + return new Date( x * 1000 ).toUTCString(); + }; + + this.yFormatter = args.yFormatter || function(y) { + return y === null ? y : y.toFixed(2); + }; + + var element = this.element = document.createElement('div'); + element.className = 'detail'; + + this.visible = true; + graph.element.appendChild(element); + + this.lastEvent = null; + this._addListeners(); + + this.onShow = args.onShow; + this.onHide = args.onHide; + this.onRender = args.onRender; + + this.formatter = args.formatter || this.formatter; + + }, + + formatter: function(series, x, y, formattedX, formattedY, d) { + return /*series.name + ': ' + */formattedY; + }, + + update: function(e) { + + e = e || this.lastEvent; + if (!e) return; + this.lastEvent = e; + + if (!e.target.nodeName.match(/^(path|svg|rect)$/)) return; + + var graph = this.graph; + + var eventX = e.offsetX || e.layerX; + var eventY = e.offsetY || e.layerY; + + var j = 0; + var points = []; + var nearestPoint; + + this.graph.series.active().forEach( function(series) { + + var data = this.graph.stackedData[j++]; + + var domainX = graph.x.invert(eventX); + + var domainIndexScale = d3.scale.linear() + .domain([data[0].x, data.slice(-1)[0].x]) + .range([0, data.length]); + + var approximateIndex = Math.floor(domainIndexScale(domainX)); + var dataIndex = Math.min(approximateIndex || 0, data.length - 1); + + for (var i = approximateIndex; i < data.length - 1;) { + + if (!data[i] || !data[i + 1]) break; + if (data[i].x <= domainX && data[i + 1].x > domainX) { dataIndex = i; break } + + if (data[i + 1].x <= domainX) { i++ } else { i-- } + } + + var value = data[dataIndex]; + + var distance = Math.sqrt( + Math.pow(Math.abs(graph.x(value.x) - eventX), 2) + + Math.pow(Math.abs(graph.y(value.y + value.y0) - eventY), 2) + ); + + var xFormatter = series.xFormatter || this.xFormatter; + var yFormatter = series.yFormatter || this.yFormatter; + + var point = { + formattedXValue: xFormatter(value.x), + formattedYValue: yFormatter(value.y), + series: series, + value: value, + distance: distance, + order: j, + name: series.name + }; + + if (!nearestPoint || distance < nearestPoint.distance) { + nearestPoint = point; + } + + points.push(point); + + }, this ); + + + nearestPoint.active = true; + + var domainX = nearestPoint.value.x; + var formattedXValue = nearestPoint.formattedXValue; + + this.element.innerHTML = ''; + this.element.style.left = graph.x(domainX) + 'px'; + + this.visible && this.render( { + points: points, + detail: points, // for backwards compatibility + mouseX: eventX, + mouseY: eventY, + formattedXValue: formattedXValue, + domainX: domainX + } ); + }, + + hide: function() { + this.visible = false; + this.element.classList.add('inactive'); + + if (typeof this.onHide == 'function') { + this.onHide(); + } + }, + + show: function() { + this.visible = true; + this.element.classList.remove('inactive'); + + if (typeof this.onShow == 'function') { + this.onShow(); + } + }, + + render: function(args) { + + var graph = this.graph; + var points = args.points; + var point = points.filter( function(p) { return p.active } ).shift(); + + if (point.value.y === null) return; + + var formattedXValue = this.xFormatter(point.value.x); + var formattedYValue = this.yFormatter(point.value.y); + + this.element.innerHTML = ''; + this.element.style.left = graph.x(point.value.x) + 'px'; + + var xLabel = document.createElement('div'); + + xLabel.className = 'x_label'; + xLabel.innerHTML = formattedXValue; + this.element.appendChild(xLabel); + + var item = document.createElement('div'); + + item.className = 'item'; + item.innerHTML = this.formatter(point.series, point.value.x, point.value.y, formattedXValue, formattedYValue, point); + item.style.top = this.graph.y(point.value.y0 + point.value.y) + 'px'; + + this.element.appendChild(item); + + var dot = document.createElement('div'); + + dot.className = 'dot'; + dot.style.top = item.style.top; + dot.style.borderColor = point.series.color; + + this.element.appendChild(dot); + + if (point.active) { + item.className = 'item active'; + dot.className = 'dot active'; + } + + this.show(); + + if (typeof this.onRender == 'function') { + this.onRender(args); + } + }, + + _addListeners: function() { + + this.graph.element.addEventListener( + 'mousemove', + function(e) { + this.visible = true; + this.update(e) + }.bind(this), + false + ); + + this.graph.onUpdate( function() { this.update() }.bind(this) ); + + this.graph.element.addEventListener( + 'mouseout', + function(e) { + if (e.relatedTarget && !(e.relatedTarget.compareDocumentPosition(this.graph.element) & Node.DOCUMENT_POSITION_CONTAINS)) { + this.hide(); + } + }.bind(this), + false + ); + } +}); + diff --git a/default.css b/default.css index 2a0c2bd..ab1d1ab 100644 --- a/default.css +++ b/default.css @@ -90,10 +90,6 @@ body { * IMAGES *********************************************/ .reveal section img { - margin: 15px 0px; - background: rgb(255, 255, 255); - border: 4px solid #eeeeee; - box-shadow: 0 0 10px rgba(0, 0, 0, 0.15); -webkit-transition: all .2s linear; -moz-transition: all .2s linear; -ms-transition: all .2s linear; @@ -102,9 +98,9 @@ body { } .reveal a:hover img { - background: rgba(255, 255, 255, 0.2); + /*background: rgba(255, 255, 255, 0.2); border-color: #13daec; - box-shadow: 0 0 20px rgba(0, 0, 0, 0.55); + box-shadow: 0 0 20px rgba(0, 0, 0, 0.55);*/ } /********************************************* diff --git a/detail.css b/detail.css new file mode 100644 index 0000000..722451b --- /dev/null +++ b/detail.css @@ -0,0 +1,73 @@ +.rickshaw_graph .detail { + pointer-events: none; + position: absolute; + top: 0; + z-index: 2; + background: rgba(0, 0, 0, 0.1); + bottom: 0; + width: 1px; + transition: opacity 0.25s linear; + -moz-transition: opacity 0.25s linear; + -o-transition: opacity 0.25s linear; + -webkit-transition: opacity 0.25s linear; +} +.rickshaw_graph .detail.inactive { + opacity: 0; +} +.rickshaw_graph .detail .item.active { + opacity: 1; +} +.rickshaw_graph .detail .x_label { + font-family: Arial, sans-serif; + border-radius: 3px; + padding: 6px; + opacity: 0.5; + border: 1px solid #e0e0e0; + font-size: 12px; + position: absolute; + background: white; + white-space: nowrap; +} +.rickshaw_graph .detail .item { + position: absolute; + z-index: 2; + border-radius: 3px; + padding: 0.25em; + font-size: 12px; + font-family: Arial, sans-serif; + opacity: 0; + background: rgba(0, 0, 0, 0.4); + color: white; + border: 1px solid rgba(0, 0, 0, 0.4); + margin-left: 1em; + margin-top: -1em; + white-space: nowrap; +} +.rickshaw_graph .detail .item.active { + opacity: 1; + background: rgba(0, 0, 0, 0.8); +} +.rickshaw_graph .detail .item:before { + content: "\25c2"; + position: absolute; + left: -0.5em; + color: rgba(0, 0, 0, 0.7); + width: 0; +} +.rickshaw_graph .detail .dot { + width: 4px; + height: 4px; + margin-left: -4px; + margin-top: -3px; + border-radius: 5px; + position: absolute; + box-shadow: 0 0 2px rgba(0, 0, 0, 0.6); + background: white; + border-width: 2px; + border-style: solid; + display: none; + background-clip: padding-box; +} +.rickshaw_graph .detail .dot.active { + display: block; +} diff --git a/index.css b/index.css index edeaff7..22697a3 100644 --- a/index.css +++ b/index.css @@ -18,16 +18,250 @@ background-color: #4B7865; } -#intro-btn { - background-color: #9C646B; +.small-text { + font-size: 0.6em !important; +} + +.dark { + color: #222; +} + +.btn { + box-shadow: 1px 1px 5px black; border: 0; border-radius: 4px; color: #fff; - font-size: 1.5em; padding: 12px; } +#intro-btn { + background-color: #9C646B; + font-size: 1.5em; +} + #intro-btn:hover { background-color: #a66c74; cursor: pointer; } + +.graph-wrapper { + width: 550px; + margin: 0 auto; + text-align:center; +} + +.graph-pictures-xaxis { + width: 100%; +} +.graph-pictures-xaxis div { + width: 104.5px; + margin-right: 5.5px; + margin-top: -7px; + float:left; + background-color: rgba(0,0,0,0.7); + padding-top:6px; + display: inline-block; +} +.graph-pictures-xaxis img { + outline: 2px solid #000; + height: 55px; +} + +.detail { /*styles the on-hover stuff*/ + width: 104.5px; + text-align:center; + padding: 0; + font-size: 0.5em; + position: fixed; + top: 325px; + margin-left: 205px +} + +/*card flip attempt:*/ +.thumb { + display:block; + width:880px; + height:100px; + position:relative; + margin-top: 10px; + margin-bottom:10px; + float:left; +} + +.thumb-wrapper { + display:block; + width:100%; + height:100%; +} + +.thumb .thumb-front { + width:100%; + height:100%; + position:absolute; + display:block; +} + +.thumb .thumb-detail { + display:block; + width:100%; + height:100%; + position:absolute; + background-color: #D1C181; + outline 3px solid black; +} + +.thumb.scroll { + overflow: hidden; +} + +.thumb.scroll .thumb-detail { + bottom: -280px; +} + +.thumb.flip { + perspective:800px; +} + +.thumb.flip .thumb-wrapper { + transition: transform 1s; + transform-style: preserve-3d; +} + +.thumb.flip .thumb-detail { + transform: rotateY(-180deg); +} + +.thumb.flip .thumb-front, .thumb.flip .thumb-detail { + backface-visibility: hidden; +} + +.thumb.flip .flipIt { + transform: rotateY(-180deg); +} + +#user-graph-next-btn { + background-color: #4B7865; + font-size: .7em; +} +#user-graph-next-btn:hover { + background-color: #9CB06C; + cursor: pointer; +} + +#generated-graph-large { + display: inline-block; + /*background:white; + border-left:6px solid white; + border-right: 6px solid white; + border-top: 3px solid white;*/ +} +#generated-graph-large-yaxis { + position:absolute; + top: 0; + bottom: 0; + width: 50px; +} +#generated-graph-label { + position: relative; + top: -15px; + font-size: .6em; +} + +#middle-bar{ + margin-top:30px; + font-size: .8em; + width: 100% +} + +#what-happens-btn { + font-size: .8em; +} + +#what-happens-btn:hover{ + background-color: #9CB06C; + cursor: pointer; +} + +#bottom-graphs-wrapper { + margin-top: 50px; +} +.generated-graph { + display: inline-block; + width: 210px; + height: 120px; + background: rgba(0,0,0,0.8); + line-height:120px; + font-size: 50px; + color: white; +} + +.clear-graph { + background: none; +} + +#final-graph-header { + height: 55px; + font-size: .7em; +} + +#final-graph-header .btn { + margin: 4px; +} + +#final-graph-header input { + font-size: .7em; + margin: 8px; +} + +#value-plot-y { + width: 450px; + position: absolute; + left:-160px; + top: 320px; + font-size: .5em; + -webkit-transform: rotate(-90deg); + -moz-transform: rotate(-90deg); +} +#value-plot { + background: white; + height: 450px; + width: 800px; + margin: 0 auto; + font-size: 400px; + line-height: 450px; + color:black; +} +#loading-gif { + position: absolute; + top: 300px; + left: 450px; + display:none; +} +#value-plot-x { + width:800px; + text-align:center; + margin: 0 auto; + font-size: .6em; +} +.left { + float: left; +} +.right { + float: right; +} + +#people-select-wrapper { + display: inline-block; +} + +#people-select-wrapper select { + display: inline-block; + padding: 3px; + font-size: .8em; + width: 120px; + outline: none; + color: black; + border: none; + border-radius: 5px; + background-color: #fff; +} diff --git a/index.html b/index.html index 3bf146a..3488670 100644 --- a/index.html +++ b/index.html @@ -4,10 +4,13 @@
+
+
+
+
These ratings follow a random distribution - every person who rates the cats will have different opinions, but some cats are more likely to get a higher rating than others. These factors mean the adoption times will not conform to a normal distribution
If we have way more people rate way more cats, the average adoption times will conform to a normal distribution!
These ratings follow a random distribution - every person who rates the cats will have different opinions. Even so, the probability of getting a 10 for each cat is not equal; some cats are more likely to get a higher rating than others. The ratings will not conform to a normal distribution
- +