|
9 | 9 |
|
10 | 10 | 'use strict';
|
11 | 11 |
|
12 |
| -var Plotly = require('../../plotly'); |
13 | 12 | var d3 = require('d3');
|
14 | 13 | var isNumeric = require('fast-isnumeric');
|
15 | 14 |
|
| 15 | +var Plotly = require('../../plotly'); |
| 16 | + |
| 17 | +var subtypes = require('./subtypes'); |
| 18 | + |
16 | 19 | var scatter = module.exports = {};
|
17 | 20 |
|
| 21 | +scatter.hasLines = subtypes.hasLines; |
| 22 | +scatter.hasMarkers = subtypes.hasMarkers; |
| 23 | +scatter.hasText = subtypes.hasText; |
| 24 | +scatter.isBubble = subtypes.isBubble; |
| 25 | + |
| 26 | +scatter.selectPoints = require('./select'); |
| 27 | + |
18 | 28 | Plotly.Plots.register(scatter, 'scatter',
|
19 | 29 | ['cartesian', 'symbols', 'markerColorscale', 'errorBarsOK', 'showLegend'], {
|
20 | 30 | description: [
|
@@ -196,26 +206,6 @@ scatter.cleanData = function(fullData) {
|
196 | 206 | }
|
197 | 207 | };
|
198 | 208 |
|
199 |
| -scatter.hasLines = function(trace) { |
200 |
| - return trace.visible && trace.mode && |
201 |
| - trace.mode.indexOf('lines') !== -1; |
202 |
| -}; |
203 |
| - |
204 |
| -scatter.hasMarkers = function(trace) { |
205 |
| - return trace.visible && trace.mode && |
206 |
| - trace.mode.indexOf('markers') !== -1; |
207 |
| -}; |
208 |
| - |
209 |
| -scatter.hasText = function(trace) { |
210 |
| - return trace.visible && trace.mode && |
211 |
| - trace.mode.indexOf('text') !== -1; |
212 |
| -}; |
213 |
| - |
214 |
| -scatter.isBubble = function(trace) { |
215 |
| - return (typeof trace.marker === 'object' && |
216 |
| - Array.isArray(trace.marker.size)); |
217 |
| -}; |
218 |
| - |
219 | 209 | scatter.colorbar = require('./colorbar');
|
220 | 210 |
|
221 | 211 | // used in the drawing step for 'scatter' and 'scattegeo' and
|
@@ -455,17 +445,17 @@ scatter.plot = function(gd, plotinfo, cdscatter) {
|
455 | 445 | tozero,tonext,nexttonext;
|
456 | 446 | scattertraces.each(function(d){
|
457 | 447 | var trace = d[0].trace,
|
458 |
| - line = trace.line; |
| 448 | + line = trace.line, |
| 449 | + tr = d3.select(this); |
459 | 450 | if(trace.visible !== true) return;
|
460 | 451 |
|
461 |
| - d[0].node = this; // store node for tweaking by selectPoints |
| 452 | + d[0].node3 = tr; // store node for tweaking by selectPoints |
462 | 453 |
|
463 | 454 | scatter.arraysToCalcdata(d);
|
464 | 455 |
|
465 | 456 | if(!scatter.hasLines(trace) && trace.fill==='none') return;
|
466 | 457 |
|
467 |
| - var tr = d3.select(this), |
468 |
| - thispath, |
| 458 | + var thispath, |
469 | 459 | // fullpath is all paths for this curve, joined together straight
|
470 | 460 | // across gaps, for filling
|
471 | 461 | fullpath = '',
|
@@ -857,54 +847,3 @@ scatter.hoverPoints = function(pointData, xval, yval, hovermode) {
|
857 | 847 |
|
858 | 848 | return [pointData];
|
859 | 849 | };
|
860 |
| - |
861 |
| -var DESELECTDIM = 0.2; |
862 |
| - |
863 |
| -scatter.selectPoints = function(searchInfo, polygon) { |
864 |
| - var cd = searchInfo.cd, |
865 |
| - xa = searchInfo.xaxis, |
866 |
| - ya = searchInfo.yaxis, |
867 |
| - selection = [], |
868 |
| - trace = cd[0].trace, |
869 |
| - curveNumber = trace.index, |
870 |
| - marker = trace.marker, |
871 |
| - i, |
872 |
| - di, |
873 |
| - x, |
874 |
| - y; |
875 |
| - |
876 |
| - if(!scatter.hasMarkers(trace)) return; // TODO: include text and/or lines? |
877 |
| - |
878 |
| - var opacity = Array.isArray(marker.opacity) ? 1 : marker.opacity; |
879 |
| - |
880 |
| - if(polygon === false) { // clear selection |
881 |
| - for(i = 0; i < cd.length; i++) cd[i].dim = 0; |
882 |
| - } |
883 |
| - else { |
884 |
| - for(i = 0; i < cd.length; i++) { |
885 |
| - di = cd[i]; |
886 |
| - x = xa.c2p(di.x); |
887 |
| - y = ya.c2p(di.y); |
888 |
| - if(polygon.contains([x, y])) { |
889 |
| - selection.push({ |
890 |
| - curveNumber: curveNumber, |
891 |
| - pointNumber: i, |
892 |
| - x: di.x, |
893 |
| - y: di.y |
894 |
| - }); |
895 |
| - di.dim = 0; |
896 |
| - } |
897 |
| - else di.dim = 1; |
898 |
| - } |
899 |
| - } |
900 |
| - |
901 |
| - // do the dimming here, as well as returning the selection |
902 |
| - // The logic here duplicates Drawing.pointStyle, but I don't want |
903 |
| - // d.dim in pointStyle in case something goes wrong with selection. |
904 |
| - d3.select(cd[0].node).selectAll('path.point') |
905 |
| - .style('opacity', function(d) { |
906 |
| - return ((d.mo+1 || opacity+1) - 1) * (d.dim ? DESELECTDIM : 1); |
907 |
| - }); |
908 |
| - |
909 |
| - return selection; |
910 |
| -}; |
0 commit comments