-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Split scatter module #184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Split scatter module #184
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
94b2098
split up scatter defaults in separate files:
etpinard 6002788
move scatter PTS_LINESONLY in constant into separate file:
etpinard b418b5f
rename getBubbleSizFn -> makeBubbleSizeFn + put it separate file
etpinard f86673c
put hoverPoint and getTraceColor in separate files
etpinard 71ad19b
require scatter subTypes directly,
etpinard 6337313
put scatter3d calc in separate, use it in scattergl
etpinard 6757bee
split up scatter methods into separate files
etpinard 3a6b49c
require scatter components directly into jasmine test file
etpinard 0be5d33
lint ('comma-spacing', 'key-spacing', some 'space-infix-ops')
etpinard 2b3081a
rm Scatter from internal Plotly object
etpinard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* Copyright 2012-2016, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
'use strict'; | ||
|
||
var Lib = require('../../lib'); | ||
|
||
|
||
// arrayOk attributes, merge them into calcdata array | ||
module.exports = function arraysToCalcdata(cd) { | ||
var trace = cd[0].trace, | ||
marker = trace.marker; | ||
|
||
Lib.mergeArray(trace.text, cd, 'tx'); | ||
Lib.mergeArray(trace.textposition, cd, 'tp'); | ||
if(trace.textfont) { | ||
Lib.mergeArray(trace.textfont.size, cd, 'ts'); | ||
Lib.mergeArray(trace.textfont.color, cd, 'tc'); | ||
Lib.mergeArray(trace.textfont.family, cd, 'tf'); | ||
} | ||
|
||
if(marker && marker.line) { | ||
var markerLine = marker.line; | ||
Lib.mergeArray(marker.opacity, cd, 'mo'); | ||
Lib.mergeArray(marker.symbol, cd, 'mx'); | ||
Lib.mergeArray(marker.color, cd, 'mc'); | ||
Lib.mergeArray(markerLine.color, cd, 'mlc'); | ||
Lib.mergeArray(markerLine.width, cd, 'mlw'); | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/** | ||
* Copyright 2012-2016, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
'use strict'; | ||
|
||
var isNumeric = require('fast-isnumeric'); | ||
|
||
var Axes = require('../../plots/cartesian/axes'); | ||
var Lib = require('../../lib'); | ||
|
||
var subTypes = require('./subtypes'); | ||
var calcMarkerColorscale = require('./marker_colorscale_calc'); | ||
|
||
|
||
module.exports = function calc(gd, trace) { | ||
var xa = Axes.getFromId(gd, trace.xaxis || 'x'), | ||
ya = Axes.getFromId(gd, trace.yaxis || 'y'); | ||
Lib.markTime('in Scatter.calc'); | ||
|
||
var x = xa.makeCalcdata(trace, 'x'); | ||
Lib.markTime('finished convert x'); | ||
|
||
var y = ya.makeCalcdata(trace, 'y'); | ||
Lib.markTime('finished convert y'); | ||
|
||
var serieslen = Math.min(x.length, y.length), | ||
marker, | ||
s, | ||
i; | ||
|
||
// cancel minimum tick spacings (only applies to bars and boxes) | ||
xa._minDtick = 0; | ||
ya._minDtick = 0; | ||
|
||
if(x.length > serieslen) x.splice(serieslen, x.length - serieslen); | ||
if(y.length > serieslen) y.splice(serieslen, y.length - serieslen); | ||
|
||
// check whether bounds should be tight, padded, extended to zero... | ||
// most cases both should be padded on both ends, so start with that. | ||
var xOptions = {padded: true}, | ||
yOptions = {padded: true}; | ||
|
||
if(subTypes.hasMarkers(trace)) { | ||
|
||
// Treat size like x or y arrays --- Run d2c | ||
// this needs to go before ppad computation | ||
marker = trace.marker; | ||
s = marker.size; | ||
|
||
if (Array.isArray(s)) { | ||
// I tried auto-type but category and dates dont make much sense. | ||
var ax = {type: 'linear'}; | ||
Axes.setConvert(ax); | ||
s = ax.makeCalcdata(trace.marker, 'size'); | ||
if(s.length > serieslen) s.splice(serieslen, s.length - serieslen); | ||
} | ||
|
||
var sizeref = 1.6 * (trace.marker.sizeref || 1), | ||
markerTrans; | ||
if(trace.marker.sizemode === 'area') { | ||
markerTrans = function(v) { | ||
return Math.max(Math.sqrt((v || 0) / sizeref), 3); | ||
}; | ||
} | ||
else { | ||
markerTrans = function(v) { | ||
return Math.max((v || 0) / sizeref, 3); | ||
}; | ||
} | ||
xOptions.ppad = yOptions.ppad = Array.isArray(s) ? | ||
s.map(markerTrans) : markerTrans(s); | ||
} | ||
|
||
calcMarkerColorscale(trace); | ||
|
||
// TODO: text size | ||
|
||
// include zero (tight) and extremes (padded) if fill to zero | ||
// (unless the shape is closed, then it's just filling the shape regardless) | ||
if(((trace.fill === 'tozerox') || | ||
((trace.fill === 'tonextx') && gd.firstscatter)) && | ||
((x[0] !== x[serieslen - 1]) || (y[0] !== y[serieslen - 1]))) { | ||
xOptions.tozero = true; | ||
} | ||
|
||
// if no error bars, markers or text, or fill to y=0 remove x padding | ||
else if(!trace.error_y.visible && ( | ||
['tonexty', 'tozeroy'].indexOf(trace.fill) !== -1 || | ||
(!subTypes.hasMarkers(trace) && !subTypes.hasText(trace)) | ||
)) { | ||
xOptions.padded = false; | ||
xOptions.ppad = 0; | ||
} | ||
|
||
// now check for y - rather different logic, though still mostly padded both ends | ||
// include zero (tight) and extremes (padded) if fill to zero | ||
// (unless the shape is closed, then it's just filling the shape regardless) | ||
if(((trace.fill === 'tozeroy') || ((trace.fill === 'tonexty') && gd.firstscatter)) && | ||
((x[0] !== x[serieslen - 1]) || (y[0] !== y[serieslen - 1]))) { | ||
yOptions.tozero = true; | ||
} | ||
|
||
// tight y: any x fill | ||
else if(['tonextx', 'tozerox'].indexOf(trace.fill) !== -1) { | ||
yOptions.padded = false; | ||
} | ||
|
||
Lib.markTime('ready for Axes.expand'); | ||
Axes.expand(xa, x, xOptions); | ||
Lib.markTime('done expand x'); | ||
Axes.expand(ya, y, yOptions); | ||
Lib.markTime('done expand y'); | ||
|
||
// create the "calculated data" to plot | ||
var cd = new Array(serieslen); | ||
for(i = 0; i < serieslen; i++) { | ||
cd[i] = (isNumeric(x[i]) && isNumeric(y[i])) ? | ||
{x: x[i], y: y[i]} : {x: false, y: false}; | ||
} | ||
|
||
// this has migrated up from arraysToCalcdata as we have a reference to 's' here | ||
if (typeof s !== undefined) Lib.mergeArray(s, cd, 'ms'); | ||
|
||
gd.firstscatter = false; | ||
return cd; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright 2012-2016, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
'use strict'; | ||
|
||
|
||
module.exports = function cleanData(fullData) { | ||
var i, | ||
tracei, | ||
filli, | ||
j, | ||
tracej; | ||
|
||
// remove opacity for any trace that has a fill or is filled to | ||
for(i = 0; i < fullData.length; i++) { | ||
tracei = fullData[i]; | ||
filli = tracei.fill; | ||
if((filli === 'none') || (tracei.type !== 'scatter')) continue; | ||
tracei.opacity = undefined; | ||
|
||
if(filli === 'tonexty' || filli === 'tonextx') { | ||
for(j = i - 1; j >= 0; j--) { | ||
tracej = fullData[j]; | ||
if((tracej.type === 'scatter') && | ||
(tracej.xaxis === tracei.xaxis) && | ||
(tracej.yaxis === tracei.yaxis)) { | ||
tracej.opacity = undefined; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Copyright 2012-2016, Plotly, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
PTS_LINESONLY: 20 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. slightly abusive, but it's the only way to clear us of circular dependencies while keeping things 🌴 |
||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the
.enter()
line is only indented 2.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a pretty normal pattern in d3, because
.enter()
is changing the selection so we want people to know it's not quite part of the normal method chain.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd vote for keeping the classic d3 style here.
Plus, it passed the eslint indent rule check, so nothing to worry.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh I see. Carry on then 😆