dedav4s icon indicating copy to clipboard operation
dedav4s copied to clipboard

Very long string unions break something (circe encoding / compiler?)

Open Quafadas opened this issue 2 years ago • 0 comments


/**
 * Defines how date-time values should be binned.
 */
type TimeUnit = 
    "date" | 
    "day" | 
    "dayhours" | 
    "dayhoursminutes" | 
    "dayhoursminutesseconds" | "dayofyear" | "hours" | "hoursminutes" | "hoursminutesseconds" | "milliseconds" | 
    "minutes" | "minutesseconds" | "month" | "monthdate" | "monthdatehours" | "monthdatehoursminutes" | "monthdatehoursminutesseconds" | "quarter" | "quartermonth" | "seconds" | "secondsmilliseconds" | 
    //"utcdate" | "utcday" | "utcdayhours" | "utcdayhoursminutes" | "utcdayhoursminutesseconds" | "utcdayofyear" | "utchours" | "utchoursminutes" | "utchoursminutesseconds" | "utcmilliseconds" | "utcminutes" | 
    //"utcminutesseconds" | "utcmonth" | "utcmonthdate" | "utcmonthdatehours" | "utcmonthdatehoursminutes" | "utcmonthdatehoursminutesseconds" | "utcquarter" | "utcquartermonth" | "utcseconds" | 
    //"utcsecondsmilliseconds" | "utcweek" | "utcweekday" | "utcweekdayhoursminutes" | "utcweekdayhoursminutesseconds" | "utcweeksdayhours" | "utcyear" | "utcyeardayofyear" | "utcyearmonth" | "utcyearmonthdate" | 
    //"utcyearmonthdatehours" | "utcyearmonthdatehoursminutes" | "utcyearmonthdatehoursminutesseconds" | "utcyearquarter" | "utcyearquartermonth" | "utcyearweek" | "utcyearweekday" | "utcyearweekdayhours" | 
    //"utcyearweekdayhoursminutes" | "utcyearweekdayhoursminutesseconds" | 
    "week" | "weekday" | "weekdayhoursminutes" | "weekdayhoursminutesseconds" | "weeksdayhours" | "year" | "yeardayofyear" | "yearmonth" | 
    "yearmonthdate" | "yearmonthdatehours" | "yearmonthdatehoursminutes" | "yearmonthdatehoursminutesseconds" | "yearquarter" |  "yearquartermonth" | 
    "yearweek" | 
    "yearweekday" | 
    "yearweekdayhours" | 
    "yearweekdayhoursminutes" | 
    "yearweekdayhoursminutesseconds"

// type TimeUnit = "date" | "day" // Short string unions work...

/**
 * Time unit for the field to be tested.
 *
 * Time unit (e.g., `year`, `yearmonth`, `month`, `hours`) for a temporal field. or [a
 * temporal field that gets casted as
 * ordinal](https://vega.github.io/vega-lite/docs/type.html#cast).
 *
 * __Default value:__ `undefined` (None)
 *
 * __See also:__ [`timeUnit`](https://vega.github.io/vega-lite/docs/timeunit.html)
 * documentation.
 *
 * The timeUnit.
 */
type TimeUnitUnion = TimeUnit | TimeUnitParams
given Decoder[TimeUnitUnion] = {
    List[Decoder[TimeUnitUnion]](
        Decoder[TimeUnit].widen,
        Decoder[TimeUnitParams].widen,
    ).reduceLeft(_ or _)
}

given Encoder[TimeUnitUnion] = Encoder.instance {
    case enc0 : TimeUnit => Encoder.encodeString(enc0)
    case enc1 : TimeUnitParams => Encoder.AsObject[TimeUnitParams].apply(enc1)
}

case class TimeUnitParams (
    /**
     * If no `unit` is specified, maxbins is used to infer time units.
     */
    val maxbins : Option[Double] = None,

    /**
     * The number of steps between bins, in terms of the least significant unit provided.
     */
    val step : Option[Double] = None,

    /**
     * Defines how date-time values should be binned.
     */
    val unit : Option[TimeUnit] = None,

    /**
     * True to use UTC timezone. Equivalent to using a `utc` prefixed `TimeUnit`.
     */
    val utc : Option[Boolean] = None
) derives Encoder.AsObject, Decoder


Quafadas avatar May 11 '22 13:05 Quafadas