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: move vega charts to API #185

Merged
merged 7 commits into from
Jun 25, 2024
Merged

Conversation

Marc-AntoineA
Copy link
Collaborator

@Marc-AntoineA Marc-AntoineA commented Jun 21, 2024

What

This PR implements moves vega charts serverside and generalizes it a little (we just have to add <searchalicious-chart name="..."/> clientside).

Resolves #123

@Marc-AntoineA Marc-AntoineA marked this pull request as draft June 21, 2024 16:49
app/validations.py Outdated Show resolved Hide resolved
} = {
q: queryParts.join(' '),
langs: this.langs,
page_size: this.pageSize.toString(),
index: this.index,
charts: ['nutriscore_grade', 'nova_group', 'ecoscore_grade'].join(',')
Copy link
Member

Choose a reason for hiding this comment

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

It should be a property.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same as facets, charts is built from <searchalicious-chart name=.../> nodes.

app/query.py Outdated Show resolved Hide resolved
* any agg: true search field can be used;
* code mutulization with facets ;
* list of charts is listed from <searchalicious-chart/> list
@Marc-AntoineA Marc-AntoineA force-pushed the feat-implement-vega-serverside branch 2 times, most recently from 559ba92 to 4be2add Compare June 24, 2024 14:46
@Marc-AntoineA Marc-AntoineA force-pushed the feat-implement-vega-serverside branch from 4be2add to 5dea4e5 Compare June 24, 2024 14:55
@Marc-AntoineA Marc-AntoineA marked this pull request as ready for review June 24, 2024 15:49
Comment on lines +14 to +120
{"category": bucket["key"], "amount": bucket["doc_count"]}
for bucket in buckets
if bucket["key"] != "unknown"
]
values.sort(key=lambda x: x["category"])

charts[chart_name] = {
"$schema": "https://vega.github.io/schema/vega/v5.json",
"title": chart_name,
"autosize": {"type": "fit", "contains": "padding"},
"signals": [
{
"name": "width",
"init": "containerSize()[0]",
"on": [{"events": "window:resize", "update": "containerSize()[0]"}],
},
{
"name": "tooltip",
"value": {},
"on": [
{"events": "rect:pointerover", "update": "datum"},
{"events": "rect:pointerout", "update": "{}"},
],
},
],
"height": 140,
"padding": 5,
"data": [
{
"name": "table",
"values": values,
},
],
"scales": [
{
"name": "xscale",
"type": "band",
"domain": {"data": "table", "field": "category"},
"range": "width",
"padding": 0.05,
"round": True,
},
{
"name": "yscale",
"domain": {"data": "table", "field": "amount"},
"nice": True,
"range": "height",
},
],
"axes": [
{"orient": "bottom", "scale": "xscale", "domain": False, "ticks": False}
],
"marks": [
{
"type": "rect",
"from": {"data": "table"},
"encode": {
"enter": {
"x": {"scale": "xscale", "field": "category"},
"width": {"scale": "xscale", "band": 1},
"y": {"scale": "yscale", "field": "amount"},
"y2": {"scale": "yscale", "value": 0},
},
"update": {
"fill": {"value": "steelblue"},
},
"hover": {
"fill": {"value": "red"},
},
},
},
{
"type": "text",
"encode": {
"enter": {
"align": {"value": "center"},
"baseline": {"value": "bottom"},
"fill": {"value": "#333"},
},
"update": {
"x": {
"scale": "xscale",
"signal": "tooltip.category",
"band": 0.5,
},
"y": {
"scale": "yscale",
"signal": "tooltip.amount",
"offset": -2,
},
"text": {"signal": "tooltip.amount"},
"fillOpacity": [
{"test": "datum === tooltip", "value": 0},
{"value": 1},
],
},
},
},
],
}
Copy link
Collaborator

@Kout95 Kout95 Jun 25, 2024

Choose a reason for hiding this comment

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

For me, you have to give data by API and then build the options in frontend like this :
This allows to avoid chart options for every graph

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

After discussion, we will keep it like this right now. Might be re-discussed with Alex.

return errors
global_config = cast(Config, CONFIG)
index_id, index_config = global_config.get_index_config(index_id)
if index_config is None:
raise ValueError(f"Cannot get index config for index_id {index_id}")
for field_name in facets:
print(index_config)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fix me

frontend/src/search-chart.ts Outdated Show resolved Hide resolved
@Marc-AntoineA Marc-AntoineA merged commit 8be0a9f into main Jun 25, 2024
6 checks passed
@Marc-AntoineA Marc-AntoineA deleted the feat-implement-vega-serverside branch June 25, 2024 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

API / component proposal for Charts
3 participants