|
| 1 | +/** |
| 2 | +* Copyright 2012-2018, Plotly, Inc. |
| 3 | +* All rights reserved. |
| 4 | +* |
| 5 | +* This source code is licensed under the MIT license found in the |
| 6 | +* LICENSE file in the root directory of this source tree. |
| 7 | +*/ |
| 8 | + |
| 9 | +'use strict'; |
| 10 | + |
| 11 | +var conePlot = require('gl-cone3d'); |
| 12 | +var simpleMap = require('../../lib').simpleMap; |
| 13 | +var parseColorScale = require('../../lib/gl_format_color').parseColorScale; |
| 14 | + |
| 15 | +function zip3(x, y, z) { |
| 16 | + var result = new Array(x.length); |
| 17 | + for(var i = 0; i < x.length; i++) { |
| 18 | + result[i] = [x[i], y[i], z[i]]; |
| 19 | + } |
| 20 | + return result; |
| 21 | +} |
| 22 | + |
| 23 | +var axisName2scaleIndex = {xaxis: 0, yaxis: 1, zaxis: 2}; |
| 24 | + |
| 25 | +exports.cone2mesh = function cone2mesh(trace, sceneLayout, dataScale) { |
| 26 | + var coneOpts = {}; |
| 27 | + var toDataCoords; |
| 28 | + |
| 29 | + if(Array.isArray(dataScale)) { |
| 30 | + toDataCoords = function(arr, axisName) { |
| 31 | + var ax = sceneLayout[axisName]; |
| 32 | + var scale = dataScale[axisName2scaleIndex[axisName]]; |
| 33 | + return simpleMap(arr, function(v) { return ax.d2l(v) * scale; }); |
| 34 | + }; |
| 35 | + } else { |
| 36 | + toDataCoords = function(arr, axisName) { |
| 37 | + return simpleMap(arr, sceneLayout[axisName].d2l); |
| 38 | + }; |
| 39 | + } |
| 40 | + |
| 41 | + coneOpts.vectors = zip3( |
| 42 | + toDataCoords(trace.u, 'xaxis'), |
| 43 | + toDataCoords(trace.v, 'yaxis'), |
| 44 | + toDataCoords(trace.w, 'zaxis') |
| 45 | + ); |
| 46 | + |
| 47 | + coneOpts.positions = zip3( |
| 48 | + toDataCoords(trace.x, 'xaxis'), |
| 49 | + toDataCoords(trace.y, 'yaxis'), |
| 50 | + toDataCoords(trace.z, 'zaxis') |
| 51 | + ); |
| 52 | + |
| 53 | + if(trace.vx && trace.vy && trace.vz) { |
| 54 | + coneOpts.meshgrid = [ |
| 55 | + toDataCoords(trace.vx, 'xaxis'), |
| 56 | + toDataCoords(trace.vy, 'yaxis'), |
| 57 | + toDataCoords(trace.vz, 'zaxis') |
| 58 | + ]; |
| 59 | + } |
| 60 | + |
| 61 | + coneOpts.colormap = parseColorScale(trace.colorscale); |
| 62 | + coneOpts.vertexIntensityBounds = [trace.cmin, trace.cmax]; |
| 63 | + |
| 64 | + // sizemode: |
| 65 | + // sizeref, |
| 66 | + coneOpts.coneSize = 2; |
| 67 | + |
| 68 | + return conePlot(coneOpts); |
| 69 | +}; |
0 commit comments