-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate from Vega-lite Spec #21
Comments
Vega-lite-api is using |
There is a rename step because the names from the generator were not what we wanted: https://github.com/vega/vega-lite/blob/main/scripts/rename-schema.sh |
This week's update: Auto-generate files from typescript typesThe generation logic is from vega-lite-api constants. When I meet a 'TopLevelUnitSpec', I generate mark: 'TopLevelUnitSpec',
layer: 'TopLevelLayerSpec',
concat: 'TopLevelConcatSpec',
hconcat: 'TopLevelHConcatSpec',
vconcat: 'TopLevelVConcatSpec',
_repeat: 'TopLevelRepeatSpec',
_facet: 'TopLevelFacetSpec',
spec: 'TopLevelSpec',
data: 'TopLevelUnitSpec', In this way, as long as we have a well-defined constant, all codes can be generated. But will that influence the maintainability of the code?
Create Internal Representation (In Process)Now when generating, the types still have inheritances, for example, center(value: boolean | RowCol<boolean>) {
if (arguments.length) {
const obj = copy(this);
set(obj, "center", value);
return obj;
} else {
return get(this, "center");
}
} To solve this, I plan to have a class that stores the inheritance through children's classes so that we can get the // internal representation of a type
class VegaLiteType {
name: string;
type: ts.Type;
kind: TypeKind;
children: VegaLiteType[];
oneLevelType: string;
properties?: ts.Type[];
description?: string; //TODO: get descirption and generate documentation
constructor(name: string, type: ts.Type, kind: TypeKind, children: VegaLiteType[]) {
this.name = name;
this.type = type;
this.kind = kind;
this.children = children;
// this.oneLevelType = this.updateOneLevelType();
this.properties = (type as any).properties;
}
generateOneLevelType(): string {
switch (this.kind) {
case TypeKind.Union:
return this.children.map(child => child.generateOneLevelType()).join(" | ");
case TypeKind.Intersection:
return this.children.map(child => child.generateOneLevelType()).join(" & ");
case TypeKind.Literal:
return this.name;
case TypeKind.TypeParameter:
return this.name;
case TypeKind.Other:
return this.name;
}
}
updateOneLevelType(): void {
this.oneLevelType = this.generateOneLevelType();
}
} |
I used type checker and AST node to parse from vega-lite/src/spec/index.ts, and begin from this:
Now it can parse the type inheritance like this (full text)
and get properties in these types (full text)
And types in each property such as mark (full text)
The code is in
apigen/explorationOnSpec/from-spec-index.ts
Line 77 in 65ed0cc
The text was updated successfully, but these errors were encountered: