Initial work on chart3.

master
ben-burlingham 10 years ago
parent 1a30ee84b7
commit 3a1d505d8b
  1. 17
      css/index.css
  2. 21
      index.html
  3. 50
      js/chart.js
  4. 156
      js/chart3.js
  5. 2
      js/init.js
  6. 26
      js/map.js
  7. 2
      sass/chart.scss
  8. 8
      sass/chart3.scss
  9. 3
      sass/index.scss
  10. 8
      sass/map.scss
  11. 34
      server/stations.js
  12. 1055
      vendor/OrbitControls.js
  13. 958
      vendor/three.min.js
  14. 0
      vendor/topojson.min.js

@ -7,7 +7,7 @@
padding: 0; }
.main {
height: 900px;
height: 920px;
margin: 10px auto;
padding: 20px;
position: relative;
@ -15,7 +15,7 @@
#chart {
cursor: pointer;
height: 100%;
height: 880px;
left: 540px;
position: absolute;
top: 20px;
@ -61,8 +61,15 @@
.tick-line {
stroke: #f0f0f0; }
#chart3 {
border: 1px solid #f00;
height: 260px;
left: 20px;
position: absolute;
top: 640px;
width: 500px; }
#map {
background: #e8fbfe;
border: 1px solid #e8e8e8;
height: 600px;
position: relative;
@ -73,8 +80,8 @@
width: 100%; }
.feature {
fill: #dffbb8;
stroke: #bde484; }
fill: #f7f7f7;
stroke: #ccc; }
.reticle {
cursor: move;

@ -28,20 +28,26 @@
<div id="chart"><svg></svg></div>
<div id="year-labels"></div>
<div id="chart3"></div>
</div>
- MAP harbors
- DATA remove less informative stations
<!-- <script src="//d3js.org/d3.v3.min.js" charset="utf-8"></script> -->
<script src="d3.min.js"></script>
<script src="topojson.min.js"></script>
<!-- <script src="//d3js.org/topojson.v1.min.js"></script> -->
<!-- https://cdnjs.cloudflare.com/ajax/libs/three.js/r74/three.min.js -->
<script src="vendor/three.min.js"></script>
<script src="vendor/OrbitControls.js"></script>
<script src="vendor/d3.min.js"></script>
<script src="vendor/topojson.min.js"></script>
<script src="js/data.js"></script>
<script src="js/map.js"></script>
<script src="js/behaviors.js"></script>
<script src="js/chart.js"></script>
<script src="js/chart3.js"></script>
<script src="js/init.js"></script>
<!-- <script src="gradients-v1.js"></script> -->
@ -50,6 +56,15 @@
<!-- <script src="gradients-v4.js"></script> -->
<!--
var camX = -20;
var camY = -300;
var camZ = 150;
var tgtX = 425;
var tgtY = 300;
var tgtZ = -20;
https://css-tricks.com/svg-line-animation-works/
DISCUSS:

@ -49,26 +49,26 @@ var BuoyAnalysisChart = {
/**
*
*/
appendGradient: function() {
var chart = d3.select('#chart svg');
var id = 'gradient-year';
// appendGradient: function() {
// var chart = d3.select('#chart svg');
// var id = 'gradient-year';
chart.selectAll('#' + id).remove();
// chart.selectAll('#' + id).remove();
var gradient = chart.append("svg:defs")
.append("svg:linearGradient")
.attr("id", id)
// var gradient = chart.append("svg:defs")
// .append("svg:linearGradient")
// .attr("id", id)
gradient.append("svg:stop")
.attr("offset", "0%")
.attr("stop-color", BuoyAnalysisChart.bars.leftHexValue)
.attr("stop-opacity", 1);
// gradient.append("svg:stop")
// .attr("offset", "0%")
// .attr("stop-color", BuoyAnalysisChart.bars.leftHexValue)
// .attr("stop-opacity", 1);
gradient.append("svg:stop")
.attr("offset", "100%")
.attr("stop-color", BuoyAnalysisChart.bars.rightHexValue)
.attr("stop-opacity", 1);
},
// gradient.append("svg:stop")
// .attr("offset", "100%")
// .attr("stop-color", BuoyAnalysisChart.bars.rightHexValue)
// .attr("stop-opacity", 1);
// },
/**
*
@ -142,8 +142,8 @@ var BuoyAnalysisChart = {
BuoyAnalysisChart.bars.imperialLabel = '°F';
BuoyAnalysisChart.bars.metricLabel = '°C';
BuoyAnalysisChart.bars.leftHexValue = '#a7dde6';
BuoyAnalysisChart.bars.rightHexValue = '#f75c5c';
BuoyAnalysisChart.bars.leftHexValue = '#e8e8e8';
BuoyAnalysisChart.bars.rightHexValue = '#e8e8e8';
break;
case 'wh':
@ -188,13 +188,13 @@ var BuoyAnalysisChart = {
var chart = d3.select('#chart svg');
var len = BuoyAnalysisData.years.end - BuoyAnalysisData.years.start;
var len = BuoyAnalysisData.years.end - BuoyAnalysisData.years.start + 1;
var h = (BuoyAnalysisChart.bars.height + BuoyAnalysisChart.bars.spacing) * len + BuoyAnalysisChart.bars.padding;
// alert(BuoyAnalysisData.bars.height + ' ' + BuoyAnalysisChart.bars.spacing)
BuoyAnalysisData.setAxisProperties();
BuoyAnalysisChart.appendAxes();
BuoyAnalysisChart.appendGradient();
// BuoyAnalysisChart.appendGradient();
BuoyAnalysisChart.appendYearLabels();
chart.selectAll('.bar-year').remove();
@ -202,6 +202,13 @@ var BuoyAnalysisChart = {
chart.selectAll('.bar-month').remove();
chart.selectAll('.tick-line').remove();
chart.append('line')
.classed('tick-line', true)
.attr('x1', 1)
.attr('x2', 1)
.attr('y1', 15)
.attr('y2', h)
chart.append('line')
.classed('tick-line', true)
.attr('x1', BuoyAnalysisChart.axis.scale(BuoyAnalysisChart.bars.tickValues[0]))
@ -220,7 +227,8 @@ var BuoyAnalysisChart = {
chart.selectAll('.bar-year').data(years).enter()
.append('rect')
.classed('bar-year', true)
.attr('fill', 'url("#gradient-year")')
// .attr('fill', 'url("#gradient-year")')
.attr('fill', '#f0f0ff')
.attr('height', 23)
// .attr('width', BuoyAnalysisChart.bars.width)
.attr('width', function(d) {

@ -0,0 +1,156 @@
'use strict';
var BuoyAnalysisChart3 = {
h: 258,
w: 498,
/**
*
*/
buildCamera: function() {
var viewAngle = 45;
var aspectRatio = BuoyAnalysisChart3.w / BuoyAnalysisChart3.h;
var near = 1;
var far = 10000;
return new THREE.PerspectiveCamera(viewAngle, aspectRatio, near, far);
},
/**
*
*/
getLighting: function() {
var pointLight = new THREE.PointLight('#fff');
pointLight.position.x = 50;
pointLight.position.y = 40;
pointLight.position.z = 40;
return [pointLight];
},
/**
*
*/
draw: function() {
var renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize( BuoyAnalysisChart3.w, BuoyAnalysisChart3.h );
renderer.setClearColor('#fff');
document.getElementById('chart3').appendChild( renderer.domElement );
var scene = new THREE.Scene();
var mat = new THREE.LineBasicMaterial({ linewidth: 3, color: '#f0f' });
var axisHelper = new THREE.AxisHelper(500);
scene.add(axisHelper);
BuoyAnalysisChart3.getLighting().forEach(function(light) {
scene.add(light);
});
var obj = new THREE.Object3D();
BuoyAnalysisMap.reticle.stations.forEach(function(station, index) {
if (index > 0) {
return;
}
var h, geo, mat, mesh;
// Ribbons. Colorize stations.
var width = 40;
var height = 300;
var width_segments = 1;
var height_segments = BuoyAnalysisData.years.end - BuoyAnalysisData.years.start;
var geo = new THREE.PlaneGeometry(width, height, width_segments, height_segments);
for (var year = BuoyAnalysisData.years.start, i = 0; year <= BuoyAnalysisData.years.end; year++, i++) {
h = BuoyAnalysisData.stationJson[station]['a' + year]['wt']['y'] * 10;
// if (h === 0) {
// continue;
// }
// geo = new THREE.PlaneGeometry(30, 30, 1);
// mat = new THREE.MeshLambertMaterial( {color: 'rgb(100, 100, 0)'} );
// mesh = new THREE.Mesh( geo, mat );
// geo.applyMatrix( new THREE.Matrix4().makeTranslation( 0, 0, 0 ) );
// mesh.position.set((year - BuoyAnalysisData.years.start) * 32, index * 32, h);
// obj.add(mesh);
geo.vertices[2 * i].z = h;
geo.vertices[2 * i + 1].z = h;
}
// for(var i = 0; i < plane.vertices.length / 2; i++) {
// plane.vertices[2 * i].z = Math.pow(2, i / 20);
// plane.vertices[2 * i + 1].z = Math.pow(2, i / 20);
// }
var mesh = new THREE.Mesh(geo, new THREE.MeshLambertMaterial({color: 0xccffcc}));
mesh.material.side = THREE.DoubleSide;
// mesh.doubleSided = true;
// mesh.rotation.y = Math.PI/2-0.5;
mesh.position.y = index * 100 + height / 2;
obj.add(mesh);
});
obj.position.set(150, 0, 0);
scene.add(obj);
var camX = -20;
var camY = -300;
var camZ = 150;
var tgtX = 425;
var tgtY = 300;
var tgtZ = -20;
// var geoCam = new THREE.BoxGeometry(10, 10, 10);
// var matCam = new THREE.MeshLambertMaterial( {color: '#f0f'} );
// var boxCam = new THREE.Mesh( geoCam, matCam );
// boxCam.position.set(camX, camY, camZ);
// scene.add(boxCam);
// var geoTgt = new THREE.BoxGeometry(10, 10, 10);
// var matTgt = new THREE.MeshLambertMaterial( {color: '#0ff'} );
// var boxTgt = new THREE.Mesh( geoTgt, matTgt );
// boxTgt.position.set(tgtX, tgtY, tgtZ);
// scene.add(boxTgt);
var camera = BuoyAnalysisChart3.buildCamera();
camera.up.set( 0, 0, 1 );
camera.position.set(camX, camY, camZ);
var controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.target = new THREE.Vector3(tgtX, tgtY, tgtZ);
// // Range is 0 to Math.PI radians.
// controls.minPolarAngle = 50 * Math.PI / 180; // radians
// controls.maxPolarAngle = 90 * Math.PI / 180; // radians
// // How far you can orbit horizontally, upper and lower limits.
// // If set, must be a sub-interval of the interval [ - Math.PI, Math.PI ].
// controls.minAzimuthAngle = -90 * Math.PI / 180; // radians
// controls.maxAzimuthAngle = 0 * Math.PI / 180; // radians
controls.update();
(function animate() {
requestAnimationFrame(animate);
renderer.render(scene, camera);
controls.update();
})();
}
};

@ -17,4 +17,6 @@
.then(BuoyAnalysisChart.updateAxes)
.then(BuoyAnalysisChart.draw)
.then(BuoyAnalysisChart3.draw)
})();

