SVG Map and show branches - javascript

I have a SVG Iran map with province and I want to show branches in every provinces
when I click on every province show 2 column data include name of branches and branches information.
we have some branches in some cities, for example in Tehran we have 5 branches and in another city only one branches, in this js code only show information from one branch!
in below code
const ardabil = new MapItem('ardabil', 'استان اردبیل', 'branches name', 'branches info')
but I can't set information for three or four branches names and branches informations
for example when I click on Tehran province, we will see:
in first col: name of branch 1
in second col: information of branch 1
although I want to show when click on Tehran province
row:
col 1: name of branch 1
col 2: info of branch 1
row
col 1: name of branch 2
col 2: info of branch 2
row
col 1: name of branch 3
col 2: info of branch 3
in some provinces we have 10 branches and in some provinces we have 1 branch
in some provinces we have not any branches
you can see my html,js code:
codepen
regards

Related

how to get specific rows at the top after performing sorting in tabulator javascript?

I am trying to get the rows of a table at the top after performing sorting using a tabulator. Is there any inbuilt functionality in the tabulator to achieve this?
Example:
actual table:
Sno Animal City
1 Dog Boston
2 Cat Chicago
3 Rat Texas
4 Eagle Colorado
Return table:
I need to get Cat at the Rat after sorting based on Animal
Sno Animal City
3 Rat Texas
2 Cat Chicago
1 Dog Boston
4 Eagle Colorado
You have two options to achieve this. You could either use a custom sorter function that ensures they are moved to the top of the table:
{title:"Name", field:"name", sorter:function(a, b, aRow, bRow, column, dir, sorterParams){
//a, b - the two values being compared
//aRow, bRow - the row components for the values being compared (useful if you need to access additional fields in the row data for the sort)
//column - the column component for the column being sorted
//dir - the direction of the sort ("asc" or "desc")
//sorterParams - sorterParams object from column definition array
// logic to normally sort rows an ensure row is on the top.
return a - b;
},
}
Details of how to build a custom sorter can be found in the Sorting Documentation
or you could use a combination of the dataSorted callback and the moveRow
var table = new Tabulator("#example-table", {
dataSorted:function(sorters, rows){
//sorters - array of the sorters currently applied
//rows - array of row components in their new order
var rowID = 2 the id for the row you want to move
table.moveRow(2, table.getRows()[0], true); //move the row with an id of 2 and insert it at the top of the table
},
});
Details on how to move rows can be found in the {Movable Rows Documentation](http://tabulator.info/docs/4.8/move#example-table-movable-rows)

C3.js: plot categorical time series

I am trying to plot 6 superposed time series created by 3 sensors on 2 machines:
Sensor 1:
Time serie 1 (first machine)
Time serie 2 (second machine)
Sensor 2:
Time serie 3 (first machine)
Time serie 4 (second machine)
Sensor 3:
Time serie 5 (first machine)
Time serie 6 (second machine)
I found that c3.js is a perfect fit for my need here.
The only (big) problem is that c3.js plot only one label by chart like here:
As one can see, data1 (blue) correspond to one serie and data1 (orange) correspond to one serie, the same thing for data3 (green)
What I need :
I need the sensors to be my labels => 3 labels and 2 time series by label.
Is there a way to do it ?

Can I have a ranking from my data value into a tooltip with Leaflet?

I am making a Choropleth Map consisting of 799 regions, colored by score value, so I was wondering if I could add ranking of each region dynamically into a tooltip.
For example : "This region : #1 of #799" etc...
Part of my data which are in a csv :
region | score
--------------
a | 0.5
b | 1.2
c | 3.7
d | 1
e | 2.3
There is probably no out-of-the-box solution. But this is quite straight forward.
You would need to perform a "preprocessing" step in order to determine the ranking, then you could add this data into your regions popup for example.
Fill an array with your regions data.
Sort the array using a compare function that uses your score.
Fill the regions layer popup with the index (+1) of the region within the array, of the length of the array.

How to associate multiple sets of data to each other and sort in javascript

I have 2 tables with 2 sets of data
score - individual name - team name
score 1 name 1 team 1
score 2 name 2 team 1
score 3 name 3 team 1
score - individual name - team name
score 1 name 1 team 2
score 2 name 2 team 2
score 3 name 3 team 2
Each (other than team name, which is only one text input) is a text input where I will input a value.
Lets say the possible score is a value from 1 - 100 and I want to list the players in order from lowest score to highest score in a table on the click of a button. I also want to associate the players name and there team with their score in the list. I know how to set the score in an array using document.getElementsByClassName() and list from least to greatest. What I do not know how to make the players name and team stay with that particular score, even if the score changes and I hit the button again. I would appreciate javascript only, no Jquery unless it is the only way. Thanks for the help!

Sum quantities for list of items in shopping cart using Javascript

I'm trying to write a small piece of Javascript that will sort through a list of items in a shopping cart and determine whether the quantities for each brand sum to a multiple of 12.
An example of the shopping cart would be:
- Brand 1 - Oranges ---------- Qty: 10
- Brand 2 - Oranges ---------- Qty: 4
- Brand 1 - Oranges ---------- Qty: 2
- Brand 3 - Oranges ---------- Qty: 6
- Brand 2 - Oranges ---------- Qty: 20
The totals are therefore: Brand 1 = 12, Brand 2 = 24, Brand 3 = 6.
If the total of Brand 1, Brand 2 or Brand 3 is not a multiple of 12 (eg. Brand 3 above), I want the Javascript function to produce an error.
I think the best way to solve this is through an array and somehow splitting it based on brand then summing the totals but I'm not sure how to go about doing it.
Any help would be greatly appreciated.
You need two loops for that, the first one is to sum up all the qty's for each brand, the 2nd loop is to check if all sums are a multiple of 12.
You can find an example here: http://jsfiddle.net/5QGWG/

Categories