Skip to content

Commit

Permalink
Make new expressions format the default.
Browse files Browse the repository at this point in the history
  • Loading branch information
texodus committed Nov 20, 2023
1 parent 0bb2a9a commit 1078c76
Show file tree
Hide file tree
Showing 114 changed files with 1,709 additions and 1,632 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1342,10 +1342,10 @@ jobs:

# Install artifact
- name: Install wheel (system)
run: python -m pip install -U --no-dependencies *manylinux2014*.whl
run: python -m pip install --force-reinstall -U --no-dependencies *manylinux2014*.whl

- name: Install wheel (local)
run: python -m pip install -U --no-dependencies *manylinux2014*.whl --target python/perspective
run: python -m pip install --force-reinstall -U --no-dependencies *manylinux2014*.whl --target python/perspective

- name: Check Installed labextensions
run: jupyter labextension list
Expand Down
2 changes: 1 addition & 1 deletion docs/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async function run_with_theme(page, is_dark = false) {
{
plugin: "Datagrid",
group_by: [],
expressions: [],
expressions: {},
split_by: [],
sort: [],
aggregates: {},
Expand Down
10 changes: 5 additions & 5 deletions docs/docs/expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ quotes_.
<div>
<perspective-viewer
columns='["Sales", "Profit", "Expected Sales"]'
expressions='["// Expected Sales\n(\"Sales\" * 10) + \"Profit\""]'
expressions='{"Expected Sales": "(\"Sales\" * 10) + \"Profit\""}'
></perspective-viewer>
</div>
Expand All @@ -110,7 +110,7 @@ if ("Profit" > 0) {
<div>
<perspective-viewer
columns='["Profit","Profitable"]'
expressions='["//Profitable\nif (\"Profit\" > 0) { &apos;Stonks&apos; } else { &apos;Not Stonks&apos; }"]'
expressions='{"Profitable": "if (\"Profit\" > 0) { &apos;Stonks&apos; } else { &apos;Not Stonks&apos; }"}'
></perspective-viewer>
</div>
Expand Down Expand Up @@ -153,7 +153,7 @@ half
<div>
<perspective-viewer
columns='["Sales", "My Column Name"]'
expressions='["// My Column Name\nvar incrementedBy200 := \"Sales\" + 200;\nvar half := incrementedBy200 / 2;\nhalf"]'
expressions='{"My Column Name": "var incrementedBy200 := \"Sales\" + 200;\nvar half := incrementedBy200 / 2;\nhalf"}'
></perspective-viewer>
</div>
<br/>
Expand All @@ -171,7 +171,7 @@ percentDisplay
<div>
<perspective-viewer
columns='["Complex Expression", "Customer Name", "Sales", "Profit"]'
expressions='["// Complex Expression\nvar upperCustomer := upper(\"Customer Name\");\nvar separator := concat(upperCustomer, &apos; | &apos;);\nvar profitRatio := floor(percent_of(\"Profit\", \"Sales\")); // Remove trailing decimal.\nvar combined := concat(separator, string(profitRatio));\nvar percentDisplay := concat(combined, &apos;%&apos;);\npercentDisplay"]'
expressions='{"Complex Expression": "var upperCustomer := upper(\"Customer Name\");\nvar separator := concat(upperCustomer, &apos; | &apos;);\nvar profitRatio := floor(percent_of(\"Profit\", \"Sales\")); // Remove trailing decimal.\nvar combined := concat(separator, string(profitRatio));\nvar percentDisplay := concat(combined, &apos;%&apos;);\npercentDisplay"}'
></perspective-viewer>
</div>
<br/>
Expand All @@ -197,6 +197,6 @@ finalPrice + additionalModifier
<div>
<perspective-viewer
columns='["Conditional"]'
expressions='["// Conditional\nvar priceAdjustmentDate := date(2016, 6, 18);\nvar finalPrice := \"Sales\" - \"Discount\";\nvar additionalModifier := 0;\n\nif(\"Order Date\" > priceAdjustmentDate) {\n finalPrice -= 5;\n additionalModifier -= 2;\n}\nelse\n finalPrice += 5;\n\nfinalPrice + additionalModifier"]'
expressions='{"Conditional": "var priceAdjustmentDate := date(2016, 6, 18);\nvar finalPrice := \"Sales\" - \"Discount\";\nvar additionalModifier := 0;\n\nif(\"Order Date\" > priceAdjustmentDate) {\n finalPrice -= 5;\n additionalModifier -= 2;\n}\nelse\n finalPrice += 5;\n\nfinalPrice + additionalModifier"}'
></perspective-viewer>
</div>
4 changes: 2 additions & 2 deletions docs/docs/js.md
Original file line number Diff line number Diff line change
Expand Up @@ -696,11 +696,11 @@ await elem.restore({ settings: true });
// Create an expression
await elem.restore({
columns: ['"Sales" + 100'],
expressions: ['"Sales" + 100'],
expressions: { "New Column": '"Sales" + 100' },
});

// ERROR if the column does not exist in the schema or expressions
// await elem.restore({columns: ["\"Sales\" + 100"], expressions: []});
// await elem.restore({columns: ["\"Sales\" + 100"], expressions: {}});

// Add a filter
await elem.restore({ filter: [["Sales", "<", 100]] });
Expand Down
10 changes: 6 additions & 4 deletions docs/docs/view.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ A custom name can be added to an expression by making the first line a comment:

```javascript
const view = await table.view({
expressions: ['"a" + "b"'],
expressions: { '"a" + "b"': '"a" + "b"' },
});
```

Expand All @@ -503,7 +503,9 @@ view = table.view(expressions=['"a" + "b"'])
const elem = document.querySelector("perspective-viewer");
await elem.restore({
columns: ["new expression"],
expressions: ['//new expression\n"Sales" + "Profit" * 50 / sqrt("Sales")'],
expressions: {
"new expression": '"Sales" + "Profit" * 50 / sqrt("Sales")',
},
});
```

Expand All @@ -514,15 +516,15 @@ await elem.restore({
widget = PerspectiveWidget()
widget.restore(
columns=["new_expression"],
expressions=["//new expression\n\"Sales\" + \"Profit\" * 50 / sqrt(\"Sales\")"]
expressions={"new expression": "\"Sales\" + \"Profit\" * 50 / sqrt(\"Sales\")"}
)
```

</TabItem>
</Tabs>

<div>
<perspective-viewer columns='["new expression"]' expressions='["//new expression\n\"Sales\" + \"Profit\" * 50 / sqrt(\"Sales\")"]'>
<perspective-viewer columns='["new expression"]' expressions='{"new expression": "\"Sales\" + \"Profit\" * 50 / sqrt(\"Sales\")"}'>
</perspective-viewer>
</div>

Expand Down
13 changes: 8 additions & 5 deletions docs/src/components/Demo/layouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export const LAYOUTS = {
columns: ["chg (-)", "chg", "chg (+)"],
filter: [],
sort: [["chg", "desc"]],
expressions: [
'//chg (-)\nif("chg"<0){"chg"}else{0}',
'//chg (+)\nif("chg">0){"chg"}else{0}',
],
expressions: {
"chg (-)": 'if("chg"<0){"chg"}else{0}',
"chg (+)": 'if("chg">0){"chg"}else{0}',
},
aggregates: { "chg (+)": "avg", chg: "avg", "chg (-)": "avg" },
},
datagrid: {
Expand Down Expand Up @@ -91,7 +91,10 @@ export const LAYOUTS = {
title: "Spread Heatmap",
columns: ["name"],
plugin: "Heatmap",
expressions: [`bucket("bid",2)`, `bucket("ask",2)`],
expressions: {
'bucket("bid",2)': 'bucket("bid",2)',
'bucket("ask",2)': `bucket("ask",2)`,
},
group_by: [`bucket("bid",2)`],
split_by: [`bucket("ask",2)`],
sort: [],
Expand Down
54 changes: 32 additions & 22 deletions docs/src/components/ExampleGallery/features.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ exports.default = [
},
},
},
expressions: [
`//Profit (-)\nif("Profit"<0){"Profit"}else{0}`,
`//Profit (+)\nif("Profit">0){"Profit"}else{0}`,
],
expressions: {
[`Profit (-)`]: `if("Profit"<0){"Profit"}else{0}`,
[`Profit (+)`]: `if("Profit">0){"Profit"}else{0}`,
},
},
},

Expand Down Expand Up @@ -381,7 +381,7 @@ exports.default = [
group_by: ["State"],
split_by: ["Profit (-/+)"],
columns: ["Profit"],
expressions: [`//Profit (-/+)\nif("Profit"<0){1}else{0}`],
expressions: { "Profit (-/+)": `if("Profit"<0){1}else{0}` },
sort: [["Profit", "desc"]],
},
viewport: { width: 600, height: 450 },
Expand Down Expand Up @@ -502,7 +502,9 @@ exports.default = [
config: {
plugin: "Y Line",
group_by: ["bucket(\"Order Date\", 'M')"],
expressions: ["bucket(\"Order Date\", 'M')"],
expressions: {
"bucket(\"Order Date\", 'M')": "bucket(\"Order Date\", 'M')",
},
columns: ["Sales"],
},
},
Expand All @@ -514,10 +516,10 @@ exports.default = [
plugin: "Y Line",
group_by: ["bucket(\"Order Date\", 'M')"],
split_by: ["bucket(\"Order Date\", 'Y')"],
expressions: [
"bucket(\"Order Date\", 'M')",
"bucket(\"Order Date\", 'Y')",
],
expressions: {
"bucket(\"Order Date\", 'M')": "bucket(\"Order Date\", 'M')",
"bucket(\"Order Date\", 'Y')": "bucket(\"Order Date\", 'Y')",
},
columns: ["Sales"],
},
},
Expand All @@ -529,7 +531,9 @@ exports.default = [
plugin: "Y Line",
group_by: ["bucket(\"Order Date\", 'M')"],
split_by: ["Region"],
expressions: ["bucket(\"Order Date\", 'M')"],
expressions: {
"bucket(\"Order Date\", 'M')": "bucket(\"Order Date\", 'M')",
},
columns: ["Sales"],
},
},
Expand Down Expand Up @@ -605,7 +609,9 @@ exports.default = [
config: {
plugin: "Y Area",
group_by: ["bucket(\"Order Date\", 'M')"],
expressions: ["bucket(\"Order Date\", 'M')"],
expressions: {
"bucket(\"Order Date\", 'M')": "bucket(\"Order Date\", 'M')",
},
columns: ["Sales"],
},
},
Expand All @@ -617,10 +623,10 @@ exports.default = [
plugin: "Y Area",
group_by: ["bucket(\"Order Date\", 'M')"],
split_by: ["bucket(\"Order Date\", 'Y')"],
expressions: [
"bucket(\"Order Date\", 'M')",
"bucket(\"Order Date\", 'Y')",
],
expressions: {
"bucket(\"Order Date\", 'M')": "bucket(\"Order Date\", 'M')",
"bucket(\"Order Date\", 'Y')": "bucket(\"Order Date\", 'Y')",
},
columns: ["Sales"],
},
},
Expand All @@ -632,7 +638,9 @@ exports.default = [
plugin: "Y Area",
group_by: ["bucket(\"Order Date\", 'M')"],
split_by: ["Region"],
expressions: ["bucket(\"Order Date\", 'M')"],
expressions: {
"bucket(\"Order Date\", 'M')": "bucket(\"Order Date\", 'M')",
},
columns: ["Sales"],
},
},
Expand Down Expand Up @@ -1052,7 +1060,9 @@ exports.default = [
config: {
columns: ["Discount"],
plugin: "Heatmap",
expressions: ["bucket(\"Order Date\", 'M')"],
expressions: {
"bucket(\"Order Date\", 'M')": "bucket(\"Order Date\", 'M')",
},
aggregates: {
"Order Date": "dominant",
Sales: "avg",
Expand All @@ -1070,10 +1080,10 @@ exports.default = [
config: {
plugin: "Heatmap",
columns: ["Profit"],
expressions: [
'bucket("Profit", 100)',
"bucket(\"Order Date\", 'M')",
],
expressions: {
'bucket("Profit", 100)': 'bucket("Profit", 100)',
"bucket(\"Order Date\", 'M')": "bucket(\"Order Date\", 'M')",
},
group_by: ["bucket(\"Order Date\", 'M')"],
split_by: ['bucket("Profit", 100)'],
plugin_config: {},
Expand Down
2 changes: 1 addition & 1 deletion docs/src/components/ExampleGallery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function OverlayDemo(props) {
convert({
plugin: "Datagrid",
group_by: [],
expressions: [],
expressions: {},
split_by: [],
sort: [],
aggregates: {},
Expand Down
8 changes: 4 additions & 4 deletions examples/blocks/src/citibike/layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"columns": ["lon", "lat", "num_bikes_available", null, null],
"filter": [["lon", "!=", 0.0]],
"sort": [["num_bikes_available", "asc"]],
"expressions": [],
"expressions": {},
"aggregates": {}
},
"PERSPECTIVE_GENERATED_ID_1": {
Expand Down Expand Up @@ -65,9 +65,9 @@
"columns": ["Available (%)", "name"],
"filter": [],
"sort": [["last_reported", "desc"]],
"expressions": [
"// Available (%)\n\"num_bikes_available\" / \"capacity\""
],
"expressions": {
"Available (%)": "\"num_bikes_available\" / \"capacity\""
},
"aggregates": {}
}
}
Expand Down
22 changes: 9 additions & 13 deletions examples/blocks/src/covid/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@
<link rel="stylesheet" crossorigin="anonymous" href="/node_modules/@finos/perspective-viewer/dist/css/themes.css" />

<script type="module">
import {worker} from "/node_modules/@finos/perspective/dist/cdn/perspective.js";
import { worker } from "/node_modules/@finos/perspective/dist/cdn/perspective.js";

const WORKER = worker();
const REQ = fetch(
"https://api.covidtracking.com/v1/states/daily.csv"
);
const REQ = fetch("https://api.covidtracking.com/v1/states/daily.csv");

const LAYOUT = {
plugin: "Y Area",
Expand All @@ -43,21 +41,19 @@
columns: ["deathIncrease"],
filter: [],
sort: [["deathIncrease", "col desc"]],
expressions: [
`// Parsed "date" bucket by week
var year := integer(floor("date" / 10000));
var month := integer(floor("date" / 100)) - year * 100;
var day := integer("date" % 100);
bucket(date(year, month, day), \'W\')`,
],
expressions: {
[`Parsed "date" bucket by week`]: `var year := integer(floor("date" / 10000));
var month := integer(floor("date" / 100)) - year * 100;
var day := integer("date" % 100);
bucket(date(year, month, day), \'W\')`,
},
aggregates: {},
};

async function load() {
const resp = await REQ;
const csv = await resp.text();
const el =
document.getElementsByTagName("perspective-viewer")[0];
const el = document.getElementsByTagName("perspective-viewer")[0];
const table = WORKER.table(csv);
el.load(table);
el.restore(LAYOUT);
Expand Down
12 changes: 6 additions & 6 deletions examples/blocks/src/evictions/layout.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
"columns": ["lon", "lat", null, null, null],
"filter": [["lon", "is not null", null]],
"sort": [],
"expressions": [
"// lon\nvar x[2];\nindexof(\"shape\", ' .+?( )', x);\nvar y := substring(\"shape\", 7, x[1] - 7);\nfloat(y)",
"// lat\nvar x[2];\nindexof(\"shape\", ' .+?( )', x);\nvar y := substring(\"shape\", x[0], length(\"shape\") - x[1]);\nfloat(y)",
"// bucket lon\nvar x[2];\nindexof(\"shape\", ' .+?( )', x);\nvar y := substring(\"shape\", 7, x[1] - 7);\nbucket(float(y), 0.0025) + 0.00125",
"// bucket lat\nvar x[2];\nindexof(\"shape\", ' .+?( )', x);\nvar y := substring(\"shape\", x[0], length(\"shape\") - x[1]);\nbucket(float(y), 0.0025) + 0.00125"
],
"expressions": {
"lon": "var x[2];\nindexof(\"shape\", ' .+?( )', x);\nvar y := substring(\"shape\", 7, x[1] - 7);\nfloat(y)",
"lat": "var x[2];\nindexof(\"shape\", ' .+?( )', x);\nvar y := substring(\"shape\", x[0], length(\"shape\") - x[1]);\nfloat(y)",
"bucket lon": "var x[2];\nindexof(\"shape\", ' .+?( )', x);\nvar y := substring(\"shape\", 7, x[1] - 7);\nbucket(float(y), 0.0025) + 0.00125",
"bucket lat": "var x[2];\nindexof(\"shape\", ' .+?( )', x);\nvar y := substring(\"shape\", x[0], length(\"shape\") - x[1]);\nbucket(float(y), 0.0025) + 0.00125"
},
"aggregates": {
"lon": "avg",
"lat": "avg",
Expand Down
11 changes: 5 additions & 6 deletions examples/blocks/src/fractal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import perspective from "/node_modules/@finos/perspective/dist/cdn/perspective.j

function generate_mandelbrot(params) {
return `
// color
var height := ${params.height};
var width := ${params.width};
var xmin := ${params.xmin};
Expand Down Expand Up @@ -57,11 +56,11 @@ function generate_layout(params) {
group_by: [`floor("index" / ${params.height})`],
split_by: [`"index" % ${params.height}`],
columns: ["color"],
expressions: [
generate_mandelbrot(params).trim(),
`floor("index" / ${params.height})`,
`"index" % ${params.height}`,
],
expressions: {
color: generate_mandelbrot(params).trim(),
[`floor("index" / ${params.height})`]: `floor("index" / ${params.height})`,
[`"index" % ${params.height}`]: `"index" % ${params.height}`,
},
};
}

Expand Down
Loading

0 comments on commit 1078c76

Please sign in to comment.