8000 `bar3d` new trace type by archmoj · Pull Request #7003 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

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
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
voila
  • Loading branch information
archmoj committed May 24, 2024
commit 6077a3f59488826c75d389e65c1f248cc1c9de81
185 changes: 50 additions & 135 deletions src/traces/bar3d/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,121 +9,86 @@ var baseAttrs = require('../../plots/attributes');
var extendFlat = require('../../lib/extend').extendFlat;
var overrideAll = require('../../plot_api/edit_types').overrideAll;

function makeSliceAttr(axLetter) {
return {
show: {
valType: 'boolean',
dflt: false,
description: [
'Determines whether or not slice planes about the', axLetter,
'dimension are drawn.'
].join(' ')
},
locations: {
valType: 'data_array',
dflt: [],
description: [
'Specifies the location(s) of slices on the axis.',
'When not specified slices would be created for',
'all points of the axis', axLetter, 'except start and end.'
].join(' ')
},
fill: {
valType: 'number',
min: 0,
max: 1,
dflt: 1,
description: [
'Sets the fill ratio of the `slices`. The default fill value of the',
'`slices` is 1 meaning that they are entirely shaded. On the other hand',
'Applying a `fill` ratio less than one would allow the creation of',
'openings parallel to the edges.'
].join(' ')
}
};
}

function makeCapAttr(axLetter) {
return {
show: {
valType: 'boolean',
dflt: true,
description: [
'Sets the fill ratio of the `slices`. The default fill value of the', axLetter,
'`slices` is 1 meaning that they are entirely shaded. On the other hand',
'Applying a `fill` ratio less than one would allow the creation of',
'openings parallel to the edges.'
].join(' ')
},
fill: {
valType: 'number',
min: 0,
max: 1,
dflt: 1,
description: [
'Sets the fill ratio of the `caps`. The default fill value of the',
'`caps` is 1 meaning that they are entirely shaded. On the other hand',
'Applying a `fill` ratio less than one would allow the creation of',
'openings parallel to the edges.'
].join(' ')
}
};
}

