How to change mark properties with selections [vega-lite] - visualization

How can one change mark properties (not field encodings or values) with vega-lite selections ?
For example, to highlight selected bars with a layer mark {type: bar, fill: none, stroke, black}.

I think I found an answer in the interactive bar select highlight example
It may not be directly possible to change mark properties via selection but one can conditionally set fillOpacity and strockWidth encodings channel with a selection.
Releveant piece of code is :
"fillOpacity": {
"condition": {"selection": "select", "value": 1},
"value": 0.3
},
"strokeWidth": {
"condition": [
{
"test": {
"and": [
{"selection": "select"},
"length(data(\"select_store\"))"
]
},
"value": 2
},
{"selection": "highlight", "value": 1}
],
"value": 0
}

Related

Highlight characters within words in Opensearch query

I have set up a custom analyser that uses an edge_ngram filter for a text field. I'm then trying to highlight the characters a user types but opensearch is highlighting the entire word, even if only a small number of characters have been typed.
E.g. Typing "Man" in the search bar will result in the word "Manly" being highlighted. <em>Manly</em> Trail Running Tour. What I really want is <em>Man</em>ly Trail Running Tour.
This should be possible with the fvh highlighting type and chars as the boundary_scanner argument per the docs https://opensearch.org/docs/2.1/opensearch/search/highlight/#highlighting-options
Settings
"title_autocomplete": {
"type": "text",
"term_vector": "with_positions_offsets",
"analyzer": "autocomplete"
}
"analysis": {
"filter": {
"edge_ngram_filter": {
"type": "edge_ngram",
"min_gram": "3",
"max_gram": "20"
}
},
"analyzer": {
"autocomplete": {
"filter": [
"lowercase",
"edge_ngram_filter"
],
"type": "custom",
"tokenizer": "standard"
}
}
}
Query:
{
"track_total_hits": true,
"highlight": {
"type": "fvh",
"boundary_scanner": "chars",
"fields": {
"title_autocomplete": {}
}
},
"size": 6,
"query": {
"multi_match": {
"query": "Man",
"fields": [
"title_autocomplete^2"
]
}
}
}

VS Code custom syntax highlight

I would like to ask for help. I have file with custom format. Each line looks similair to this:
T S 123456 0 0.3 -0.9 -0.2 V paramName
Records are separated by tabs (\t)
Basically, i only want to highlight, lets say each word (column, because there will be a lot of those lines) by diferent style/color - it does not matter. I read a lot about custom grammars for VS Code, but I still does not have any idea, how to do it.
One of my attempts:
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "Testlist for DataExpress",
"patterns": [
{
"include": "#records"
},
{
"include": "#keywords"
}
],
"repository": {
"keywords": {
"patterns": [{
"name": "keyword.control.tsv",
"match": "\\b(TSTLST|Program|Device|Comment)\\b"
}]
},
"records":{
"match": "T\tS\t[0-9]+\t[0-9]+\t[0-9]+.[0-9]+\t[+-][0-9]+.[0-9]+\t[+-][0-9]+.[0-9]+\t.*\t.*",
"captures": {
"1": {
"name":"keyword.operator.new"
},
"2": {
"name":"markup.bold"
},
"3": {
"name":"variable"
},
"4": {
"name":"entity.name.class"
}
}
}
},
"scopeName": "source.tsv"
}
Idea behind was, get back list defined by regexp and then each capture format in different way.
I know, thats a silly idea, but as I said, i am out of ideas for now.
Thanks a lot
Edit
From comment:
Correct regexp is :
(T\tS\t)([0-9]+\t[0-9]+)(\t[0-9]+.[0-9]+)(\t[+-][0-9]+.[0-9]+\t[+-][0-9]+.[0-9]+)(\t.*)(\t.*)

Mapbox GL style line color based on property text value

