@@ -2,7 +2,7 @@ import ColorscalePicker from '../widgets/ColorscalePicker';
22import Field from './Field' ;
33import PropTypes from 'prop-types' ;
44import React , { Component } from 'react' ;
5- import { connectToContainer } from 'lib' ;
5+ import { connectToContainer , adjustColorscale } from 'lib' ;
66
77class Colorscale extends Component {
88 constructor ( props ) {
@@ -12,6 +12,18 @@ class Colorscale extends Component {
1212
1313 onUpdate ( colorscale , colorscaleType ) {
1414 if ( Array . isArray ( colorscale ) ) {
15+ if ( this . context . container . type === 'pie' ) {
16+ const numPieSlices = this . context . graphDiv . calcdata [ 0 ] . length + 1 ;
17+ const adjustedColorscale = adjustColorscale (
18+ colorscale ,
19+ numPieSlices ,
20+ colorscaleType ,
21+ { repeat : true }
22+ ) ;
23+ this . props . updatePlot ( adjustedColorscale ) ;
24+ return ;
25+ }
26+
1527 this . props . updatePlot (
1628 colorscale . map ( ( c , i ) => {
1729 let step = i / ( colorscale . length - 1 ) ;
@@ -50,6 +62,11 @@ Colorscale.propTypes = {
5062 ...Field . propTypes ,
5163} ;
5264
65+ Colorscale . contextTypes = {
66+ container : PropTypes . object ,
67+ graphDiv : PropTypes . object ,
68+ } ;
69+
5370export default connectToContainer ( Colorscale , {
5471 modifyPlotProps : ( props , context , plotProps ) => {
5572 if (
@@ -65,5 +82,30 @@ export default connectToContainer(Colorscale, {
6582 . filter ( t => context . traceIndexes . includes ( t . index ) )
6683 . map ( t => [ 0 , t . marker . color ] ) ;
6784 }
85+
86+ if (
87+ context &&
88+ context . container &&
89+ context . graphDiv &&
90+ ( ! plotProps . fullValue ||
91+ ( Array . isArray ( plotProps . fullValue ) && ! plotProps . fullValue . length ) ) &&
92+ context . container . type === 'pie' &&
93+ context . graphDiv . calcdata
94+ ) {
95+ plotProps . fullValue = context . graphDiv . calcdata [ 0 ] . map ( d => [ 0 , d . color ] ) ;
96+ }
97+
98+ if (
99+ props . attr === 'marker.colors' &&
100+ plotProps . fullValue &&
101+ Array . isArray ( plotProps . fullValue ) &&
102+ ! plotProps . fullValue . every ( el => Array . isArray ( el ) )
103+ ) {
104+ plotProps . fullValue = plotProps . fullValue . map ( c => [ 0 , c ] ) ;
105+ }
106+
107+ if ( context . container . type === 'pie' && context . traceIndexes . length > 1 ) {
108+ plotProps . isVisible = false ;
109+ }
68110 } ,
69111} ) ;
0 commit comments