perspective_client/config/
plugin.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 std::collections::HashMap;
14use std::fmt::Debug;
15
16use serde::{Deserialize, Serialize};
17
18#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
19pub struct Symbol {
20    /// the name of the symbol
21    pub name: String,
22    /// unescaped HTML string
23    pub html: String,
24}
25impl std::fmt::Display for Symbol {
26    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
27        f.write_str(&self.name)
28    }
29}
30
31#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
32pub struct SymbolAttributes {
33    /// a vec of SVGs to render
34    pub symbols: Vec<Symbol>,
35}
36
37/// The default style configurations per type, as retrived by
38/// plugin.plugin_attributes
39#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
40pub struct DefaultStyleAttributes {
41    pub string: serde_json::Value,
42    pub datetime: serde_json::Value,
43    pub date: serde_json::Value,
44    pub integer: serde_json::Value,
45    pub float: serde_json::Value,
46    pub bool: serde_json::Value,
47}
48
49/// The data needed to populate a column's settings.
50///
51/// These are typically default values, a listing of possible values, or other
52/// basic configuration settings for the plugin. This is the result of calling
53/// plugin.plugin_attributes
54#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
55pub struct PluginAttributes {
56    pub symbol: Option<SymbolAttributes>,
57    pub style: Option<DefaultStyleAttributes>,
58    // color: ColorAttributes,
59    // axis: AxisAttributes,
60    //...
61}
62
63/// The configuration which is created as the result of calling plugin.save
64#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
65pub struct PluginConfig {
66    /// Refers to the currently active columns. Maps name to configuration.
67    #[serde(default)]
68    pub columns: HashMap<String, serde_json::Value>,
69}