Rename layer "aesthetics" to "mappings"

pull/12129/head
Christopher Henn 2019-02-22 08:51:38 -08:00 committed by Alirie Gray
parent 385c0ae4d1
commit dff331667e
6 changed files with 30 additions and 29 deletions

View File

@ -47,7 +47,7 @@ export const Histogram: SFC<Props> = ({
const layer = useLayer( const layer = useLayer(
env, env,
() => { () => {
const [table, aesthetics] = bin( const [table, mappings] = bin(
baseTable, baseTable,
x, x,
xDomain, xDomain,
@ -56,7 +56,7 @@ export const Histogram: SFC<Props> = ({
position position
) )
return {table, aesthetics, colors, scales: {}} return {table, mappings, colors, scales: {}}
}, },
[baseTable, xDomain, x, fill, position, binCount, colors] [baseTable, xDomain, x, fill, position, binCount, colors]
) )
@ -75,12 +75,12 @@ export const Histogram: SFC<Props> = ({
}, },
} = env } = env
const {aesthetics, table} = layer const {mappings, table} = layer
const hoveredRowIndices = findHoveredRowIndices( const hoveredRowIndices = findHoveredRowIndices(
table.columns[aesthetics.xMin], table.columns[mappings.xMin],
table.columns[aesthetics.xMax], table.columns[mappings.xMax],
table.columns[aesthetics.yMax], table.columns[mappings.yMax],
hoverX, hoverX,
hoverY, hoverY,
xScale, xScale,

View File

@ -24,11 +24,11 @@ const drawBars = (
): void => { ): void => {
clearCanvas(canvas, width, height) clearCanvas(canvas, width, height)
const {table, aesthetics} = layer const {table, mappings} = layer
const xMinCol = table.columns[aesthetics.xMin] const xMinCol = table.columns[mappings.xMin]
const xMaxCol = table.columns[aesthetics.xMax] const xMaxCol = table.columns[mappings.xMax]
const yMinCol = table.columns[aesthetics.yMin] const yMinCol = table.columns[mappings.yMin]
const yMaxCol = table.columns[aesthetics.yMax] const yMaxCol = table.columns[mappings.yMax]
const context = canvas.getContext('2d') const context = canvas.getContext('2d')

View File

@ -39,7 +39,7 @@ export interface AestheticScaleMappings {
export interface Layer { export interface Layer {
table?: Table table?: Table
aesthetics: AestheticDataMappings mappings: AestheticDataMappings
scales: AestheticScaleMappings scales: AestheticScaleMappings
colors?: string[] colors?: string[]
xDomain?: [number, number] xDomain?: [number, number]

View File

@ -13,11 +13,11 @@ import {getGroupKey} from 'src/minard/utils/getGroupKey'
// key”) that the scale uses as a domain // key”) that the scale uses as a domain
// 3. Lookup the scale and get the color via this representation // 3. Lookup the scale and get the color via this representation
export const getBarFill = ( export const getBarFill = (
{scales, aesthetics, table}: Layer, {scales, mappings, table}: Layer,
i: number i: number
): string => { ): string => {
const fillScale = scales.fill const fillScale = scales.fill
const values = aesthetics.fill.map(colKey => table.columns[colKey][i]) const values = mappings.fill.map(colKey => table.columns[colKey][i])
const groupKey = getGroupKey(values) const groupKey = getGroupKey(values)
const fill = fillScale(groupKey) const fill = fillScale(groupKey)

View File

@ -5,14 +5,14 @@ export const getHistogramTooltipProps = (
layer: Layer, layer: Layer,
rowIndices: number[] rowIndices: number[]
): HistogramTooltipProps => { ): HistogramTooltipProps => {
const {table, aesthetics} = layer const {table, mappings} = layer
const xMinCol = table.columns[aesthetics.xMin] const xMinCol = table.columns[mappings.xMin]
const xMaxCol = table.columns[aesthetics.xMax] const xMaxCol = table.columns[mappings.xMax]
const yMinCol = table.columns[aesthetics.yMin] const yMinCol = table.columns[mappings.yMin]
const yMaxCol = table.columns[aesthetics.yMax] const yMaxCol = table.columns[mappings.yMax]
const counts = rowIndices.map(i => { const counts = rowIndices.map(i => {
const grouping = aesthetics.fill.reduce( const grouping = mappings.fill.reduce(
(acc, colName) => ({ (acc, colName) => ({
...acc, ...acc,
[colName]: table.columns[colName][i], [colName]: table.columns[colName][i],

View File

@ -33,7 +33,7 @@ export const INITIAL_PLOT_ENV: PlotEnv = {
yDomain: null, yDomain: null,
baseLayer: { baseLayer: {
table: {columns: {}, columnTypes: {}}, table: {columns: {}, columnTypes: {}},
aesthetics: {}, mappings: {},
scales: {}, scales: {},
}, },
layers: {}, layers: {},
@ -117,20 +117,21 @@ export const plotEnvReducer = (state: PlotEnv, action: PlotAction): PlotEnv =>
/* /*
Find all columns in the current in all layers that are mapped to the supplied Find all columns in the current in all layers that are mapped to the supplied
aesthetics aesthetic mappings
*/ */
const getColumnsForAesthetics = ( const getColumnsForAesthetics = (
state: PlotEnv, state: PlotEnv,
aesthetics: string[] mappings: string[]
): any[][] => { ): any[][] => {
const {baseLayer, layers} = state const {baseLayer, layers} = state
const cols = [] const cols = []
for (const layer of Object.values(layers)) { for (const layer of Object.values(layers)) {
for (const aes of aesthetics) { for (const mapping of mappings) {
if (layer.aesthetics[aes]) { const colName = layer.mappings[mapping]
const colName = layer.aesthetics[aes]
if (colName) {
const col = layer.table const col = layer.table
? layer.table.columns[colName] ? layer.table.columns[colName]
: baseLayer.table.columns[colName] : baseLayer.table.columns[colName]
@ -272,8 +273,8 @@ const getColorScale = (
of data (for now). So the domain of the scale is a set of "group keys" which of data (for now). So the domain of the scale is a set of "group keys" which
represent all possible groupings of data in the layer. represent all possible groupings of data in the layer.
*/ */
const getFillDomain = ({table, aesthetics}: Layer): string[] => { const getFillDomain = ({table, mappings}: Layer): string[] => {
const fillColKeys = aesthetics.fill const fillColKeys = mappings.fill
if (!fillColKeys.length) { if (!fillColKeys.length) {
return [] return []
@ -299,7 +300,7 @@ const setFillScales = (draftState: PlotEnv) => {
layers layers
.filter( .filter(
// Pick out the layers that actually need a fill scale // Pick out the layers that actually need a fill scale
layer => layer.aesthetics.fill && layer.colors && layer.colors.length layer => layer.mappings.fill && layer.colors && layer.colors.length
) )
.forEach(layer => { .forEach(layer => {
layer.scales.fill = getColorScale(getFillDomain(layer), layer.colors) layer.scales.fill = getColorScale(getFillDomain(layer), layer.colors)