Skip to content
This repository has been archived by the owner on Apr 10, 2018. It is now read-only.

Allow arbitrary expressions in functions, filters, and cluster aggregators #47

Closed
nickidlugash opened this issue Jun 16, 2014 · 13 comments

Comments

@nickidlugash
Copy link
Contributor

Will it be possible to support +, -, *, and /?

@tmcw
Copy link
Contributor

tmcw commented Jun 16, 2014

Could you go into a little more detail about how these would be represented? Like "{{a}} + {{b}}"?

Fwiw, expressions like this are probably super useful, but I'd be interested in whether the approach we've taken for filters could be applied rather than doing infix like Carto or string like Mapnik - like we would have something like

{
  "+": ["{{a}}", 2]
}

Instead of

"{{a}} + 2"

@jfirebaugh
Copy link
Contributor

Can we enumerate some uses cases for this feature? I'm particularly interested in how much it overlaps with #226 (Stop functions based on arbitrary properties).

@nickidlugash
Copy link
Contributor Author

hrm. In theory, there are some use cases for this not covered by stop functions based on arbitrary properties. I might not be fully understanding the stop functions, but they seem to mainly be for assigning different values of the same style property for different values of the same field in a data layer. With math operators, you could manipulate values across different properties and different GL layers.

A use case that I think would overlap with a use case for #226 is using math operators in conjunction with tokens, e.g. for building heights.

The two main non-overlapping use cases I had in mind for this were for creating systems of line widths and font sizes across different GL layers. These could potentially be really useful for creating template styles that are fast to customize. However, these use cases require the ability to use constant values in functions, which you currently can't do in the editor.

@danpat
Copy link

danpat commented Feb 18, 2016

I have a specific use case. I'm generating vector tiles from OSRM that contain speed values on roads, in km/h. It would be nice to show localized values (mph vs km/h) by doing some simple math in the style.

I'm ambivalent about the syntax, but I've found this capability in Mapnik hugely useful.

Other basic math functions, like round() would also be helpful in my case.

@timrobertson100
Copy link

A use case:

Given vector tiles containing polygons which represent sales regions. Each polygon is accompanied with data giving sales totals for a range of months in an attribute list (e.g. Month1:€10000, Month2:€23000 etc). You want to do a visualisation with a double handled time slider, where the user selects the period (e.g. month23-month45) and the polygons are then coloured based on total sales in the month ranges - this lets the user explore which regions are hot over different time ranges. You need to do math across feature attributes to total them up, and they can't be predetermined, as the slider control on the page is not known in advance.

As far as I can tell from my (very limited) use, this is not possible using filters.

(If this is possible, can you please point me at how - I am trying to find ways around this at the moment)

@stackTom
Copy link

@timrobertson100 have you found a solution to this problem?

@timrobertson100
Copy link

@stackTom - I ended up doing server side processing on UI changes as I couldn't find a way in filters.

@jfirebaugh
Copy link
Contributor

See mapbox/DEPRECATED-mapbox-gl#15 for additional syntax proposals.

@lucaswoj
Copy link

Let's continue the conversation from mapbox/mapbox-gl-function#28 here 😄

To summarize so far:

  • Arbitrary expression functions will make our filters, functions, and cluster aggregators more powerful & flexible
  • Implementing arbitrary expressions will be challenging because they may need to run on the GPU
  • We are leaning towards a lispy syntax comprised of nested arrays
  • Devising a workable GUI for arbitrary expressions may be a challenge.

@lucaswoj lucaswoj changed the title Support basic math operators? Support arbitrary expression functions, filters, and cluster aggregators Dec 21, 2016
@lucaswoj
Copy link

@1ec5 Agreed, creating a point & click GUI for this will be a little tricky. I'm not sure that users demand a point and click GUI for this, however. Most computer users are familiar with the notion of editing formulas, in Excel or Numbers for example.

@1ec5
Copy link
Contributor

1ec5 commented Dec 21, 2016

Most computer users are familiar with the notion of editing formulas, in Excel or Numbers for example.

I have no qualms about an inline, text-based GUI for arithmetic or statistical expressions. But as soon as you introduce the notion of conditionals, you get a mini string language – an outcome that we took #104 on a tangent to avoid.

@lucaswoj lucaswoj changed the title Support arbitrary expression functions, filters, and cluster aggregators Arbitrary expression functions, filters, and cluster aggregators Dec 22, 2016
@lucaswoj
Copy link

lucaswoj commented Dec 22, 2016

Important use cases:

  • unit conversion
  • number formatting
  • token defaults
  • customizable interpolation
  • arithmetic on feature properties within functions

@lucaswoj lucaswoj changed the title Arbitrary expression functions, filters, and cluster aggregators Allow arbitrary expressions in functions, filters, and cluster aggregators Dec 22, 2016
@lucaswoj
Copy link

lucaswoj commented Feb 1, 2017

This issue was moved to mapbox/mapbox-gl-js#4077

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants