I have a query:
query {
productByHandle(handle: "${productHandle}") {
variants(first: 3) {
edges {
node {
title
id
priceV2 {
amount
}
image {
transformedSrc(maxWidth: 400)
}
}
}
}
}
}
Which works great. However, I'm struggling to find the syntax to get multiple transformedSrcs from the variant image. I want to use this for an image srcset, so I'll need to have multiple sizes returned.
I'm new to GraphQL in general. I tried an array on the image, using an AND with multiple maxWidth and scale, duplicating the image piece, etc. I've also searched the Shopify API docs many times.
Is this just not possible for some reason, or am I missing something?
I'm also curious for answers and new to GraphQL. I seem to have had some success using aliases of transformedSrc in the query, see below. Not entirely sure if this is the correct way though. I'm surprised by the lack of info consider it's essential for fast loading sites.
query {
collectionByHandle(handle: "archived") {
products(first: 250) {
edges {
node {
id
title
description
tags
images(first: 100) {
edges {
node {
altText
originalSrc
smallImage: transformedSrc(maxWidth: 200, crop: CENTER)
bigImage: transformedSrc(maxWidth: 400, crop: CENTER)
}
}
}
}
}
}
}
}
Related
I currently have images which the image name is returned by a function and is dynamically called based on a variable like this:
String _setImage() {
if (currentQuestion > 1 && currentQuestion < 11) {
return "assets/images/image_$intensityIndex.png";
} else {
return "assets/images/image.png";
}
}
I want to switch to preloading the images and I am using the technique described at Preload images in a stateful widget on Flutter, but I am not sure how to have the function return an image which the name is dynamically determined based on another variable. Here is what I have so far:
void initState() {
super.initState();
image0 = Image.asset('assets/images/image_0.png');
image1 = Image.asset('assets/images/image_1.png');
image2 = Image.asset('assets/images/image_2.png');
image3 = Image.asset('assets/images/image_3.png');
}
void didChangeDependencies() {
super.didChangeDependencies();
precacheImage(image0.image, context);
precacheImage(image1.image, context);
precacheImage(image2.image, context);
precacheImage(image3.image, context);
}
Image _setImage() {
if (currentQuestion > 1 && currentQuestion < 11) {
return ______________;
} else {
return image0;
}
}
All help is appreciated!
Am not sure how to return an image which the name is dynamically
determined based on another variable
You don't need to return with precach because if you use exact image that you cache.
Ex:
precacheImage('assets/images/image_1.png'); // if this is the image name
Image.asset('assets/images/image_1.png'); // when you use this it is getting from the cache but the path should be same.
If I explain it another way:
precacheImage("assets/images/image_$intensityIndex.png"); // image_1.png
Image.asset('assets/images/image_1.png'); // when you do this, asset taking from the cache by looking at the path.
We are using graphql and relay, and recompose.
I am getting some data from a Unit, but I also need some data from its Project.(A unit belongs to a project)
And I have figured out how to, get some images i need from the project like so:
project {
images {
fileKey
aspectRatio
}
but i get many images.. like 20.. and i just need the first one.. How do i tell relay or graphQl to give me just one?
Thanks, here is my whole fragment:
const enhance = compose(
fragment(graphql`
fragment DetailsSectionContainer_unit on Unit {
tourIdArchilogic
tourIdMatterport
images {
fileKey
aspectRatio
}
...TitleRowContainer_unit
...UnitSummaryContainer_unit
...ContactFormColumnContainer_unit
project {
images {
fileKey
aspectRatio
}
...ContactFormColumnContainer_project
}
company {
...ContactFormColumnContainer_company
}
...TourContainer_unit
}
fragment DetailsSectionContainer_rentedUnit on RentedUnit {
...UnitSummaryContainer_rentedUnit
}
fragment DetailsSectionContainer_vacantUnit on VacantUnit {
...UnitSummaryContainer_vacantUnit
}
`),
);
you should change the return type of your images to a connection, then you tell the server how many images you want to fetch like this:
project {
images(first: 1) {
edges {
node {
fileKey
aspectRatio
}
}
}
}
More about connections here ->
Grahpql connections
This is my Amibroker code for a 2 bar swing chart, I need to add a condition that if price falls below the previous swing low in one bar, then to treat it as a two bar move. The problem I have is, holding the last swing low price variable to check against todays low. I have commented the problem lines in caps. What I have I thought would work but the condition is not showing up on the swing chart. Can someone tell me what I am doing wrong.Thanks.
_SECTION_BEGIN("2 day swing");
upBar = H>Ref(H,-1);
dnBar = L<Ref(L,-1);
HighBarPrice=LowBarPrice=Null;
inLong=inShort=upCount=dnCount=fupbar=fdnbar=0;
for( i=1; i<BarCount; i++ )
{
if(inLong==0 AND inShort==0)
{
if(upBar[i])
{
upCount=upCount+1;
if(upCount==2)
{
fupbar[i] = 1;
inLong=1;
dnCount=0;
}
}
if(dnBar[i])
{
dnCount=dnCount+1;
if(dnCount==2)
{
fdnbar[i] = 1;
inShort=1;
upCount=0;
}
}
if(inLong==1)
{
if(dnBar[i])
{
dnCount=dnCount+1;
if(L[i]<LowBarPrice) {dnCount=2;} //THIS IS THE PROBLEM
if(dnCount==2)
{
fdnbar[i]=1;
inShort=1;
if(upBar[i])
{
upCount=1;
}
else
{
upCount=0;
}
continue;
}
}
if(upBar[i]) {HighBarPrice=H[i];}
if(upBar[i] AND NOT dnBar[i]){ dnCount=0;}
}
if(inShort==1)
{
if(upBar[i])
{
upCount=upCount+1;
if(H[i]>HighBarPrice) {upCount=2;}
if(upCount==2)
{
fupbar[i]=1;
inLong=1;
if(dnBar[i])
{
dnCount=1;
}
else
{
dnCount=0;
}
continue;
}
}
if(dnBar[i]) {LowBarPrice=L[i];}// DOWN BAR IN SHORT SWING SHOULD GIVE NEW LOW
if(dnBar[i] AND NOT upBar[i]){ upCount=0;}
}
}
// Swing chart drawn here
_SECTION_END();
Your LowBarPrice doesn't have an array indexer on it. Also, you initialize it as null and it stays that way because you never assign any value to it after initialization. So technically, in your condition, you're saying, if L[i] < null.
Write your conditions outside the loop. That'll create an array that will hold your price until you reference it in the loop.
So, for example, initialize LowBarPrice like this:
LowBarPrice = ValueWhen(DownBar, Ref(L,-1));
Thereafter, you'll get the price when you reference it in the loop.
if(L[i] < LowBarPrice[i])
This article really helped me get my head around looping in AmiBroker. It might give some context around your issue. The part that relates specifically to your question is under the section "Array Indexing
http://www.amibrokerforum.com/index.php?topic=50.0
Is there a way, how to z-index polygons using Leaflet nowadays? I am OK when the map is initiated, but when adding new polygons to existing map, I need new polygons to be sorted into existing ones base on their area - so bigger ones will not overlap small ones. I have found this solution:
Leaflet z-index
but it's veeeeery slow, when my map contains bigger amount of features. Any idea?
I have no idea about performance of this answer, but you could give it a try:
GeoJSON Layer Order In Leaflet 0.7.5
The main code is:
// To be called after adding a geoJsonLayer to the map.
function assignZindex(geoJsonLayer) {
geoJsonLayer.eachLayer(function (layer) {
layer._container.zIndex = layer.options.zIndex;
});
}
// To be called after assignZindex().
function reOrderVectorLayers() {
var root = map._pathRoot,
child = root.firstChild,
next;
while (child) {
next = child.nextSibling;
if (!next) {
break;
}
if (next.zIndex < child.zIndex) {
root.insertBefore(next, child);
if (next === root.firstChild) {
continue;
}
child = next.previousSibling;
continue;
}
child = next;
}
}
It assumes the zIndex property is a number defined in options of each of your vector (polygon) layer.
As said in comments of that question, if you use Leaflet 1.x, you can now create your own panes that you can order through CSS z-index, and insert each of your vector layer in a specified pane.
I've searched everywhere to find out how to add a class to a particular row in slickgrid. It looks like there used to be a rowCssClasses property but it's gone now. Any help on this would be extremely appreciated.
Update: I figured it out using the getItemMetadata...so before you render, you have to do something like this:
dataView.getItemMetadata = function (row) {
if (this.getItem(row).compareThis > 1) {
return {
'cssClasses': 'row-class'
};
}
};
That will inject that 'row-class' into the row that matches the if statement. It seems that this getItemMetadata function doesn't exist until you put it there and slickGrid checks to see if there's anything in there. It makes it kind of difficult to figure out it's options but if you search for getItemMetadata in the slick.grid.js file you should find some hidden treasures! I hope this helps someone!
If there's a better way of doing this, please let me know.
In newer versions of SlickGrid, DataView brings its own getItemMetadata to provide formatting for group headers and totals. It is easy to chain that with your own implementation though. For example,
function row_metadata(old_metadata_provider) {
return function(row) {
var item = this.getItem(row),
ret = old_metadata_provider(row);
if (item && item._dirty) {
ret = ret || {};
ret.cssClasses = (ret.cssClasses || '') + ' dirty';
}
return ret;
};
}
dataView.getItemMetadata = row_metadata(dataView.getItemMetadata);
myDataView.getItemMetadata = function(index)
{
var item = myDataView.getItem(index);
if(item.isParent === true) {
return { cssClasses: 'parentRow' };
}
else {
return { cssClasses: 'childRow' };
}
};
//In my CSS
.parentRow {
background-color: #eeeeee;
}
.childRow {
background-color: #ffffff;
}
You could use the setCellCssStyles function:
https://github.com/mleibman/SlickGrid/wiki/Slick.Grid#wiki-setCellCssStyles
grid.setCellCssStyles(key, hash)
key - A string key. Will overwrite any data already associated with
this key.
hash - A hash of additional cell CSS classes keyed by row number and
then by column id. Multiple CSS classes can be specified and separated
by space.
Example:
{
0: {
"number_column": "cell-bold",
"title_column": "cell-title cell-highlighted"
},
4: {
"percent_column": "cell-highlighted"
} }
I used that to highlight edited fields in my grid. I didn't like the getItemMetadata method.