I'm trying to create a diagram which shows links between nodes on the same hierarchy level but witthin different groups in a circular layout. It's basically a visualisation of keywords/tags/groups attached to objects a la Circos:
var data =
[
{
"name": "Adam",
"tags": ["tall", "blonde"]
},
{
"name": "Barbara",
"tags": ["tall", "brunette", "student", "single"]
}
];
Or, like something I'm trying to do:
var data =
[
{
"name": "Project 1",
"categories":
[
"Category A",
"Category B",
"Category C",
"Category D"
]
},
{
"name": "Project 2",
"categories":
[
"Category C",
"Category D",
"Category E"
]
},
{
"name": "Project 3",
"categories":
[
"Category A",
"Category E"
]
},
{
"name": "Project 4",
"categories":
[
"Category A",
"Category C",
"Category D",
"Category E"
]
},
{
"name": "Project 5",
"categories":
[
"Category A",
"Category B",
"Category D"
]
}
];
Each object can have a number of categories corresponding to the number of node copies appearing in the circle. Visually, it should look something like this:
Is it possible with D3.js? If so, which layout? It looks like it would be something between chord (but without values) and bundle (without hierarchy).
I'd imagine the script would need to traverse through the JSON data and find all unique categories first and then distribute and interlink nodes of each object depending on what and how many categories are attached to it. Finally, it would label each category.
Any ideas would be appreciated.
Related
I created categories in craft and I'd like to get total amount of entries related to individual category. Right now I have a query that returns my categories:
query categoriesQuery {
categories(group: "projectCategories") {
id
slug
title
}
}
but I would also like for each category to return the amount of related entries.
So I would like to add another field that counts related entries - I wanted to do somethings like this, but it won't work:
query categoriesQuery {
categories(group: "projectCategories") {
id
slug
title
_count(relatedToEntries(section: "projects"))
}
}
Is there any way to get amount of entries related to single category? The result that I'm trying to achieve would look somethings like this:
{
"data": {
"categories": [
{
"id": "1",
"slug": "Category-1",
"title": "Category 1",
"amountOfRelatedEntries": 1
},
{
"id": "2",
"slug": "Category-2",
"title": "Category 2",
"amountOfRelatedEntries": 2
},
{
"id": "3",
"slug": "Category-3",
"title": "Category 3",
"amountOfRelatedEntries": 3
},
]
}
}
<v-jstree :data="data"
textFieldName="name"
#item-click="itemClick"
/>
If I use statics - then this works:
data() {
return {
data: [
{
"name": "title 1",
"children": [
{
"name": "Child 1",
},
{
"name": "Child 2",
},
]
}
]
}
},
If I use ajax, then all data is loaded, but openChildren doesn't work(
Response comes in the correct format:
[{ "id": 1, "name": "Title", "children": [{ "id": 1, "name": "Child 1" }, { "id": 2, "name": "Child 2" }.......
children are also loaded, why does the functionality break down?
By trial, I found a way to solve it) in the server response in parent, the "opened" parameter must be specified , either true or false
I have a ProductDocument model in CosmosDB, which represents a Product. Within that model there is a subdocument contributors which holds who has contributed to the Product. Each contributor has a role.
Now I have been experimenting with a query that needs to:
Only select ProductDocument with a contributor.roleDescription of Author
Only select ProductDocument with a division of Pub 1
Only include contributors sub documents with a contributor.roleDescription of Author in the result set.
Now I'm struggling with:
Part 3 of select above. How do I accomplish this bit as my result set is including both contributor.roleDescription of Author AND Illustrator
Example Cosmos Model:
[
{
"id": "1",
"coverTitle": "A Title",
"pubPrice": 2.99,
"division" :"Pub 1",
"Availability": {
"code": "20",
"description": "Digital No Stock"
},
"contributors": [
{
"id": 1,
"firstName": "Brad",
"lastName": "Smith",
"roleDescription": "Author",
"roleCode": "A01"
},
{
"id": 2,
"firstName": "Steve",
"lastName": "Bradley",
"roleDescription": "Illustrator",
"roleCode": "A12"
}
]
},
{
"id": "2",
"coverTitle": "Another Title",
"division" :"Pub 2",
"pubPrice": 2.99,
"Availability": {
"code": "50",
"description": "In Stock"
},
"contributors": [
{
"id": 1,
"firstName": "Gareth Bradley",
"lastName": "Smith",
"roleDescription": "Author",
"roleCode": "A01"
}
]
}]
Here is my SQL which I have been playing around with in the Data Explorer:
SELECT VALUE p
FROM Products p
JOIN c IN p.contributors
WHERE c.roleDescription = 'Author'
AND p.division = 'Pub 1'
Here is my LINQ query from my service:
var query = client.CreateDocumentQuery<ProductDocument>(
UriFactory.CreateDocumentCollectionUri("BiblioAPI", "Products"),
new FeedOptions
{
MaxItemCount = -1,
EnableCrossPartitionQuery = true
}
)
.SelectMany(product => product.Contributors
.Where(contributor => contributor.RoleDescription == "Author")
.Select(c => product)
.Where(p => product.Division == "Pub 1"))
.AsDocumentQuery();
List<ProductDocument> results = new List<ProductDocument>();
while (query.HasMoreResults)
{
results.AddRange(await query.ExecuteNextAsync<ProductDocument>());
}
It selects the correct records, but how do I de-select the Illustrator sub document of contributor, because at the moment I get the following:
{
"id": "1",
"coverTitle": "A Title",
"pubPrice": 2.99,
"division" :"Pub 1",
"Availability": {
"code": "20",
"description": "Digital No Stock"
},
"contributors": [
{
"id": 1,
"firstName": "Brad",
"lastName": "Smith",
"roleDescription": "Author",
"roleCode": "A01"
},
{
"id": 2,
"firstName": "Steve",
"lastName": "Bradley",
"roleDescription": "Illustrator",
"roleCode": "A12"
}
]
}
But the following output is what I want, excluding the Illustrator contributor sub document:
{
"id": "1",
"coverTitle": "A Title",
"pubPrice": 2.99,
"division" :"Pub 1",
"Availability": {
"code": "20",
"description": "Digital No Stock"
},
"contributors": [
{
"id": 1,
"firstName": "Brad",
"lastName": "Smith",
"roleDescription": "Author",
"roleCode": "A01"
}
]
}
EDIT:
I would like to filter on Product if one of the subdocument contributor.roleDescription equals Author. So if the Product record doesn't include a Author contributor I don't want it
I want to include each contributor subdocument that equals Author. So if there are multiple Author contributor subdocuments for a Product, I want to include them, but exclude the Illustrator ones.
You could have a Collection of ProductDocuments.
Help on the fluent LINQ syntax would help greatly.
Azure CosmosDB now supports subqueries. Using subqueries, you could do this in two ways, with minor differences:
You could utilize the ARRAY expression with a subquery in your projection, filtering out contributors that you don’t want, and projecting all your other attributes. This query assumes that you need a select list of attributes to project apart from the array.
SELECT c.id, c.coverTitle, c.division, ARRAY(SELECT VALUE contributor from contributor in c.contributors WHERE contributor.roleDescription = "Author") contributors
FROM c
WHERE c.division="Pub 1"
This assumes that you need to filter on division "Pub 1" first followed by the subquery with the ARRAY expression.
Alternately, if you want the entire document along with the filtered contributors, you could do this:
SELECT c, ARRAY(SELECT VALUE contributor from contributor in c.contributors WHERE contributor.roleDescription = "Author") contributors
FROM c
WHERE c.division="Pub 1"
This will project the original document with a "Pub 1" division in the property labeled "c", along with a filtered contributor array separately in the property labeled "contributors". You could refer this contributor array for your filtered contributors and ignore the one in the document.
This will do what you want, but obviously if you have multiple contributors you want to show it might not do quite what you are after - it's hard to tell with your question if that is what you want exactly
SELECT p.id, p.coverTitle, p.pubPrice, p.division, p.Availability, c as contributors
FROM Products p
JOIN c IN p.contributors
WHERE c.roleDescription = 'Author'
AND p.division = 'Pub 1'
and the output is:
[
{
"id": "1",
"coverTitle": "A Title",
"pubPrice": 2.99,
"division": "Pub 1",
"Availability": {
"code": "20",
"description": "Digital No Stock"
},
"contributors": {
"id": 1,
"firstName": "Brad",
"lastName": "Smith",
"roleDescription": "Author",
"roleCode": "A01"
}
}
]
Note that contributors is not a list, it's a single value, so if multiple contributors match the filter, then you will get the same product returned multiple times.
I am developing a swimlane diagram using D3 v4. The diagram is a planning aid depicting Tasks which are carried out over time. The Tasks are up the Y axis and time is along the X axis.
Here is some example data to help understand my problem:
Tasks
[
{
"id": "2a606884-d6b9-4ad1-a5ff-5c816c43fef6",
"description": "Task 01",
"start": "2017-11-07T02:00:00.000Z",
"finish": "2017-11-07T08:00:00.000Z",
"label": "Task 01",
"taskTypeId": "0b936e39-49b9-4cc8-b5c5-b1f1338e9faf",
"taskTypeDescription": "Walk the dog"
},
{
"id": "6713025e-63e2-4ff3-8202-43e17c13431d",
"description": "Task 02",
"start": "2017-11-07T08:00:00.000Z",
"finish": "2017-11-07T12:00:00.000Z",
"label": "Task 02 02",
"taskTypeId": "9af060ba-5abf-4627-8462-7c21281ab487",
"taskTypeDescription": "Wash the car"
},
{
"id": "ff071aa5-e14b-4b32-bd51-7cf079f4c876",
"description": "Task 03",
"start": "2017-11-07T12:00:00.000Z",
"finish": "2017-11-07T14:00:00.000Z",
"label": "Task 03",
"taskTypeId": "8e6a8b11-0e23-4473-8795-ac74fc1efe07",
"taskTypeDescription": "Make the beds"
},
{
"id": "a84219e2-5da9-4119-915b-d84f35fda9d0",
"description": "Task 04",
"start": "2017-11-07T12:00:00.000Z",
"finish": "2017-11-07T14:00:00.000Z",
"label": "Task 04",
"taskTypeId": "a065dfe2-2c68-4467-84a5-1fce7c34513b",
"taskTypeDescription": "Wash up dishes"
}
]
New TaskTypes array nested by Area:
[
{
"key": "Outdoor",
"values": [
{
"id": "a97ad203-37e4-4fb8-8168-c3fdc1980d3d",
"description": "Walk the dog",
"areaId": "19952c5a-b762-4937-a613-6151c8cd9332",
"areaDescription": "Outdoor"
},
{
"id": "0b936e39-49b9-4cc8-b5c5-b1f1338e9faf",
"description": "Wash the car",
"areaId": "19952c5a-b762-4937-a613-6151c8cd9332",
"areaDescription": "Outdoor"
}
]
},
{
"key": "Indoor",
"values": [
{
"id": "8632bd18-8968-4185-95f0-f093f7fc9a02",
"description": "Make the beds",
"areaId": "87d8f755-ef60-4cfa-9a4a-c94cff9f8a22",
"areaDescription": "Indoor"
},
{
"id": "8e6a8b11-0e23-4473-8795-ac74fc1efe07",
"description": "Wash the dishes",
"areaId": "87d8f755-ef60-4cfa-9a4a-c94cff9f8a22",
"areaDescription": "Indoor"
}
]
}
]
So far my diagram lists all the TaskTypes up the Y axis using a simple 1 dimensional array of TaskTypes. Each Task is then positioned, within its row for the Task's TaskType, along the X axis according to the start/finish of the Task. All good.
My yScale is currently like this:
this.yScale = d3
.scaleBand()
.domain(this.taskTypeDescriptions)
.rangeRound([0, this.chartHeight])
.padding(padding);
...where this.taskTypeDescriptions is a simple 1 dimensional array of TaskTypes.
Now I have grouped TaskTypes by Area. In my example data above there are 2 Areas: Outdoor and Indoor. I want to visually group the rows of TaskType by their parent Area.
This appears to be like a grouped bar chart except that all the examples I have seen of these have the same second tier of data repeated for each primary group of data. In my scenario I have many discrete TaskTypes, none of them repeated, but I still want them grouped by their Area. Is this possible at all?
Any suggestions or thoughts very welcome. Thanks.
Currently we have a problem to perform a query (or more precisely to design a mapping) in elasticsearch, which help us to perform a query over a relational problem, that we didn't get solved with our non-document orientated thinking from sql.
We want to create a many-to-many relation between different Elasticsearch entries. We need this to edit an entry once and keep all using’s updated to this.
To describe the problem, we'll use the following simple data model:
Broadcast Content
------------ ---------
Id Id
Day Title
Contents [] Description
So we have two different types to index, broadcasts and contents.
A broadcast can have many contents and single contents could also be part of different broadcasts (e.g. repetition).
JSON like:
index/broadcasts
{
"Id": "B1",
"Day": "2014-10-15",
"Contents": [
"C1",
"C2"
]
}
{
"Id": "B2",
"Day": "2014-10-16",
"Contents": [
"C1",
"C3"
]
}
index/contents
{
"Id": "C1",
"Title": "Wake up",
"Description": "Morning show with Jeff Bridges"
}
{
"Id": "C2",
"Title": "Have a break!",
"Description": "Everything about Android"
}
{
"Id": "C3",
"Title": "Late Night Disaster",
"Description": "Comedy show"
}
Now we want to rename the "Late Night Disaster" into something more precisely and keep all references up to date.
How could we approach this? Are there fourther options in ES, like includes in RavenDB?
Nested objects or child-parent relations didn't helped us so far.
What about denormalizing? seems difficult if we come from the SQL mindset, but give you a try, even with millions of documents, LUCENE indexing can help, and renaming will be a batch job.
[
{
"Id": "B1",
"Day": "2014-10-15",
"Contents": [
{
"Title": "Wake up",
"Description": "Morning show with Jeff Bridges"
},
{
"Title": "Have a break!",
"Description": "Everything about Android"
}
]
},
{
"Id": "B2",
"Day": "2014-10-16",
"Contents": [
{
"Title": "Wake up",
"Description": "Morning show with Jeff Bridges"
},
{
"Title": "Late Night Disaster",
"Description": "Comedy show"
}
]
}
]