Skip to content

Commit 28735ff

Browse files
committed
Add message to traces with no opacity
1 parent 9824a02 commit 28735ff

File tree

5 files changed

+305
-274
lines changed

5 files changed

+305
-274
lines changed

src/components/containers/Section.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ import Info from '../fields/Info';
22
import MenuPanel from './MenuPanel';
33
import React, {Component, cloneElement} from 'react';
44
import PropTypes from 'prop-types';
5-
import unpackPlotProps from '../../lib/unpackPlotProps';
6-
import {containerConnectedContextTypes} from '../../lib/connectToContainer';
5+
import {
6+
containerConnectedContextTypes,
7+
localize,
8+
unpackPlotProps,
9+
} from '../../lib';
710

8-
export default class Section extends Component {
11+
class Section extends Component {
912
constructor(props, context) {
1013
super(props, context);
1114

@@ -21,12 +24,23 @@ export default class Section extends Component {
2124
}
2225

2326
processAndSetChildren(nextProps, nextContext) {
27+
const {fullContainer} = nextContext;
28+
const {localize: _} = nextProps;
2429
this.sectionVisible = false;
2530

2631
const children = React.Children.toArray(nextProps.children);
2732
this.children = [];
2833
let menuPanel = null;
2934

35+
/*
36+
* show opacity disabled message for scatter traces that have a fill 'tonexty' || 'tonextx'
37+
* based on:
38+
* https://github.com/plotly/plotly.js/blob/master/src/traces/scatter/clean_data.js#L13
39+
*/
40+
const cannotSetTraceOpacity =
41+
fullContainer.type === 'scatter' &&
42+
(fullContainer.fill !== 'none' || fullContainer.fill !== 'toself');
43+
3044
for (let i = 0; i < children.length; i++) {
3145
const child = children[i];
3246
if (!child) {
@@ -47,6 +61,17 @@ export default class Section extends Component {
4761
let newProps = {};
4862
if (child.plotProps) {
4963
plotProps = child.plotProps;
64+
} else if (cannotSetTraceOpacity && child.props.attr === 'opacity') {
65+
this.sectionVisible = true;
66+
const child = (
67+
<Info>
68+
{_(
69+
'Trace opacity is not supported for a scatter trace with fill ' +
70+
'or for a scatter trace that gets filled by another scatter trace.'
71+
)}
72+
</Info>
73+
);
74+
this.children.push(child);
5075
} else if (isAttr) {
5176
if (child.type.supplyPlotProps) {
5277
plotProps = child.type.supplyPlotProps(child.props, nextContext);
@@ -94,3 +119,4 @@ Section.propTypes = {
94119
};
95120

96121
Section.contextTypes = containerConnectedContextTypes;
122+
export default localize(Section);

src/lib/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import bem from './bem';
22
import connectAnnotationToLayout from './connectAnnotationToLayout';
33
import connectAxesToLayout from './connectAxesToLayout';
44
import connectLayoutToPlot, {getLayoutContext} from './connectLayoutToPlot';
5-
import connectToContainer from './connectToContainer';
5+
import connectToContainer, {
6+
containerConnectedContextTypes,
7+
} from './connectToContainer';
68
import connectTraceToPlot from './connectTraceToPlot';
79
import dereference from './dereference';
810
import findFullTraceIndex from './findFullTraceIndex';
@@ -37,6 +39,7 @@ export {
3739
connectLayoutToPlot,
3840
connectToContainer,
3941
connectTraceToPlot,
42+
containerConnectedContextTypes,
4043
customTraceToPlotlyTrace,
4144
dereference,
4245
findFullTraceIndex,

src/styles/components/fields/_field.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.field {
22
align-items: center;
3-
border-top:$border-light;
3+
border-top: $border-light;
44
color: #6d6d6d;
55
display: flex;
66
font-size: $font-size;
@@ -18,7 +18,7 @@
1818

1919
.field__no-title {
2020
width: 100%;
21-
padding: 0 12px;
21+
padding: 3px 12px;
2222
}
2323

2424
.field__no-title--center {

0 commit comments

Comments
 (0)