-
Notifications
You must be signed in to change notification settings - Fork 271
Conversation
Deploy preview for superset-ui ready! Built with commit 34960fd |
6ea548e
to
9ef9389
Compare
Codecov Report
@@ Coverage Diff @@
## master #230 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 138 142 +4
Lines 1520 1559 +39
Branches 400 406 +6
=====================================
+ Hits 1520 1559 +39
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall, had a couples questions. very cool types!
the vx
re-write has made me more appreciative of TS and nuances :)
channels[name] = definitions.map( | ||
(definition, i) => | ||
new ChannelEncoder({ | ||
channelType: 'Text', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this come from channelTypes[name]
or channelTypes[name][0]
? or Text
is the only type that has an array? (seems possibly fragile in the future)
channelNames | ||
.map(name => this.channels[name]) | ||
.forEach(c => { | ||
if (isNotArray(c) && c.hasLegend() && isFieldDef(c.definition)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we not care about channels encoded as arrays in legends?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, the channels that are array are fields for tooltip
. I tried to think if we want to support other channels that require legends such as color
as array of multiple fields but that makes thing very complicated. Better create a derived field field1,field2
in the dataset and use that derived field instead. (vega
also has support for formula
instead of field
for this kind of purpose, which I haven't explored how to port)
@@ -126,4 +126,8 @@ export default class ChannelEncoder<Def extends ChannelDef<Output>, Output exten | |||
isY() { | |||
return isY(this.channelType); | |||
} | |||
|
|||
hasLegend() { | |||
return this.definition.legend !== false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since it looks like legend
is optional, should this check if it's set to true
?
EDIT: I see that the complete encoding specifies false
or { ... }
.
import { EncodingConfig, DeriveChannelTypes, DeriveEncoding } from '../types/Encoding'; | ||
import mergeEncoding from '../utils/mergeEncoding'; | ||
|
||
type CreateEncoderFactoryParams<Config extends EncodingConfig> = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this type
is beautiful 😻
}; | ||
|
||
export type DeriveChannelTypes<Config extends EncodingConfig> = { | ||
readonly [k in keyof Config]: Config[k]['0']; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#TIL
, did not know that you could index types like this.
interesting it has to be a string and not a number.
|
||
export type DeriveChannelEncoders<Config extends EncodingConfig> = { | ||
readonly [k in keyof Config]: Config[k]['2'] extends 'multiple' | ||
? ChannelEncoder<ChannelTypeToDefMap<Config[k]['1']>[Config[k]['0']]>[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so advanced! 🤯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is like 3rd-4th time I rewrote the whole thing lol.
🏆 Enhancements
Add
Encoder
to@superset-ui/encodable
. AnEncoder
is a utility class created once per chart type.ChannelEncoder
vega-lite
syntax), then resolves ambiguity and produce complete definition and actionable utility functions.Example Usage
The component developer creates an encoder factory once.
The
factory
encapsulates the awkwardchannelTypes
anddefaultEncoding
Encoder
instance of this chartEncoder
fromencoding
becausefactory.create(encoding)
only needs one argument:encoding
.This is how user-specified
encoding
may look like.Then create an
Encoder
for the incomingencoding
and use it to facilitate rendering.