var attrs = module.exports = overrideAll(extendFlat({
x: {
valType: 'data_array',
description: [
'Sets the X coordinates of the vertices on X axis.'
'Sets the X coordinates of bars on X axis.'
].join(' ')
},
y: {
valType: 'data_array',
description: [
'Sets the Y coordinates of the vertices on Y axis.'
'Sets the Y coordinates of bars on Y axis.'
].join(' ')
},
z: {
base: {
valType: 'data_array',
description: [
'Sets the Z coordinates of the vertices on Z axis.'
'Sets the Z coordinates (i.e. the base) of bars on Z axis.'
].join(' ')
},
value: {
valType: 'data_array',
description: [
'Sets the 4th dimension (value) of the vertices.'
'Sets the height of bars.'
].join(' ')
},
isomin: {

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 minimum boundary for iso-surface plot.'
'Sets the gap (in plot fraction) between bars of',
'adjacent location coordinates on X axis.'
].join(' ')
},
isomax: {

ygap: {
valType: 'number',
min: 0,
max: 1,
dflt: 0.2,
editType: 'calc',
description: [
'Sets the maximum boundary for iso-surface plot.'
'Sets the gap (in plot fraction) between bars of',
'adjacent location coordinates on Y axis.'
].join(' ')
},

surface: {
show: {
valType: 'boolean',
dflt: true,
marker: {
color: {
valType: 'color',
dflt: '#eee', // TODO: Is this a good default?
// TODO: support arrayOk
editType: 'calc',
description: [
'Hides/displays surfaces between minimum and maximum iso-values.'
'Sets the color of the whole mesh if `coloring` is set to *color*.'
].join(' ')
},
count: {
valType: 'integer',
dflt: 2,
min: 1,
coloring: {
valType: 'enumerated',
values: ['color', 'fill', 'heatmap'],
dflt: 'heatmap',
editType: 'calc',
description: [
'Sets the number of iso-surfaces between minimum and maximum iso-values.',
'By default this value is 2 meaning that only minimum and maximum surfaces',
'would be drawn.'
'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: {
Expand All @@ -132,62 +97,12 @@ var attrs = module.exports = overrideAll(extendFlat({
max: 1,
dflt: 1,
description: [
'Sets the fill ratio of the iso-surface. The default fill value of the',
'surface is 1 meaning that they are entirely shaded. On the other hand',
'Applying a `fill` ratio less than one would allow the creation of',
'openings parallel to the edges.'
].join(' ')
},
pattern: {
valType: 'flaglist',
flags: ['A', 'B', 'C', 'D', 'E'],
extras: ['all', 'odd', 'even'],
dflt: 'all',
description: [
'Sets the surface pattern of the iso-surface 3-D sections. The default pattern of',
'the surface is `all` meaning that the rest of surface elements would be shaded.',
'The check options (either 1 or 2) could be used to draw half of the squares',
'on the surface. Using various combinations of capital `A`, `B`, `C`, `D` and `E`',
'may also be used to reduce the number of triangles on the iso-surfaces and',
'creating other patterns of interest.'
].join(' ')
}
},

spaceframe: {
show: {
valType: 'boolean',
dflt: false,
description: [
'Displays/hides tetrahedron shapes between minimum and',
'maximum iso-values. Often useful when either caps or',
'surfaces are disabled or filled with values less than 1.'
].join(' ')
},
fill: {
valType: 'number',
min: 0,
max: 1,
dflt: 0.15,
description: [
'Sets the fill ratio of the `spaceframe` elements. The default fill value',
'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(' ')
}
},

slices: {
x: makeSliceAttr('x'),
y: makeSliceAttr('y'),
z: makeSliceAttr('z')
},

caps: {
x: makeCapAttr('x'),
y: makeCapAttr('y'),
z: makeCapAttr('z')
},
},

text: {
Expand Down Expand Up @@ -232,5 +147,5 @@ colorScaleAttrs('', {
// required defaults to speed up surface normal calculations
attrs.flatshading.dflt = true; attrs.lighting.facenormalsepsilon.dflt = 0;

attrs.x.editType = attrs.y.editType = attrs.z.editType = attrs.value.editType = 'calc+clearAxisTypes';
attrs.x.editType = attrs.y.editType = attrs.base.editType = attrs.value.editType = 'calc+clearAxisTypes';
attrs.transforms = undefined;
46 changes: 23 additions & 23 deletions src/traces/bar3d/calc.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
'use strict';

var colorscaleCalc = require('../../components/colorscale/calc');
var processGrid = require('../streamtube/calc').processGrid;
var filter = require('../streamtube/calc').filter;

module.exports = function calc(gd, trace) {
trace._len = Math.min(
var i;
var len = Math.min(
trace.x.length,
trace.y.length,
trace.z.length,
trace.value.length
);

trace._x = filter(trace.x, trace._len);
trace._y = filter(trace.y, trace._len);
trace._z = filter(trace.z, trace._len);
trace._value = filter(trace.value, trace._len);
trace._len = len;
trace._value = filter(trace.value, len);
trace._Xs = filter(trace.x, len);
trace._Ys = filter(trace.y, len);

var grid = processGrid(trace);
trace._gridFill = grid.fill;
trace._Xs = grid.Xs;
trace._Ys = grid.Ys;
trace._Zs = grid.Zs;
trace._len = grid.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(var i = 0; i < trace._len; i++) {
var v = trace._value[i];
min = Math.min(min, v);
max = Math.max(max, v);
}
for(i = 0; i < trace._len; i++) {
var h =
trace._Zs[i] +
trace._value[i];

trace._minValues = min;
trace._maxValues = max;
trace._vMin = (trace.isomin === undefined || trace.isomin === null) ? min : trace.isomin;
trace._vMax = (trace.isomax === undefined || trace.isomin === null) ? max : trace.isomax;
min = Math.min(min, h);
max = Math.max(max, h);
}

colorscaleCalc(gd, trace, {
vals: [trace._vMin, trace._vMax],
vals: [min, max],
containerStr: '',
cLetter: 'c'
});
Expand Down
Loading
0