@ -6,8 +6,8 @@ var BuoyAnalysisMap = {
*/
reticle: {
stations: [],
x: 450,
y: 550,
x: 200,
y: 300,
scale: d3.scale.linear()
.domain([0, 100])
.range([20, 350])
@ -41,6 +41,24 @@ var BuoyAnalysisMap = {
var station;
var stations = [];
var colors = [
'#f00',
'#d00',
'#b00',
'#900',
'#700',
'#0f0',
'#0d0',
'#0b0',
'#090',
'#070',
'#00f',
'#00d',
'#00b',
'#009',
'#007',
];
for (var prop in BuoyAnalysisData.stationJson) {
station = BuoyAnalysisData.stationJson[prop];
@ -58,8 +76,8 @@ var BuoyAnalysisMap = {
.attr('cy', function(d) { return d.y; })
.attr('r', 3)
.attr('id', function(d) { return 's' + d.id; })
.attr('fill', '#f00')
.attr('stroke', '#f00')
.attr('stroke', function(d, i) { return colors[i]; })
// .attr('stroke', '#f00')
.attr('stroke-width', 5)
},

@ -3,7 +3,7 @@
$axisW: 30px;
cursor:pointer;
height:100%;
height:880px;
left:540px;
position:absolute;
top:20px;

@ -0,0 +1,8 @@
#chart3 {
border:1px solid #f00;
height:260px;
left:20px;
position:absolute;
top:640px;
width:500px;
}

@ -1,6 +1,6 @@
// IMPORTANT: Run npm run watch to compile
$mainH: 900px;
$mainH: 920px;
$mainW: 800px;
* {
@ -21,5 +21,6 @@ $mainW: 800px;
}
@import 'chart';
@import 'chart3';
@import 'map';
@import 'options';

@ -1,5 +1,5 @@
#map {
background:#e8fbfe;
// background:#e8fbfe;
border:1px solid #e8e8e8;
height:600px;
position:relative;
@ -13,8 +13,10 @@
}
.feature {
fill:#dffbb8;
stroke:#bde484;
// fill:#dffbb8;
fill:#f7f7f7;
// stroke:#bde484;
stroke:#ccc;
}
.reticle {

@ -36,26 +36,26 @@ module.exports = {
'46042',
'46053',
'46054',
'46092',
// '46092',
'46213',
'46214',
'46215',
'46216',
'46217',
'46221',
// '46214',
// '46215',
// '46216',
// '46217',
// '46221',
'46223',
'46225',
// '46225',
'46232',
'46234',
'46237',
'46239',
'46240',
'46242',
'46244',
'46253',
'46254',
'46256',
'46257'
// '46234',
// '46237',
// '46239',
// '46240',
// '46242'
// '46244',
// '46253',
// '46254',
// '46256',
// '46257'
],
/**

File diff suppressed because it is too large Load Diff

958
vendor/three.min.js vendored

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save