add smallcolorscale fractions for chromatic scaled colors

This commit is contained in:
Robert Elliott 2018-09-10 15:59:14 +02:00
parent 3fdd9164c8
commit 4242a64f30
2 changed files with 16 additions and 5 deletions

View File

@ -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>
);

View File

@ -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 );
};