Skip to content

Commit

Permalink
feat: integer color by keep discrete groups
Browse files Browse the repository at this point in the history
  • Loading branch information
vieiralucas committed Sep 19, 2024
1 parent a4945b8 commit eabb133
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 24 deletions.
10 changes: 9 additions & 1 deletion apps/api/src/python/visualizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
HistogramBin,
NumpyTimeDeltaTypes,
YAxis,
NumpyIntegerTypes,
} from '@briefer/types'
import { executeCode } from './index.js'
import { logger } from '../logger.js'
Expand Down Expand Up @@ -84,7 +85,14 @@ function getCode(
}
: null,
colorBy: serie.colorBy
? { ...serie.colorBy, type: dfTypeToAltairType(serie.colorBy.type) }
? {
...serie.colorBy,
type:
// integer types are treated as nominal for colorBy
NumpyIntegerTypes.safeParse(serie.colorBy.type).success
? 'N'
: dfTypeToAltairType(serie.colorBy.type),
}
: null,
})),
}))
Expand Down
49 changes: 26 additions & 23 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ export const dateSchema = z
message: 'Invalid date format',
})

// all numpy number types
export const NumpyNumberTypes = z.enum([
export const NumpyIntegerTypes = z.enum([
'byte',
'ubyte',

Expand Down Expand Up @@ -78,27 +77,6 @@ export const NumpyNumberTypes = z.enum([

'longlong',

'f2',
'f4',
'f8',
'f16',

'float16',
'float32',
'float64',
'float128',

'Float',
'Float16',
'Float32',
'Float64',

'float',
'longfloat',

'double',
'longdouble',

'u1',
'u2',
'u4',
Expand Down Expand Up @@ -126,6 +104,31 @@ export const NumpyNumberTypes = z.enum([
'ULongLong',
])

// all numpy number types
export const NumpyNumberTypes = z.enum([
...NumpyIntegerTypes.options,
'f2',
'f4',
'f8',
'f16',

'float16',
'float32',
'float64',
'float128',

'Float',
'Float16',
'Float32',
'Float64',

'float',
'longfloat',

'double',
'longdouble',
])

export type NumpyNumberTypes = z.infer<typeof NumpyNumberTypes>

// all numpy date types
Expand Down

0 comments on commit eabb133

Please sign in to comment.