Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Expose expression functions #935

Merged
merged 5 commits into from
Jun 10, 2022
Merged

Conversation

ZacharyBys
Copy link
Contributor

@ZacharyBys ZacharyBys commented Jun 7, 2022

Exposes vega.expressionFunction to allow consumers to create custom functions/formatters.

Follow up to this ticket: #934

Version

Published prerelease version: v6.21.0-next.0

Changelog

🎉 This release contains work from a new contributor! 🎉

Thank you, Zachary Bys (@ZacharyBys), for all your work!

🚀 Enhancement

🐛 Bug Fix

⚠️ Pushed to next

🔩 Dependency Updates

Authors: 4

Copy link
Member

@kanitw kanitw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Let's make visitor optional

  • Add doc to README.md? (Add expressionFunction: ... to option object list and to the table below)

mark: 'point',
transform: [
{calculate: "simpleFunction()", as: "result1"},
{calculate: "visitorFunction()", as: "result2"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

visitorFunction -> functionWithVisitor?

src/types.ts Outdated
@@ -4,6 +4,8 @@ import {Config as VlConfig} from 'vega-lite';
export type Mode = 'vega' | 'vega-lite';
export type Config = VlConfig | VgConfig;

export type ExpressionFunction = Record<string, Function | {fn: Function, visitor: Function}>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah my bad, I think visitor should be optional

src/embed.ts Outdated
if (opts.expressionFunctions) {
for (const name in opts.expressionFunctions) {
const expressionFunction = opts.expressionFunctions[name];
if ('fn' in expressionFunction && 'visitor' in expressionFunction) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work correctly if visitor is optional.

use isObject(expressionFunction) instead ?

(you can import isObject from vega, for consistency with other isString, etc.)

@ZacharyBys ZacharyBys requested a review from kanitw June 9, 2022 18:32
@kanitw kanitw merged commit 0e9b871 into vega:next Jun 10, 2022
@github-actions
Copy link

🚀 PR was released in v6.21.0 🚀

@github-actions github-actions bot added released this feature has been released! and removed prerelease labels Jun 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released this feature has been released!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants