-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
bar3d
new trace type
#7003
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
Open
bar3d
new trace type
#7003
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions
lib/bar3d.js
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,3 @@ | ||
'use strict'; | ||
|
||
module.exports = require('../src/traces/bar3d'); |
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
151 changes: 151 additions & 0 deletions
src/traces/bar3d/attributes.js
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,151 @@ | ||
'use strict'; | ||
|
||
var colorScaleAttrs = require('../../components/colorscale/attributes'); | ||
var axisHoverFormat = require('../../plots/cartesian/axis_format_attributes').axisHoverFormat; | ||
var hovertemplateAttrs = require('../../plots/template_attributes').hovertemplateAttrs; | ||
var meshAttrs = require('../mesh3d/attributes'); | ||
var baseAttrs = require('../../plots/attributes'); | ||
|
||
var extendFlat = require('../../lib/extend').extendFlat; | ||
var overrideAll = require('../../plot_api/edit_types').overrideAll; | ||
|
||
var attrs = module.exports = overrideAll(extendFlat({ | ||
x: { | ||
valType: 'data_array', | ||
description: [ | ||
'Sets the X coordinates of bars on X axis.' | ||
].join(' ') | ||
}, | ||
y: { | ||
valType: 'data_array', | ||
description: [ | ||
'Sets the Y coordinates of bars on Y axis.' | ||
].join(' ') | ||
}, | ||
base: { | ||
valType: 'data_array', | ||
description: [ | ||
'Sets the Z coordinates (i.e. the base) of bars on Z axis.' | ||
].join(' ') | ||
}, | ||
value: { | ||
valType: 'data_array', | ||
description: [ | ||
'Sets the height of bars.' | ||
].join(' ') | ||
}, | ||
|
||
showbase: { | ||
valType: 'boolean', | ||
dflt: false, | ||
editType: 'calc', | ||
description: [ | ||
'Determines whether or not the base of a bar is filled.' | ||
].join(' ') | ||
}, | ||
|
||
xgap: { | ||
valType: 'number', | ||
min: 0, | ||
max: 1, | ||
dflt: 0.2, | ||
editType: 'calc', | ||
description: [ | ||
'Sets the gap (in plot fraction) between bars of', | ||
'adjacent location coordinates on X axis.' | ||
].join(' ') | ||
}, | ||
|
||
ygap: { | ||
valType: 'number', | ||
min: 0, | ||
max: 1, | ||
dflt: 0.2, | ||
editType: 'calc', | ||
description: [ | ||
'Sets the gap (in plot fraction) between bars of', | ||
'adjacent location coordinates on Y axis.' | ||
].join(' ') | ||
}, | ||
|
||
marker: { | ||
color: { | ||
valType: 'color', | ||
dflt: '#eee', // TODO: Is this a good default? | ||
// TODO: support arrayOk | ||
editType: 'calc', | ||
description: [ | ||
'Sets the color of the whole mesh if `coloring` is set to *color*.' | ||
].join(' ') | ||
}, | ||
coloring: { | ||
valType: 'enumerated', | ||
values: ['color', 'fill', 'heatmap'], | ||
dflt: 'heatmap', | ||
editType: 'calc', | ||
description: [ | ||
'Determines the coloring method showing the bar values.', | ||
'If *color*, *marker.color* is used for all bars.', | ||
'If *fill*, coloring is done evenly across a single bar.', | ||
'If *heatmap*, a heatmap gradient coloring is applied', | ||
'between each level from bottom to top.' | ||
].join(' ') | ||
}, | ||
fill: { | ||
valType: 'number', | ||
min: 0, | ||
max: 1, | ||
dflt: 1, | ||
description: [ | ||
'Sets the fill ratio of the `marker` elements. The default fill value', | ||
'is 0.15 meaning that only 15% of the area of every faces of tetras would be', | ||
'shaded. Applying a greater `fill` ratio would allow the creation of stronger', | ||
'elements or could be sued to have entirely closed areas (in case of using 1).' | ||
].join(' ') | ||
}, | ||
}, | ||
|
||
text: { | ||
valType: 'string', | ||
dflt: '', | ||
arrayOk: true, | ||
description: [ | ||
'Sets the text elements associated with the vertices.', | ||
'If trace `hoverinfo` contains a *text* flag and *hovertext* is not set,', | ||
'these elements will be seen in the hover labels.' | ||
].join(' ') | ||
}, | ||
hovertext: { | ||
valType: 'string', | ||
dflt: '', | ||
arrayOk: true, | ||
description: 'Same as `text`.' | ||
}, | ||
hovertemplate: hovertemplateAttrs(), | ||
xhoverformat: axisHoverFormat('x'), | ||
yhoverformat: axisHoverFormat('y'), | ||
zhoverformat: axisHoverFormat('z'), | ||
valuehoverformat: axisHoverFormat('value', 1), | ||
|
||
showlegend: extendFlat({}, baseAttrs.showlegend, {dflt: false}) | ||
}, | ||
|
||
colorScaleAttrs('', { | ||
colorAttr: '`value`', | ||
showScaleDflt: true, | ||
editTypeOverride: 'calc' | ||
}), { | ||
opacity: meshAttrs.opacity, | ||
lightposition: meshAttrs.lightposition, | ||
lighting: meshAttrs.lighting, | ||
flatshading: meshAttrs.flatshading, | ||
contour: meshAttrs.contour, | ||
|
||
hoverinfo: extendFlat({}, baseAttrs.hoverinfo) | ||
}), 'calc', 'nested'); | ||
|
||
// required defaults to speed up surface normal calculations | ||
attrs.flatshading.dflt = true; attrs.lighting.facenormalsepsilon.dflt = 0; | ||
|
||
attrs.x.editType = attrs.y.editType = attrs.base.editType = attrs.value.editType = 'calc+clearAxisTypes'; | ||
attrs.transforms = undefined; |
45 changes: 45 additions & 0 deletions
src/traces/bar3d/calc.js
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,45 @@ | ||
'use strict'; | ||
|
||
var colorscaleCalc = require('../../components/colorscale/calc'); | ||
var filter = require('../streamtube/calc').filter; | ||
|
||
module.exports = function calc(gd, trace) { | ||
var i; | ||
var len = Math.min( | ||
trace.x.length, | ||
trace.y.length, | ||
trace.value.length | ||
); | ||
|
||
trace._len = len; | ||
trace._value = filter(trace.value, len); | ||
trace._Xs = filter(trace.x, len); | ||
trace._Ys = filter(trace.y, len); | ||
|
||
if(!trace.base) trace.base = new Array(len).fill(0); // TODO: Improve me! | ||
trace.z = trace.base; // TODO: why we need to add z to trace? | ||
|
||
trace._Zs = filter(trace.base, len); | ||
|
||
for(i = 0; i < trace._Zs.length; i++) { | ||
var base = trace._Zs[i]; | ||
if(!base || isNaN(base)) trace._Zs[i] = 0; | ||
} | ||
|
||
var min = Infinity; | ||
var max = -Infinity; | ||
for(i = 0; i < trace._len; i++) { | ||
var h = | ||
trace._Zs[i] + | ||
trace._value[i]; | ||
|
||
min = Math.min(min, h); | ||
max = Math.max(max, h); | ||
} | ||
|
||
colorscaleCalc(gd, trace, { | ||
vals: [min, max], | ||
containerStr: '', | ||
cLetter: 'c' | ||
}); | ||
}; |
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.