Skip to content
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

bar3d new trace type #7003

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/bar3d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('../src/traces/bar3d');
1 change: 1 addition & 0 deletions lib/index-gl3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Plotly.register([
require('./surface'),
require('./isosurface'),
require('./volume'),
require('./bar3d'),
require('./mesh3d'),
require('./cone'),
require('./streamtube'),
Expand Down
1 change: 1 addition & 0 deletions lib/index-strict.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Plotly.register([
require('./surface'),
require('./isosurface'),
require('./volume'),
require('./bar3d'),
require('./mesh3d'),
require('./cone'),
require('./streamtube'),
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Plotly.register([
require('./surface'),
require('./isosurface'),
require('./volume'),
require('./bar3d'),
require('./mesh3d'),
require('./cone'),
require('./streamtube'),
Expand Down
8 changes: 8 additions & 0 deletions src/components/legend/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,14 @@ module.exports = function style(s, gd, legend) {
];
useGradient = false;
break;
case 'bar3d' :
ptsData = [ // TODO: Fix me!
['M-6,6H0L-6,-6Z'],
['M6,6H0L6,-6Z'],
['M-6,-6H6L0,6Z']
];
useGradient = false;
break;
}
}

Expand Down
151 changes: 151 additions & 0 deletions src/traces/bar3d/attributes.js
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
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'
});
};
Loading