Skip to content

Instantly share code, notes, and snippets.

@sdboyer
Last active January 27, 2021 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdboyer/5053e745b7c16579f7d59ccc8c340af3 to your computer and use it in GitHub Desktop.
Save sdboyer/5053e745b7c16579f7d59ccc8c340af3 to your computer and use it in GitHub Desktop.
experimenting with CUEified ts decls
package uplot
// Note that we use the CUE #-prefixed "definitions" here, which means that CUE
// won't output that thing when doing its own eval/rendering. This may change,
// but for the moment we're assuming that typescript generation will not happen
// through any action taken by the `cue` binary, but rather by way of a custom
// program, where we can access the CUE structures directly.
//
// To that end, all that's really omitted here is "hints" to a theoretical
// typescript generator that tell it to treat the first group as enums, the
// second as interfaces, etc. We could just make them members of a magical
// struct if we wanted to, though that doesn't feel like the most ergonomic
// option. If we realistically expect Grafana core and contrib authors to write
// and maintain these files as the source for generated typescript and go, such
// ergonomics are important.
// Typescript enums. We've omitted the key portion of an enum's k/v pairs because
// we're not sure how to represent it directly, and because there's a structured
// relation (title case) to the string literal, and thus could theoretically be
// applied during the transform process.
#AxisPlacement: 'auto' | 'top' | 'right' | 'bottom' | 'left' | 'hidden'
#PointVisibility: 'auto' | 'never' | 'always'
#DrawStyle: 'line' | 'bars' | 'points'
#LineInterpolation: 'linear' | 'smooth' | 'stepBefore' | 'stepAfter'
#ScaleDistribution: 'linear' | 'log'
#GraphGradientMode: 'none' | 'opacity' | 'hue' | 'scheme'
// Interfaces.
#LineStyle: {
fill?: 'solid' | 'dash' | 'dot' | 'square'
dash?: [...number]
}
#LineConfig: {
lineColor?: string
lineWidth?: number
lineInterpolation?: #LineInterpolation
lineStyle?: #LineStyle
spanNulls?: bool
}
#FillConfig: {
fillColor?: string
fillOpacity?: number
fillBelowTo?: string
}
#PointsConfig: {
showPoints?: #PointVisibility
pointSize?: number
pointColor?: string
pointSymbol?: string
}
#ScaleDistributionConfig: {
type: #ScaleDistribution
log?: number
}
#AxisConfig: {
axisPlacement?: #AxisPlacement
axisLabel?: string
axisWidth?: number
axisSoftMin?: number
axisSoftMax?: number
scaleDistribution?: #ScaleDistributionConfig
}
#HideSeriesConfig: {
tooltip: bool
legend: bool
graph: bool
}
#GraphFieldConfig: #LineConfig & #FillConfig & #PointsConfig & #AxisConfig & {
drawStyle?: #DrawStyle
gradientMode?: #GraphGradientMode
hideFrom?: #HideSeriesConfig
}
$ cue eval -i uPlot.cue
#AxisPlacement: 'auto' | 'top' | 'right' | 'bottom' | 'left' | 'hidden'
#PointVisibility: 'auto' | 'never' | 'always'
#DrawStyle: 'line' | 'bars' | 'points'
#LineInterpolation: 'linear' | 'smooth' | 'stepBefore' | 'stepAfter'
#ScaleDistribution: 'linear' | 'log'
#GraphGradientMode: 'none' | 'opacity' | 'hue' | 'scheme'
#LineStyle: {}
#LineConfig: {}
#FillConfig: {}
#PointsConfig: {}
#ScaleDistributionConfig: {
type: 'linear' | 'log'
}
#AxisConfig: {}
#HideSeriesConfig: {
tooltip: bool
legend: bool
graph: bool
}
#GraphFieldConfig: {}
$ cue eval -iO uPlot.cue # LOL
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment