import React from 'react'; import { IField } from '../../interfaces'; import { ColorDisplay } from './encodings'; const MAX_COLORS = 15; export default function ColorPanel(props: { display: ColorDisplay; field: IField; aggerated?: boolean }) { const { display, field, aggerated } = props; const fieldName = aggerated && field.analyticType === 'measure' && field.aggName ? `${field.aggName}(${field.name})` : field.name; return (
{display.type === 'nominal' && (
{fieldName}
{display.colors.slice(0, MAX_COLORS).map(({ name, color }) => { return (
{name}
); })} {display.colors.length > MAX_COLORS && (
...{display.colors.length - MAX_COLORS} entries
)}
)} {display.type === 'quantitative' && (
{fieldName}
{Math.floor(display.domain[1])}
{Math.floor(display.domain[1] * 0.75 + display.domain[0] * 0.25)}
{Math.floor(display.domain[1] * 0.5 + display.domain[0] * 0.5)}
{Math.floor(display.domain[1] * 0.25 + display.domain[0] * 0.75)}
{Math.floor(display.domain[0])}
)}
); }