add smallcolorscale fractions for chromatic scaled colors
This commit is contained in:
parent
3fdd9164c8
commit
4242a64f30
|
@ -93,7 +93,7 @@ class WidgetCharts extends Component {
|
|||
</ul>
|
||||
</Card>
|
||||
<Card title={ __( 'Store Charts', 'wc-admin' ) }>
|
||||
<Chart data={ this.state.someOrders } title="Example Chart" />
|
||||
<Chart data={ this.state.someOrders } title="Example Chart" layout="comparison" />
|
||||
</Card>
|
||||
</Fragment>
|
||||
);
|
||||
|
|
|
@ -99,10 +99,21 @@ export const getUniqueDates = ( lineData, parseDate ) => {
|
|||
};
|
||||
|
||||
export const getColor = ( key, params ) => {
|
||||
const keyValue =
|
||||
params.orderedKeys.length > 1
|
||||
? findIndex( params.orderedKeys, d => d.key === key ) / ( params.orderedKeys.length - 1 )
|
||||
: 0;
|
||||
const smallColorScales = [
|
||||
[],
|
||||
[ 0.5 ],
|
||||
[ 0.333, 0.667 ],
|
||||
[ 0.2, 0.5, 0.8 ],
|
||||
[ 0.12, 0.375, 0.625, 0.88 ],
|
||||
];
|
||||
let keyValue = 0;
|
||||
const len = params.orderedKeys.length;
|
||||
const idx = findIndex( params.orderedKeys, d => d.key === key );
|
||||
if ( len < 5 ) {
|
||||
keyValue = smallColorScales[ len ][ idx ];
|
||||
} else {
|
||||
keyValue = idx / ( params.orderedKeys.length - 1 );
|
||||
}
|
||||
return params.colorScheme( keyValue );
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue