Skip to content

Commit f177f89

Browse files
committed
Generalize customTraceToPlotlyTrace function and rename
1 parent 48a1360 commit f177f89

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

src/components/fields/TraceSelector.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33
import React, {Component} from 'react';
44
import {
55
connectToContainer,
6-
customTraceToPlotlyTrace,
6+
traceTypeToPlotlyFigure,
77
localize,
88
plotlyTraceToCustomTrace,
99
} from 'lib';
@@ -114,9 +114,10 @@ class TraceSelector extends Component {
114114
}
115115

116116
updatePlot(value) {
117-
const update = customTraceToPlotlyTrace(value);
118-
if (this.props.updateContainer) {
119-
this.props.updateContainer(update);
117+
const {updateContainer} = this.props;
118+
119+
if (updateContainer) {
120+
updateContainer(traceTypeToPlotlyFigure(value));
120121
}
121122
}
122123

src/lib/customTraceType.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,28 @@ export function plotlyTraceToCustomTrace(trace) {
1515
return trace.type;
1616
}
1717

18-
export function customTraceToPlotlyTrace(customTraceType) {
19-
if (customTraceType === 'line') {
18+
export function traceTypeToPlotlyFigure(traceType) {
19+
if (traceType === 'line') {
2020
return {type: 'scatter', mode: 'lines', fill: 'none'};
2121
}
2222

23-
if (customTraceType === 'scatter') {
23+
if (traceType === 'scatter') {
2424
return {type: 'scatter', mode: 'markers', fill: 'none'};
2525
}
2626

27-
if (customTraceType === 'area') {
27+
if (traceType === 'area') {
2828
return {type: 'scatter', fill: 'tozeroy'};
2929
}
3030

31-
return {type: customTraceType};
31+
if (traceType === 'ohlc') {
32+
return {
33+
type: 'ohlc',
34+
autobinx: true,
35+
autobiny: true,
36+
decreasing: {line: {color: '#7F7F7F'}},
37+
increasing: {line: {color: '#17BECF'}},
38+
};
39+
}
40+
41+
return {type: traceType};
3242
}

src/lib/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import tinyColor from 'tinycolor2';
1313
import unpackPlotProps from './unpackPlotProps';
1414
import walkObject, {isPlainObject} from './walkObject';
1515
import {
16-
customTraceToPlotlyTrace,
16+
traceTypeToPlotlyFigure,
1717
plotlyTraceToCustomTrace,
1818
} from './customTraceType';
1919
import * as PlotlyIcons from 'plotly-icons';
@@ -53,7 +53,7 @@ export {
5353
connectToContainer,
5454
connectTraceToPlot,
5555
containerConnectedContextTypes,
56-
customTraceToPlotlyTrace,
56+
traceTypeToPlotlyFigure,
5757
dereference,
5858
findFullTraceIndex,
5959
getDisplayName,

0 commit comments

Comments
 (0)