-
Notifications
You must be signed in to change notification settings - Fork 77
feat: add encodeable utilities for chart #15
Conversation
adf8069
to
be15fbd
Compare
packages/superset-ui-preset-chart-xy/src/encodeable/utils/isEnabled.ts
Outdated
Show resolved
Hide resolved
|
||
export interface Dataset { | ||
keys: string[]; | ||
values: PlainObject[]; |
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.
not sure if we can make sure that the key in the PlainObject
will be always in the set of key
? seems impossible.\
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.
I googled a bit and couldn't figure this out, worth asking in #typescript tho?
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.
Can use typeguard to help. Not sure if possible to define solely as type without knowing the fields before hand.
export type PlainObject<Key extends string = string, Value extends any = any> = {
[key in Key]: Value
};
export type Dataset<T extends string> = {
keys: T[];
values: Partial<PlainObject<T>>[];
}
function isDataset<T extends string>(input: Dataset<T>): Dataset<T> {
return input;
}
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.
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.
mmm. this is more complicated. the guard only work for inline input, but if you pass a variable with type already it make keys
string[]
instead of 'a'|'b'|'c'[]
and the check does not work.
packages/superset-ui-preset-chart-xy/src/encodeable/BaseEncoder.ts
Outdated
Show resolved
Hide resolved
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.
Looking great overall! some crazy TS in there 😎
Thanks for the hard work on this!
packages/superset-ui-preset-chart-xy/src/encodeable/types/fielddef.ts
Outdated
Show resolved
Hide resolved
x: number | null; | ||
y: number | null; | ||
color: string; | ||
fill: boolean; |
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.
does a boolean
mean it impossible to have different color
/ fill
?
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.
Umm, at this point yes. the fill is gradient from [stroke] color
to white.
I can make this boolean | string
, which may lead to some ugly line charts with stroke and fill not getting along.
packages/superset-ui-preset-chart-xy/src/encodeable/BaseEncoder.ts
Outdated
Show resolved
Hide resolved
packages/superset-ui-preset-chart-xy/src/encodeable/BaseEncoder.ts
Outdated
Show resolved
Hide resolved
packages/superset-ui-preset-chart-xy/src/encodeable/BaseEncoder.ts
Outdated
Show resolved
Hide resolved
packages/superset-ui-preset-chart-xy/src/encodeable/ChannelEncoder.ts
Outdated
Show resolved
Hide resolved
packages/superset-ui-preset-chart-xy/src/encodeable/parsers/parseAxis.ts
Outdated
Show resolved
Hide resolved
packages/superset-ui-preset-chart-xy/src/encodeable/types/spec.ts
Outdated
Show resolved
Hide resolved
packages/superset-ui-preset-chart-xy/src/encodeable/utils/isEnabled.ts
Outdated
Show resolved
Hide resolved
|
||
export interface Dataset { | ||
keys: string[]; | ||
values: PlainObject[]; |
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.
I googled a bit and couldn't figure this out, worth asking in #typescript tho?
be15fbd
to
9c3c907
Compare
Addressed most of the comments. |
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.
Overall this looks super clean and solid improvements vs the first round! 😍 🎉 I think none of my comments are blocking and that we could extend the fill
option to accept a string
in the future if need be.
thanks for all the hard work on this, pretty crazy TS here! ❤️ will approve from my end but still let @conglei comment/review if he wants!
"lodash": "^4.17.11", | ||
"prop-types": "^15.6.2", | ||
"reselect" : "^4.0.0", | ||
"vega": "^5.2.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.
I didn't see any imports of vega
, is this because it's a vega-lite
dep? bundle size should be okay with the deep imports I'd think.
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.
Tried removing it and realize vega-lite
needs it.
packages/superset-ui-preset-chart-xy/src/encodeable/types/FieldDef.ts
Outdated
Show resolved
Hide resolved
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.
Thanks for adding this! 🥂 It looks good to me!
6f03d9f
to
6825b18
Compare
Add tn / translateWithNumber
* feat: add encodeable utilities * feat: add types back * refactor: simplify function calls * refactor: rename generic type * refactor: more edits * refactor: remove unused function * refactor: rename file * fix: address comments * fix: add vega back
🏆 Enhancements
Define encoding config for a visualization
x
,y
,color
,stroke
, fill. These channels configurations should be consistent/sharable across all visualizations. For example,x
andy
usually have scales and axes. Scales havedomain
,range
. Axes havelabel
,format
. Color can support categorical, sequential or fixed color. All channels can support fixed value, field name in the data, or sometimes aggregates (haven't implemented the aggregate yet).vega-lite
encoding grammar. (See line chart example, vega-lite encoding documentation)vega-lite
encoding grammar for now as we don’t have enough time (and may not intend) to provide 100% feature ofvega-lite
.Implement TypeScript types for the encoding config.
vega-lite
package (XXXFieldDef
) directly but ended up getting too overwhelmed.vega-lite
then write higher-level types that has same name but only with the subset of the fields, so we can keep that of what we support and slowly adopt more in the future instead of taking it all now which our encoder does not know how to handle and also make it harder to implement the encoder. (preview)Write an encoder that parses the encoding config mention above and become a helper during visualization rendering.
Encoder
class and each visualization such as line chart will implement its ownEncoder
that extends from the base class. See: base Encoder class, Line Chart's EncoderLong shot
@superset-ui/encodeable
.