vega:过滤每组的第 n 个

问题描述

如果我按日期分组,我将如何过滤每个组的 nth 个条目?


environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  firebase_core:
  cloud_firestore:
  firebase_database: 
  firebase:
  slide_button: ^0.2.8
  Flutter_native_splash: 
  splashscreen:
  flappy_search_bar: 
  Flutter:
    sdk: Flutter
  google_maps_Flutter: 
  location:  
  Flutter_polyline_points: 
  permission: ^0.1.7
  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.0
  permission_handler: ^6.1.1
  imagebutton: ^0.0.6

编辑

让我们保持这个数据不可知,因为我的数据有很多列,我想要完整的行。

解决方法

转换概述:

  1. 将时间转换为日期以进行分组。
  2. 按日期分组并对组内的每一行进行编号。
  3. 过滤第n行。
{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json","data": {"url": "https://cdn.jsdelivr.net/npm/vega-datasets@v1.29.0/data/seattle-temps.csv"},"transform": [
    {"timeUnit": "yearmonthdate","field": "date","as": "date"},{
      "window": [{"op": "row_number","as": "row"}],"groupby": ["date"]
    },{"calculate": "datum.index","as":"newnew"},{"filter": "datum['row'] == 1"}
  ],"mark": "point","encoding": {
    "x": {"field": "date","type": "temporal"},"y": {"field": "temp","type": "quantitative"}
  }
}

缺点是添加窗口变换后vega编辑器变得很慢。