Having a highchart, in which there are multiple lines, how can i get index of array data from which the point has been derived.
this.series.data.indexOf( this.point)
It gives correct index of the point from line. But i need the index of the array from which series data has been loaded.
To get the index of a particular series you just use
this.series.index
with 0 being the first series.
There is a bug in yourChart.series.index selector:
It works normal when you add new series with yourChart.addSeries({..}) and it updates indexes.
But after you delete some series with yourChart.series[series.index].remove() it not updates indexes, until you add one more series.
Though, if you need to delete couple series one by one, you should select particular series by using simply yourChart.series array:
for (i in yourChart.series) {
// your search condition, for example by name
if (searchByName === chart.series[i].name) {
chart.series[i].remove();
}
}
where i is real index, not series.index!
Although, you can't select corect index by property chart.series.index which you can access at yourChart.series.options.index, you can't select series using it.
Related
I have models named Issue and Label. Each issue can have many labels. Each label can have many issues.
I am trying to build a query that will return an issue that contains all of the supplied labels.
For instance, if I supply ['bug', 'fix', 'enhancement'] I want issues that have all three of those three labels at least.
Currently, I have:
labels = ['bug', 'fix', 'enhancement']
Issue.joins(:labels).where(labels: { name: labels }).distinct
But this is insufficient as it returns issues that have at least one of the label names. I see this is because is because an 'IN' operator is generated:
WHERE "labels"."name" IN ('bug', 'fix', 'enhancement')
And from here on, I'm lost. The labels array can be any length. Can I get the result I want in a single query?
How can I find rows in a table that point to rows in another that match all the specified column values?
I didn't check it, but maybe this approach could work
Issue.select('issues.id, count(labels.id) as cnt').includes(:labels).where(labels: { name: labels }).group('issues.id').having("cnt = #{labels.size}");
My doubt is regarding Filter Screen.
I want to store & remove data which user selected & deselected from Filter Screen respectively. I am not sure what data type to use here.
As it appears from below image :
Suppose I have Few filter headings like "Category", "Color", "Unit",etc.
& inside of every heading i have some values like in category I have values from category 1, category 2... upto category 50.
Now when user selects anything like Category2, category3.. I can store those particular values in Array, but when user deselect any category(unchecking the checkboxes) randomly then how i will be able to remove that particular value from array because i can't get related index inside array.(means like user selected some 10 categories then i have some 10 values inside my array but thay are not matched indexwise with values from tableView index.)
Assist me on how to approach this..
Here is how i would approach the problem. Assuming i have a data source which would contain the items without applying any filter. (In practice this is not how it would be, you would probably be getting your data source via network calls) Once a user applies or removes a filter by checking or unchecking the checkbox, i would filter the data source with the active filters.
Let's say this is your item class.
class Item {
var category: Category
var color: Color
}
enum Category {
case one
case two
.
.
case none
}
// Similarly for color and other parameters
Now this would be your filter object that maintains all the filters that are active.
class FilterParameters {
var category: [Category]? = nil
var color: [Color]? = nil
}
Create an object of this class and every time a filter is checked or unchecked, filter your data source with the current active filters. (If a filter is not selected then ignore that filter and construct filter parameters based on the ones you do have).
I'm stuck with this problem. I;ve built an API in Rails and a client in Angular. I've got a model called Todo which has a property called order. When I create a new Todo, I automatically assign the newly created todo a value order like so:
#todo = Todo.create(todo_params)
#todo.order = Todo.count + 1
And to display all todos:
#todos = Todo.where(...).order(:order.desc)
In my client I'm using Sortable for the UI manipulation and there's a method called onUpdate which gives me the new indexes for the array.
The problem I'm having is that the indexes are considerably different than the value I've in the order property. When the aforementioned function is called I get the item and two more values: newIndex and oldIndex, but the problem is that this doesn't give me the index of the other todos, so how can I reorganise this on the database?
I'd appreciate any help as I'm a bit at loss here.
PS: Please note this is Rails API only, so no views.
EDIT
Output wanted:
Let's imagine this: I have three items in the database: {name: A, order: 1}, {name: B, order: 2}, {name: C, order: 3}. In the front-end, while using ng-repeat, each item will have an $index. Let's say for argument sake that A will have $index value of 0, B 1, C 2. At the moment, when I use the Angular library Sortable, when I manually sort the list, I get the values: oldIndex and newIndex which corresponds to the position of the item I've moved within the array, but it does not shows the position of all items within array, so I don't know how to use the properties these values to update the object in the database.
For anyone that might be interested: At the end I've used the following solution:
Every time Sortable updated an item, it also sends an array with all items on it in the correct order. I then looped through the array and updated each item with the new order. Not sure this is the most efficient way to do it but it resolved the problem for now.
I'm trying to recreate the buggy CNContactPickerViewController made by Apple so I have an array of data [CNContact] which i need to display neatly in a UITableView. It all works great until i try to add sections based on the first letter of the contacts' last names to that table. The only solution i found is to iterate through the [CNContact] array and manually group every contact into a dictionary, based on their initials resulting in a [String:[CNContact]]. Is there a better way to do this?
The end result can be viewed in the screenshot below.
This will sort your contacts by last name. Might be overkill, as you want them grouped only by the first letter of the last name, whereas this will sort using the whole name.
var contacts :[CNContact] = [CNContact]();
// fill your contacts here
contacts.sortInPlace { (contact1, contact2) -> Bool in
contact1.familyName.compare(contact2.familyName) == .OrderedAscending
}
Not sure if you need the original ordering. If you want the original array, do create copy of the old one, and do sort in place for the copy.
No matter how I swing it, I need some kind of function to find the index of a item in an array supplied as a parameter.
I am trying to simply update items in a collection based on the index of one of their properties in an array, and have been poring through Cypher docs for nearly 2 hours...
It would also be acceptable to order the items by that array, and then run a foreach on the ordered list...
Following #stefan-armbruster answer and great blog post, a slow but simple index_of can be done with:
reduce(x=[-1,0], i IN [1,2,7,5,21,5,1,435] |
CASE WHEN i = 21 THEN [x[1], x[1]+1] ELSE [x[0], x[1]+1] END
)[0]
Here reduce function works with a two elements array: the position and the current index. If an element in your array matches the given condition, the first element of the reduced array will be replaced with the current index.
I put an example on neo4j console http://console.neo4j.org/?id=34byv
I've blogged about that recently. You can use the reduce function with an three element array as state variable containing
the index of the highest occupation so far
the current index (aka iteration number)
the value of highest occupation so far
As an example to find the index of max element in an array:
RETURN reduce(x=[0,0,0], i IN [1,2,2,5,2,1] |
CASE WHEN i>x[2] THEN [x[1],x[1]+1,o] ELSE [x[0], x[1]+1,x[2]] END
)[0]