I'm trying to style a single GeoJSON source with different line colors based on a feature property using react-map-gl, and I can't find a way to get set the color of lines in a smart way.
Most of all, I would love to apply a function on the dataset to return the color of my own choosing based on a feature property value, but so far I haven't fount anything about it. If you know about it, please point in my direction:)
If I have the following GeoJSON:
{
"type": "FeatureCollection",
"name": "lineData",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "Need": "Urgent" }, "geometry": { "type": "MultiLineString", "coordinates": [ [ [ 10.653823175868171, 59.676506860589157 ], [ 10.652881996887283, 59.675443989456632 ] ] ] } },
{ "type": "Feature", "properties": { "Need": "Starting" }, "geometry": { "type": "MultiLineString", "coordinates": [ [ [ 10.658536710768077, 59.680279341285896 ], [ 10.65787427600862, 59.680222775937636 ] ] ] } },
{ "type": "Feature", "properties": { "Need": "Medium" }, "geometry": { "type": "MultiLineString", "coordinates": [ [ [ 10.653224904719789, 59.67859470385492 ], [ 10.653201052045171, 59.678557551379008 ] ] ] } },
]
}
I would like to be able to style this source data with different line colors based on the property "Need". Say, urgent becomes red, medium becomes yellow, and starting becomes green.
I've read about styling expressions at mapbox, and I believe the "feature-state" is key to solving this, but I cant wrap my head around how to get the color converted from a feature.
If this in the rendering:
<Source id="my-data" type="geojson" data={TheDataFileWithSomeData}>
<Layer {...layerStyleTheLines } />
</Source>
Then I want a layer styling something like this (not working):
const layerStyleTheLines = {
id: 'style_it_to_red',
type: 'line',
paint: {
'line-color': [
[["==", ["feature-state", "Need"], "Urgent"],"red"],
[["==", ["feature-state", "Need"], "Medium"],"yellow"],
[["==", ["feature-state", "Need"], "Starting"],"green"]
],
'line-width': 3,
}
};
Thanks for all your help!
I've read about styling expressions at mapbox, and I believe the "feature-state" is key to solving this, but I cant wrap my head around how to get the color converted from a feature.
You only want feature-state if you're intending to manipulate the feature attributes dynamically, which I don't think you are.
You probably just want regular data-driven styling:
const layerStyleTheLines = {
id: 'style_it_to_red',
type: 'line',
paint: {
'line-color': [
'match', ['get','Need'],
'Urgent', 'red',
'Medium', 'yellow',
'Starting','green',
'black'
],
'line-width': 3,
}
};

How to set the ProcessFlowLaneHeader state with JSON-model?

