Is there a specific name for this kind of charts ? What JavaScript Charting Library has it ?
Look up treemaps / treemapping. This is how Wikipedia describes them:
"In information visualization and computing, treemapping is a method for displaying hierarchical data by using nested rectangles. […]
Treemaps display hierarchical (tree-structured) data as a set of
nested rectangles. Each branch of the tree is given a rectangle, which
is then tiled with smaller rectangles representing sub-branches. A
leaf node's rectangle has an area proportional to a specified
dimension of the data."
One notable tool which utilizes this technique is WinDirStat. Their website also refers to this kind of visualization as a treemap.
Given this term, you should be able to easily find a JavaScript library that can produce them by simply performing a web search. (I cannot recommend any of the following, since I haven't used them, but the linked Google search finds jsTreemap, Plotly.js, Google Charts, and a few others, on the very first result page.)
If you're curious about the algorithm(s) behind these diagrams, these papers might be of interest:
Brian Johnson, Ben Shneiderman (1991): Treemaps: a space-filling approach to the visualization of hierarchical information structures.
Mark Bruls, Kees Huizing, Jarke van Wijk (1999): Squarified Treemaps.
It's called a treemap, and ZingChart is a JavaScript charting library that has it. It's a useful way to chart hierarchical data. It also allows for user interaction since the user can further drilldown into the treemap. Check out the below demo.
var myConfig = {
"graphset":[
{
"type":"treemap",
"plotarea":{
"margin":"0 0 30 0"
},
"tooltip":{
},
"options":{
},
"series":[
{
"text":"North America",
"children":[
{
"text":"United States",
"children":[
{
"text":"Texas",
"value":21
},
{
"text":"California",
"value":53
},
{
"text":"Ohio",
"value":12
},
{
"text":"New York",
"value":46
},
{
"text":"Michigan",
"value":39
},
{
"text":"Alabama",
"value":25
}
]
},
{
"text":"Canada",
"value":113
},
{
"text":"Mexico",
"value":78
}
]
},
{
"text":"Europe",
"children":[
{
"text":"France",
"value":42
},
{
"text":"Spain",
"value":28
},
{
"text":"Switzerland",
"value":13
},
{
"text":"Germany",
"value":56
},
{
"text":"Cyprus",
"value":7
}
]
},
{
"text":"Africa",
"children":[
{
"text":"Egypt",
"value":22
},
{
"text":"Congo",
"value":38
},
{
"text":"Lesotho",
"value":9
}
]
},
{
"text":"Asia",
"children":[
{
"text":"India",
"value":92
},
{
"text":"China",
"value":68
},
{
"text":"Mongolia",
"value":25
}
]
},
{
"text":"South America",
"children":[
{
"text":"Brazil",
"value":42
},
{
"text":"Argentina",
"value":28
},
{
"text":"Peru",
"value":15
},
{
"text":"Uruguay",
"value":33
}
]
},
{
"text":"Australia (continent)",
"children":[
{
"text":"Australia (country)",
"value":121
},
{
"text":"New Zealand",
"value":24
}
]
}
]
}
]
};
zingchart.render({
id : 'myChart',
data : myConfig,
height: 400,
width: 600
});
<head>
<script src= "https://cdn.zingchart.com/zingchart.min.js"></script>
<script>zingchart.MODULESDIR = "https://cdn.zingchart.com/modules/";
ZC.LICENSE = ["569d52cefae586f634c54f86dc99e6a9","ee6b7db5b51705a13dc2339db3edaf6d"];</script>
</head>
<body>
<div id='myChart'></div>
</body>
For more information on treemaps, read this blog post: https://blog.zingchart.com/2015/03/10/treemaps-charting/
Disclaimer: I'm on the ZingChart team. Let me know if you have more questions. Thanks!
Related
I am currently migrating our application using an old version of chart-js but at the moment I am a bit lost.
NB : The old project was made with vuejs 2 and now we are using nuxt3 rc11
By reading the documentation on the migration, many things have changed and I have trouble finding my way around:
https://www.chartjs.org/docs/latest/getting-started/v3-migration.html
Here is what the parameters I send to chart-js look like
{
"type":"doughnut",
"data":{
"labels":[
"",
"",
"",
""
],
"datasets":[
{
"data":[
16,
0,
0,
1
],
"backgroundColor":[
"#00CBA1",
"#FFBF00",
"#FF406C",
"#4C49AF"
],
"borderWidth":"transparent"
}
]
},
"plugins":[
],
"options":{
"hover":{
"mode":"index",
"axis":"y"
},
"legend":{
"display":false
},
"scales":{
"x":{
"gridLines":{
"display":false
},
"ticks":{
"padding":10,
"display":false
}
},
"y":{
"ticks":{
"beginAtZero":true,
"padding":20,
"display":false
},
"gridLines":{
"drawBorder":false,
"color":"#E3E3E3",
"zeroLineColor":"#E3E3E3",
"display":false
}
}
},
"tooltip":{
"enabled":false
},
"maintainAspectRatio":true,
"responsive":true,
"tooltips":{
},
"layout":{
"padding":{
"top":10,
"right":10
}
},
"cutoutPercentage":60
}
}
I don't know what is wrong with this actualy because my canvas display empty cells like this
I thank you in advance for your clarification
Colleagues, good afternoon!
I'm struggling with some issue. I am using MongoDB 4.4.4. My assignment looks like this:
There is a set of elements methods[].subcategories[].actions[]. Please note that all objects are arrays and they may be absent. Elements of the actions[] array consists of the _id and title fields.
It is necessary to find the actual value of recordId by the field actions.title of the element and write it to the element of the actions array.
List of current values:
0af4cd2e-78cb-109b-8178-d5a7ba0e0012, Inspection
0af4cd2e-78cb-109b-8178-d5a7ba130014, Screening
0af4cd2e-78cb-109b-8178-d5a7ba170016, Poll
0af4cd2e-78cb-109b-8178-d5a7ba1b0018, Getting written explanations
0af4cd2e-78cb-109b-8178-d5a7ba1e001a, Request for documents
0af4cd2e-78cb-109b-8178-d5a7ba21001c, Sampling (samples)
0af4cd2e-78cb-109b-8178-d5a7ba23001e, Instrumental examination
0af4cd2e-78cb-109b-8178-d5a7ba260020, Test
0af4cd2e-78cb-109b-8178-d5a7ba2b0022, Expertise
0af4cd2e-78cb-109b-8178-d5a7ba2d0024, Experiment
3b7205c1-8282-4b63-8121-b82aacd7ca67, Request for documents that, in accordance with the mandatory requirements, must be located at the location (carrying out activities) of the controlled person (its branches, representative offices, separate structural divisions) or the object of control
I wrote the following code:
db.getSiblingDB("ervk_core").getCollection("supervision1").updateMany(
{},
{
"$set": {
"methods.subcategories.actions.$[elem1]._id": "0af4cd2e-78cb-109b-8178-d5a7ba0e0012",
"methods.subcategories.actions.$[elem2]._id": "0af4cd2e-78cb-109b-8178-d5a7ba0e0014",
"methods.subcategories.actions.$[elem3]._id": "0af4cd2e-78cb-109b-8178-d5a7ba0e0016",
"methods.subcategories.actions.$[elem4]._id": "0af4cd2e-78cb-109b-8178-d5a7ba0e0018",
"methods.subcategories.actions.$[elem5]._id": "0af4cd2e-78cb-109b-8178-d5a7ba0e001a",
"methods.subcategories.actions.$[elem6]._id": "0af4cd2e-78cb-109b-8178-d5a7ba0e001c",
"methods.subcategories.actions.$[elem7]._id": "0af4cd2e-78cb-109b-8178-d5a7ba0e001e",
"methods.subcategories.actions.$[elem8]._id": "0af4cd2e-78cb-109b-8178-d5a7ba260020",
"methods.subcategories.actions.$[elem9]._id": "0af4cd2e-78cb-109b-8178-d5a7ba260022",
"methods.subcategories.actions.$[elem10]._id": "0af4cd2e-78cb-109b-8178-d5a7ba260024",
"methods.subcategories.actions.$[elem11]._id": "3b7205c1-8282-4b63-8121-b82aacd7ca67",
}
},
{
"arrayFilters": [
{
"elem1.title": "Inspection",
},
{
"elem2.title": "Search",
},
{
"elem3.title": "Poll",
},
{
"elem4.title": "Receipt of Written Explanations",
},
{
"elem5.title": "Retrieval of Documents",
},
{
"elem6.title": "Sampling (samples)",
},
{
"elem7.title": "Instrumental examination",
},
{
"elem8.title": "Trial",
},
{
"elem9.title": "Expertise",
},
{
"elem10.title": "Experiment",
},
{
"elem11.title": "Request for documents that, in accordance with the mandatory requirements, must be located at the location (carrying out activities) of the controlled person (its branches, representative offices, separate structural divisions) or the object of control",
}
]
}
);
However, it gives the error "The path 'methods.subcategories.actions' must exist in the document in order to apply array updates.". I understand why it occurs - due to the absence of the actions[] array. But how can I account for the fact that methods[].subcategories[].actions[] arrays may be missing. And did I write the code correctly, otherwise I'm already a little confused. Thanks a lot in advance!
What you can do is add array filters checks to the method and subcategory object to see the nested array exists, this will solve your issue as Mongo will not continue checking the nested conditions in case they don't exist. Here's how you'd do it:
db.collection.updateMany(
{
"methods.subcategories.actions": {
$exists: true
}
},
{
"$set": {
"methods.$[methodElem].subcategories.$[subCatElem].actions.$[elem1]._id": "0af4cd2e-78cb-109b-8178-d5a7ba0e0012",
"methods.$[methodElem].subcategories.$[subCatElem].actions.$[elem2]._id": "0af4cd2e-78cb-109b-8178-d5a7ba0e0014",
"methods.$[methodElem].subcategories.$[subCatElem].actions.$[elem3]._id": "0af4cd2e-78cb-109b-8178-d5a7ba0e0016",
"methods.$[methodElem].subcategories.$[subCatElem].actions.$[elem4]._id": "0af4cd2e-78cb-109b-8178-d5a7ba0e0018",
"methods.$[methodElem].subcategories.$[subCatElem].actions.$[elem5]._id": "0af4cd2e-78cb-109b-8178-d5a7ba0e001a",
"methods.$[methodElem].subcategories.$[subCatElem].actions.$[elem6]._id": "0af4cd2e-78cb-109b-8178-d5a7ba0e001c",
"methods.$[methodElem].subcategories.$[subCatElem].actions.$[elem7]._id": "0af4cd2e-78cb-109b-8178-d5a7ba0e001e",
"methods.$[methodElem].subcategories.$[subCatElem].actions.$[elem8]._id": "0af4cd2e-78cb-109b-8178-d5a7ba260020",
"methods.$[methodElem].subcategories.$[subCatElem].actions.$[elem9]._id": "0af4cd2e-78cb-109b-8178-d5a7ba260022",
"methods.$[methodElem].subcategories.$[subCatElem].actions.$[elem10]._id": "0af4cd2e-78cb-109b-8178-d5a7ba260024",
"methods.$[methodElem].subcategories.$[subCatElem].actions.$[elem11]._id": "3b7205c1-8282-4b63-8121-b82aacd7ca67"
}
},
{
"arrayFilters": [
{
"methodElem.subcategories": {
$exists: true
}
},
{
"subCatElem.actions": {
$exists: true
}
},
{
"elem1.title": "Inspection"
},
{
"elem2.title": "Search"
},
{
"elem3.title": "Poll"
},
{
"elem4.title": "Receipt of Written Explanations"
},
{
"elem5.title": "Retrieval of Documents"
},
{
"elem6.title": "Sampling (samples)"
},
{
"elem7.title": "Instrumental examination"
},
{
"elem8.title": "Trial"
},
{
"elem9.title": "Expertise"
},
{
"elem10.title": "Experiment"
},
{
"elem11.title": "Request for documents that, in accordance with the mandatory requirements, must be located at the location (carrying out activities) of the controlled person (its branches, representative offices, separate structural divisions) or the object of control"
}
]
})
Mongo Playground
I also changed the updates query to just ignore documents with no nested actions, this is just to save time.
I am following the examples located on the following page:
http://developer.echonest.com/docs/v4/genre.html#artists
I'd like to offset the results from a search for artists by genre. The example they provide on the page listed "results" and "start". I assume "start" is the offset. The example query they provide is:
http://developer.echonest.com/api/v4/genre/artists?api_key=JEXNQ223JXCCQEINO&format=json&results=5&start=0&bucket=hotttnesss&name=jazz
But I get any error stating the "start" is an invalid parameter. Has anyone been able to use the "start" parameter with success?
This looks like a bug in their example. If you read the documentation, "start" and "results" are not valid for the genre/artists endpoint. Changing the example to remove these to parameters works.
Calling:
http://developer.echonest.com/api/v4/genre/artists?api_key=*********&format=json&bucket=hotttnesss&name=jazz
(replace the *** with your Key)
Yields:
{
"response":{
"status":{
"version":"4.2",
"code":0,
"message":"Success"
},
"artists":[
{
"name":"John Coltrane",
"hotttnesss":0.588225,
"id":"ARIOZCU1187FB3A3DC"
},
{
"name":"Thelonious Monk",
"hotttnesss":0.649332,
"id":"AR9PLH11187FB58A87"
},
{
"name":"Miles Davis",
"hotttnesss":0.697302,
"id":"AR7RTGF1187FB38793"
},
{
"name":"Miles Davis Quintet",
"hotttnesss":0.489603,
"id":"AR5DF1C1187FB4E94C"
},
{
"name":"Cannonball Adderley",
"hotttnesss":0.560071,
"id":"ARQ5TM41187FB3E97D"
},
{
"name":"Wayne Shorter",
"hotttnesss":0.548165,
"id":"ARO3CKW1187B9905A8"
},
{
"name":"Wynton Marsalis",
"hotttnesss":0.566708,
"id":"ARV3VEI1187B9AD5C9"
},
{
"name":"Sonny Rollins",
"hotttnesss":0.577764,
"id":"AR6Q4T91187B995616"
},
{
"name":"The Dave Brubeck Quartet",
"hotttnesss":0.570099,
"id":"ARLKR161187FB50694"
},
{
"name":"Kenny Burrell",
"hotttnesss":0.543388,
"id":"ARQYH461187FB3E975"
},
{
"name":"Stan Getz",
"hotttnesss":0.559735,
"id":"ARMGQLA1187B9AEBF8"
},
{
"name":"Dizzy Gillespie",
"hotttnesss":0.561122,
"id":"ARXA17J1187FB3B507"
},
{
"name":"Yusef Lateef",
"hotttnesss":0.513261,
"id":"ART95BW1187FB3AF79"
},
{
"name":"Bill Evans",
"hotttnesss":0.581819,
"id":"ARTLL9E1187FB4436F"
},
{
"name":"Freddie Hubbard",
"hotttnesss":0.524227,
"id":"ARU1K2U1187FB48529"
}
]
}
}
As far as I can tell, there isn't a way to page through the artists associated with a genre...
In my application I have a list of tiles representing each project in a portfolio. This is the main list view for the app and all projects are fetched from the collection without any sorting or ordering.
When I have an optional slug parameter specified in my route (for the category assigned to the project) I want to be able to display the projects within the UI that match that category first, and then display the other ones that don't match the category.
For reference, I have included the code for the route below:
/**
* Project list view (all projects) with optional
* filter parameter for showing projects only by
* their category name.
*/
this.route('list', {
path: '/:_category_slug?',
template: 'template_main',
action: function() {
if(this.ready()) {
this.render();
}
},
waitOn: function() {
return [
Meteor.subscribe('projects'),
Meteor.subscribe('formations'),
Meteor.subscribe('categories')
];
},
data: function() {
if(this.params._category_slug) {
/**
* Building up the query given the category slug and the language
*/
var query = {};
query['slug.' + App.language] = this.params._category_slug;
/**
* Grab the category given the query, so we can get its 'id'
*/
var category = App.models.categories.findOne(query);
/**
* This is the query I need to work on so that I can achieve what I want
*/
return App.models.projects.find({}).fetch();
}
else {
return App.models.projects.find({}).fetch();
}
},
yieldTemplates: {
'components_header': {to: 'header'},
'views_list': {to: 'content'},
'components_footer': {to: 'footer'}
}
});
For reference, I have also included a sample of the data for three projects that is relevant to this question.
{
"id": 10,
"slug": {
"en": "sample-english-slug",
},
"title": {
"en": "Sample English Title",
},
"description": {
"en": "A good description.",
},
"category_ids": [
{
"id": 5
},
{
"id": 6
}
],
},
{
"id": 12,
"slug": {
"en": "another-sample-slug",
},
"title": {
"en": "Another sample title",
},
"description": {
"en": "Sample description three",
},
"category_ids": [
{
"id": 1
},
{
"id": 4
}
],
},
{
"id": 11,
"slug": {
"en": "another-sample-slug",
},
"title": {
"en": "A sample title",
},
"description": {
"en": "Sample description",
},
"category_ids": [
{
"id": 2
},
{
"id": 5
}
],
}
So what I would want to do is make sure that given a category with an ID of 5, I want those first two projects to be the first two that appear.
Can this be done in meteor, without having to resort to writing extra logic in JS? One approach I did have once was to update each project from within the Client side collection (something I no longer do) and set a few extra attributes, then sort after that.
When dealing with syncing client and server collections, this is not really feasible.
From the mongodb docs:
Use the dot notation to match by specific fields in an embedded document. Equality matches for specific fields in an embedded document will select documents in the collection where the embedded document contains the specified fields with the specified values. The embedded document can contain additional fields.
I don't know if you can do it with a single query, but you can concat two complementary queries that use dot notation.
var selected = App.models.projects.find({'category_ids.id': category._id}).fetch();
var other = App.models.projects.find({'category_ids.id': {$ne: category._id}}).fetch();
return selected.concat(other);
I am currently evaluating the efficiency of different databases for a use case. In Mongodb, would like to store around 1 million objects with the following structure. Each object will have between 5 and 10 objects in the foo array.
{
name:"my name",
foos:[
{
foo:"...",
bar:"..."
},
{
foo:"...",
bar:"..."
},
{
foo:"...",
bar:"..."
}
]
}
I often need to search for objects which where the foos collection contains an object with a specific property, e.g.:
// mongo collection
[
{
name:'my name',
foos:[
{
foo:'one_foo',
bar:'a_bar'
},
{
foo:'two_foo',
bar:'b_bar'
}
]
},
{
name:'another name',
foos:[
{
foo:'another foo',
bar:'a_bar'
},
{
foo:'just another foo',
bar:'c_bar'
}
]
}
]
// search (pseudo code)
{ foos: {$elemMatch: {bar: 'c_bar'}} }
// returns
{
name:'another name',
foos:[
{
foo:'another foo',
bar:'a_bar'
},
{
foo:'just another foo',
bar:'c_bar'
}
]
}
Can this efficiently be done with mongo and how should the indexes be set?
I don't want you to evaluate performance for me, just an idea how mongo performs for my use case or how optimization could look like.
MongoDB has documentation explaining how to create indexes on embedded documents, through dot notation:
Dot Notation (Reaching into Objects)
> db.blogposts.findOne()
{ title : "My First Post", author: "Jane",
comments : [{ by: "Abe", text: "First" },
{ by : "Ada", text : "Good post" } ]
}
> db.blogposts.find( { "comments.by" : "Ada" } )
> db.blogposts.ensureIndex( { "comments.by" : 1 } );
As for the performance characteristic... just test it with your dataset.