8000 Add fill gradients for scatter traces by lumip · Pull Request #6905 · plotly/plotly.js · GitHub
[go: up one dir, main page]

Skip to content

Add fill gradients for scatter traces #6905

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 10 commits into from
Mar 6, 2024
Prev Previous commit
Next Next commit
Changed scatter attribute fillgradient.orientation to fillgradient.ty…
…pe for greater consistency with marker.gradient.type
  • Loading branch information
lumip committed Feb 28, 2024
commit 4c56fa819241ba5561e8bcdb985de80d0373f5f0
4 changes: 2 additions & 2 deletions src/components/drawing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ function setFillStyle(sel, trace, gd, forLegend) {
undefined, markerPattern.fillmode,
patternBGColor, patternFGColor, patternFGOpacity
);
} else if(fillgradient && fillgradient.orientation !== 'none') {
var direction = fillgradient.orientation;
} else if(fillgradient && fillgradient.type !== 'none') {
var direction = fillgradient.type;
var gradientID = 'scatterfill-' + trace.uid;
if(forLegend) {
gradientID = 'legendfill-' + trace.uid;
Expand Down
6 changes: 3 additions & 3 deletions src/traces/scatter/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,13 @@ module.exports = {
].join(' ')
},
fillgradient: extendFlat({
orientation: {
type: {
valType: 'enumerated',
values: ['radial', 'horizontal', 'vertical', 'none'],
dflt: 'none',
editType: 'style',
editType: 'calc',
description: [
'Sets the orientation of the color gradient.',
'Sets the type/orientation of the color gradient for the fill.',
'Defaults to *none*.'
].join(' ')
},
Expand Down
2 changes: 1 addition & 1 deletion src/traces/scatter/fillcolor_defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function fillColorDefaults(traceIn, traceOut, defaultColor, coe
// to specifiy fillcolor after all other more specific candidates
// are considered, but before the global default color.
// fillcolor affects the background color of the hoverlabel in this case.
var gradientOrientation = coerce('fillgradient.orientation');
var gradientOrientation = coerce('fillgradient.type');
if(gradientOrientation !== 'none') {
coerce('fillgradient.start');
coerce('fillgradient.stop');
Expand Down
4 changes: 2 additions & 2 deletions test/image/mocks/zz-scatter_fill_gradient_tonext.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"fill": "tonext",
"hoveron": "points+fills",
"fillgradient": {
"orientation": "horizontal",
"type": "horizontal",
"colorscale": [
[0.0, "rgba(0, 255, 0, 1)"],
[0.5, "rgba(0, 255, 0, 0)"],
Expand All @@ -24,7 +24,7 @@
"fill": "tonext",
"hoveron": "fills+points",
"fillgradient": {
"orientation": "radial",
"type": "radial",
"colorscale": [
[0.0, "rgba(255, 255, 0, 0.0)"],
[0.8, "rgba(255, 0, 0, 0.3)"],
Expand Down
8 changes: 4 additions & 4 deletions test/image/mocks/zz-scatter_fill_gradient_tonexty_toself.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"fill": "tonexty",
"fillcolor": "rgba(0, 255, 0, .5)",
"fillgradient": {
"orientation": "horizontal",
"type": "horizontal",
"colorscale": [
[0.0, "rgba(0, 255, 0, 1)"],
[0.5, "rgba(0, 255, 0, 0)"],
Expand All @@ -28,7 +28,7 @@
"fill": "tonexty",
"hoveron": "fills+points",
"fillgradient": {
"orientation": "horizontal",
"type": "horizontal",
"colorscale": [
[0.0, "rgba(255, 255, 0, 1.0)"],
[0.6, "rgba(255, 255, 0, 1.0)"],
Expand All @@ -44,7 +44,7 @@
"mode": "none",
"fill": "toself",
"fillgradient": {
"orientation": "vertical",
"type": "vertical",
"colorscale": [
[0.0, "rgba(255, 0, 0, 0.8)"],
[1.0, "rgba(0, 0, 255, 0.9)"]
Expand All @@ -60,7 +60,7 @@
"mode": "none",
"fill": "toself",
"fillgradient": {
"orientation": "vertical",
"type": "vertical",
"colorscale": [
[0.0, "rgba(255, 0, 0, 0.8)"],
[1.0, "rgba(0, 0, 255, 0.9)"]
Expand Down
27 changes: 13 additions & 14 deletions test/plot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -45041,25 +45041,12 @@
},
"fillgradient": {
"colorscale": {
"anim": true,
"description": "Sets the fill gradient colors as a color scale. The color scale is interpreted as a gradient applied in the direction specified by *orientation*, from the lowest to the highest value of the scatter plot along that axis, or from the center to the most distant point from it, if orientation is *radial*.",
"editType": "style",
"valType": "colorscale"
},
"description": "Sets a fill gradient. If not specified, the fillcolor is used instead.",
"editType": "style",
"orientation": {
"description": "Sets the orientation of the color gradient. Defaults to *none*.",
"dflt": "none",
"editType": "style",
"valType": "enumerated",
"values": [
"radial",
"horizontal",
"vertical",
"none"
]
},
"editType": "calc",
"role": "object",
"start": {
"description": "Sets the gradient start value. It is given as the absolute position on the axis determined by the orientiation. E.g., if orientation is *horizontal*, the gradient will be horizontal and start from the x-position given by start. If omitted, the gradient starts at the lowest value of the trace along the respective axis. Ignored if orientation is *radial*.",
Expand All @@ -45070,6 +45057,18 @@
"description": "Sets the gradient end value. It is given as the absolute position on the axis determined by the orientiation. E.g., if orientation is *horizontal*, the gradient will be horizontal and end at the x-position given by end. If omitted, the gradient ends at the highest value of the trace along the respective axis. Ignored if orientation is *radial*.",
"editType": "calc",
"valType": "number"
},
"type": {
"description": "Sets the type/orientation of the color gradient for the fill. Defaults to *none*.",
"dflt": "none",
"editType": "calc",
"valType": "enumerated",
"values": [
"radial",
"horizontal",
"vertical",
"none"
]
}
},
"fillpattern": {
Expand Down
0