i'm currently working on an SAPUI5 app which includes a Process Flow control.
I want to set the state of the ProcessFlowLaneHeader according to values in my JSON-model but it keeps changing to a state represting each existing state of the nodes.
So I want the "donut" to show 2/3 of green, 1/12 of grey and 1/4 of red color(see JSON below). Instead it shows me 1/3 of each. When I look at the properties of the ProcessFlowLaneHeader through the UI5 Inspector while the app is running it shows me:
state: {
0: {
"state": "Positive",
"value": 1
}
1: {
"state": "Negative",
"value": 1
}
2: {
"state": "Neutral",
"value": 1
}
3: {
"state": "Planned",
"value": 0
}
4: {
"state": "Critical",
"value": 0
}
Did i make a mistake or is SAUPUI5 just overwriting my state?
How can I set the state of the ProcessFlowLaneHeade?(onInit on controller?)
My JSON:
...
"lanes": [{
"id": "0",
"icon": "sap-icon://sales-quote",
"label": "MoBe",
"position": 0,
"state": [{
"state": "Positive",
"value": 8
}, {
"state": "Negative",
"value": 1
}, {
"state": "Neutral",
"value": 3
}, {
"state": "Planned",
"value": 0
}, {
"state": "Critical",
"value": 0
}]
},
...
My View:
<ProcessFlow id="processflow1" foldedCorners="false" wheelZoomable="false" class="PFLayoutSpec" nodes="{Monitor1>/nodes}" lanes="{Monitor1>/lanes}">
<nodes>
<ProcessFlowNode laneId="{Monitor1>lane}" nodeId="{Monitor1>id}" title="{Monitor1>title}" children="{Monitor1>children}" state="{Monitor1>state}" value="{Monitor1>value}" stateText="{Monitor1>stateText}" texts="{Monitor1>texts}" highlighted="{Monitor1>highlighted}" focused="{Monitor1>focused}" titleAbbreviation="{Monitor1>titleAbbreviation}"/>
</nodes>
<lanes>
<ProcessFlowLaneHeader laneId="{Monitor1>id}" iconSrc="{Monitor1>icon}" text="{Monitor1>label}" position="{Monitor1>position}" state="{Monitor1>state}" press="onChangeDonut"/>
</lanes>
</ProcessFlow>
Thank you for your help!
Because you are showing documents in the nodes aggregation, the ProcessFlowLaneHeader state is automatically calculated from the states of the documents.
See documentation:
This type is used in the 'state' property of the ProcessFlowLaneHeader. For example, app developers can set the status of the lane header if lanes are displayed without documents. If the complete process flow is displayed (that is, if the lane header is displayed with documents underneath), the given state values of the lane header are ignored and will be calculated in the ProcessFlow according to the current state of the documents.

Magento 2 REST API - get product by slug, or get media in REST search

I have an ember app which I'm using as the front end. I need to fetch a product from the REST api but instead of using the SKU, I need to use the slug. So I access the following endpoint which works fine: http://*.com/index.php/rest/V1/products?searchCriteria[filter_groups][0][filters][0][field]=url_key&searchCriteria[filter_groups][0][filters][0][value]=daniels-icecream-slug
However, the result is obviously a product list as opposed to the product endpoint, so some of the data is omitted. Namely, the media_gallery_entries field. So is there anyways I can either return this data in the /products?searchCriteria endpoint or is there a way I can fetch /products/:slug instead of /products/:sku for the product endpoint?
you need to define conditionType as well with the API Call like following
V1/products/?searchCriteria[filterGroups][0][filters][0][field]=url_key&searchCriteria[filterGroups][0][filters][0][value]=%shirt%&searchCriteria[filterGroups][0][filters][0][condition_type]=like
Parameters :
searchCriteria[filterGroups][0][filters][0][field]=url_key
searchCriteria[filterGroups][0][filters][0][value]=%shirt%
searchCriteria[filterGroups][0][filters][0][condition_type]=like
Note: Make sure to prefix & suffix % in value as per your requirements.
I am using the same in my api Calls and it works
I'm using Magento v2.2, and when I do a search, each item has a image attribute (in the custom_attributes list) that mangento automatically adds to a product when up add an image to it:
{
"items": [{
"sku": "MH07-XS-Black",
"name": "Hero Hoodie-XS-Black",
"custom_attributes": [{
"attribute_code": "description",
"value": "<p>Gray and black color blocking sets you apart as the Hero Hoodie keeps you warm on the bus, campus or cold mean streets. Slanted outsize front pockets keep your style real . . . convenient.</p>\n<p>• Full-zip gray and black hoodie.<br />• Ribbed hem.<br />• Standard fit.<br />• Drawcord hood cinch.<br />• Water-resistant coating.</p>"
},
{
"attribute_code": "image",
"value": "/m/h/mh07-black_main.jpg"
},
{
"attribute_code": "small_image",
"value": "/m/h/mh07-black_main.jpg"
},
{
"attribute_code": "thumbnail",
"value": "/m/h/mh07-black_main.jpg"
},
{
"attribute_code": "color",
"value": "49"
},
{
"attribute_code": "minimal_price",
"value": "54.0000"
},
{
"attribute_code": "category_ids",
"value": [
"15"
]
},
{
"attribute_code": "options_container",
"value": "container2"
},
{
"attribute_code": "required_options",
"value": "0"
},
{
"attribute_code": "has_options",
"value": "0"
},
{
"attribute_code": "url_key",
"value": "hero-hoodie-xs-black"
},
{
"attribute_code": "msrp_display_actual_price_type",
"value": "0"
},
{
"attribute_code": "tax_class_id",
"value": "2"
},
{
"attribute_code": "size",
"value": "167"
}
]
}]
}