Skip to main content

perspective_viewer/config/
command_schema.rs

1// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
2// ┃ ██████ ██████ ██████       █      █      █      █      █ █▄  ▀███ █       ┃
3// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█  ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄  ▀█ █ ▀▀▀▀▀ ┃
4// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄   █ ▄▄▄▄▄ ┃
5// ┃ █      ██████ █  ▀█▄       █ ██████      █      ███▌▐███ ███████▄ █       ┃
6// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
7// ┃ Copyright (c) 2017, the Perspective Authors.                              ┃
8// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
9// ┃ This file is part of the Perspective library, distributed under the terms ┃
10// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
11// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
12
13use perspective_client::config::{Scalar, ViewConfigUpdate};
14use serde::{Deserialize, Serialize};
15use ts_rs::TS;
16
17/// The commands a command schema offers for one context.
18#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, TS)]
19pub struct CommandSchema {
20    pub commands: Vec<CommandSpec>,
21}
22
23/// One row a command schema contributes to a menu.
24#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
25#[serde(tag = "kind")]
26pub enum CommandSpec {
27    /// A command the user can pick, reported back by its `key`.
28    Command {
29        key: String,
30        label: String,
31
32        #[serde(default, skip_serializing_if = "Option::is_none")]
33        #[ts(optional)]
34        disabled: Option<bool>,
35
36        #[serde(default, skip_serializing_if = "Option::is_none")]
37        #[ts(optional)]
38        icon: Option<String>,
39
40        /// Tooltip text where the command is a button, the `label` when absent.
41        #[serde(default, skip_serializing_if = "Option::is_none")]
42        #[ts(optional)]
43        title: Option<String>,
44    },
45
46    /// A labelled submenu of further commands.
47    Group {
48        key: String,
49        label: String,
50        commands: Vec<CommandSpec>,
51    },
52}
53
54/// A surface a command schema can be evaluated for.
55#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize, TS)]
56#[serde(rename_all = "kebab-case")]
57pub enum CommandLocation {
58    ContextMenu,
59    DatagridRow,
60    DatagridCell,
61    ChartTooltip,
62}
63
64/// Options for the `setCommandSchema()` method.
65#[derive(Clone, Debug, Default, Deserialize, TS)]
66pub struct CommandSchemaOptions {
67    /// The surfaces the schema is evaluated for, `["context-menu"]` when
68    /// omitted.
69    #[ts(optional)]
70    pub scopes: Option<Vec<CommandLocation>>,
71}
72
73/// A location in a `PerspectiveViewFrame`'s coordinates: a view row and/or a
74/// view column index.
75#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, Serialize, TS)]
76pub struct PerspectiveHitRef {
77    #[serde(default, skip_serializing_if = "Option::is_none")]
78    #[ts(optional)]
79    pub y: Option<u32>,
80
81    #[serde(default, skip_serializing_if = "Option::is_none")]
82    #[ts(optional)]
83    pub x: Option<u32>,
84}
85
86/// Which axes a `PerspectiveHit` addresses.
87#[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize, TS)]
88#[serde(rename_all = "lowercase")]
89pub enum PerspectiveHitKind {
90    Cell,
91    Row,
92    Column,
93}
94
95/// What a plugin rendered at a location, resolved against its view frame.
96#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, TS)]
97pub struct PerspectiveHit {
98    pub kind: PerspectiveHitKind,
99
100    /// The view row index at draw time.
101    #[serde(default, skip_serializing_if = "Option::is_none")]
102    #[ts(optional)]
103    pub y: Option<u32>,
104
105    /// The view column index at draw time.
106    #[serde(default, skip_serializing_if = "Option::is_none")]
107    #[ts(optional)]
108    pub x: Option<u32>,
109
110    /// The row's `__ID__`: its index value(s), or its `group_by` path.
111    #[serde(default, skip_serializing_if = "Option::is_none")]
112    #[ts(optional)]
113    pub id: Option<Vec<Scalar>>,
114
115    /// The `group_by` values of the row, outermost first.
116    pub row_path: Vec<Scalar>,
117
118    /// The `split_by` values of the column, outermost first.
119    pub column_path: Vec<Scalar>,
120
121    /// The column targeted, as in `perspective-click`.
122    pub column_names: Vec<String>,
123
124    /// The cell's value, for a `"cell"` hit.
125    #[serde(default, skip_serializing_if = "Option::is_none")]
126    #[ts(optional)]
127    pub value: Option<Scalar>,
128
129    /// A `restore()` patch whose filters select the target.
130    pub config: ViewConfigUpdate,
131}