Filter Folium MarkerCluster by Column from Dataframe - mapping

I want to map a MarkerCluster with a filter by a column (QuadClass). I followed this answer: Filter Folium Map based on marker color
And it works for single markers, but when I try to use MarkerCluster nothing gets added to the map. is there anyway to achieve this?
Qclass = {1: "Verbal Cooperation",
2: "Material Cooperation",
3: "Verbal Conflict",
4: "Material Conflict"}
m = folium.Map(location=[33.8564, 66.0867],
tiles='Stamen Toner',
zoom_start=6)
marker_cluster = MarkerCluster().add_to(m)
features = {}
for row in pd.unique(df1["QuadClass"]):
features[row] = folium.FeatureGroup(name=row)
for index, row in df1.iterrows():
marker = folium.Marker([row['ActionGeo_Lat'], row['ActionGeo_Long']],
popup='QuadClass: '+Qclass[row['QuadClass']]).add_to(marker_cluster)
marker.add_to(features[row['QuadClass']])
for row in pd.unique(df1["QuadClass"]):
features[row].add_to(m)
folium.LayerControl().add_to(m)
m

Found out that folium has this plugin which solves the issue with the MarkerCluster: https://github.com/python-visualization/folium/blob/master/folium/plugins/feature_group_sub_group.py

Related

highlightValue not working in chart with CombinedChartView :: Display marker programmatically is not working :: ChartIssue :: iOS Swift :: DanielGindi

Here is what i am doing!
chart.highlightValue(x: timeStampValue, dataSetIndex: totalCount)
==> In the above line,
timeStampValue is x axis value which i have set while filling up the array.
totalCount is total count of array of data which i am displaying in chart.
What i need to achieve is
When chart screen comes up, i need to display marker by default and for that, i am using "highlightValue" method of chart which is not working.
Please let me know the solution to show marker by default programatically.
NOTE: I am using marker whose UI is custom which is working fine when i tap manually at point in chart:
let marker = CustomMarkerView.viewFromXib()!
marker.chartView = chart
chart.marker = marker
chart.drawMarkers = true
Library used : https://github.com/danielgindi/Charts
Chart Data set :
let data = CombinedChartData()
data.lineData = LineChartData(dataSets:[viewModel.lineChartDataSet, viewModel.emptylineChartDataSet])
data.lineData.highlightEnabled = true
viewModel.lineChartDataSet.highlightColor = AssetsColor.highlightedColor.color
viewModel.lineChartDataSet.drawHorizontalHighlightIndicatorEnabled = false
viewModel.lineChartDataSet.highlightLineDashPhase = 2
viewModel.lineChartDataSet.highlightLineDashLengths = [5, 2.5]
you are using the wrong value for dataSetIndex param
based on your code, the datasets only contains 2 data
data.lineData = LineChartData(dataSets:[viewModel.lineChartDataSet, viewModel.emptylineChartDataSet])
dataSetIndex is not data count, in linechart dataset represent a line that has many data (x,y), so dataSetIndex is more like which line
so your code should be something like this
chart.highlightValue(x: timeStampValue, dataSetIndex: 0)
chart.highlightValue(x: timeStampValue, dataSetIndex: 0, dataIndex: 0)
When i added 1 more parameter which is dataIndex as 0 and it worked.
Here, dataSetIndex is set to 0 because it is CombinedChartView where i have merged 2 data set.

Openpyxl don't move hyperlink location after delete_rows()

I am trying to use openpyxl delete_rows() to delete a row from a spreadsheet. The content of the row is removed fine, and the value from the following rows are moved ahead. However, the hyperlink of the following rows are not adjusted accordingly. This will cause value and hyperlink not consistent.
An example to duplicate this problem
from openpyxl import Workbook, load_workbook
destExcelName = 'd:\Temp\hello.xlsx'
wb = load_workbook(destExcelName)
ws = wb.active
ws['A1'].value = 'Google'
ws['A1'].hyperlink = 'https://www.google.com'
ws['A1'].style = 'Hyperlink'
ws['A2'].value = 'Apple'
ws['A2'].hyperlink = 'https://www.apple.com/'
ws['A2'].style = 'Hyperlink'
ws['A3'].value = 'StackOverflow'
ws['A3'].hyperlink = 'https://stackoverflow.com'
ws['A3'].style = 'Hyperlink'
ws.delete_rows(2)
wb.save(destExcelName)
wb.close()
After delete row 2 (the apple line). StackOverflow line is moved ahead and become the new row 2. However, its hyperlink still remains on A3, and A2 don't have a hyperlink value.
Anything can be done to overcome this limitation?

Cohort table conditional formatting

I'm looking for a way to conditionally format a cohort table in Google Sheets so that the colors will change from red (low values) through yellow (medium values) to green (high values) based on the values in each row. Anyone knows if this is possible?
Also, choosing the "Color scale" option in conditional formatting menu doesn't work because it colors the table based on the values of the full table, not each row individually.
I can use that option only if I apply it to each row individually, but my dataset has thousands of entries so that doesn't work for me.
Example table: https://docs.google.com/spreadsheets/d/1gpLMdgfs10Flt-VTtsc68E3Feju2H8UQhnai-R_9b3k/copy
Thanks in advance you guys are the greatest!
I wrote a simple script in Apps Script to apply the formatting to every row. It achieves the gradient per row that you want.
Example:
function applyColorGradientConditionalFormat(min = '#FF0000', mid = '#FF9900', max = '#00FF00') {
const sheet = SpreadsheetApp.getActiveSheet();
const lastCol = sheet.getLastColumn();
const conditionalFormatRules = sheet.getConditionalFormatRules();
// Build this conditional rule for all rows in sheet
for (let i = 2; i <= sheet.getLastRow(); i++) {
let range = sheet.getRange('R' + i + 'C2:R' + i + 'C' + lastCol);
let rule = SpreadsheetApp.newConditionalFormatRule()
.setRanges([range])
.setGradientMinpoint(min)
.setGradientMidpointWithValue(mid, SpreadsheetApp.InterpolationType.PERCENT, '50')
.setGradientMaxpoint(max)
.build()
conditionalFormatRules.push(rule);
}
// Apply all conditional rules built to the sheet
sheet.setConditionalFormatRules(conditionalFormatRules);
};
// Easy improvements: Create a menu to build all conditional formats manually
// or setup triggers to do it automatically
For your sample sheet this results in the following table:
Useful documentation:
Class ConditionalFormatRuleBuilder
getConditionalFormatRules()
non scripted:
=(B2:M2=MAX($B2:$M2))*($B2:$M2<>"")
=(B2:M2=MIN($B2:$M2))*($B2:$M2<>"")

Google Spreadsheet move row to new sheet based on cell value

I am new at this so still trying to figure how everything works.
I have a sheet that collects responses from a Google Form. Based on the answer to one of those questions I would like the row from that sheet to move to a different sheet document all together (not a sheet in the same document).
I have it set on a time based trigger every minute so as new responses come in it would kick them over to the correct document and then delete the row from the original spreadsheet.
I have been able to get part of the way there. I would like for it to take the row, columns A through E, move those to the correct document, find where the next open row is and place the data in columns A through E on the new document.
Where my issue is coming in at the moment is when the row is moved to the new document. I have formulas saved in columns G - Z on the destination page. It is finding the last row with a formula and placing the row after that (which is at the very bottom of the page). I am pretty sure this has to do with using an array? But I may be wrong. Is there a way to just have that look at the destination page column A-E, find the next blank row, and copy A-E from the original file to the new page?
arr = [],
values = sheetOrg.getDataRange().getValues(),
i = values.length;
while (--i) {
if (value1ToWatch.indexOf(values[i][1]) > -1) {
arr.unshift(values[i])
sheetOrg.deleteRow(i + 1)
sheet1in.getRange(sheet1in.getLastRow()+1, 1, arr.length, arr[0].length).setValues(arr);
};
I have multiple If statements each with some changes to the "valueToWatch" and the "Sheet1in" for different values and destination pages. If that information helps at all.
You can find the last cell in a column with data in it like this:
function findLastValueInColumn() {
var column = "A"; // change to whatever column you want to check
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var lastDataRow = sheet.getDataRange().getLastRow();
for (var currentRow = lastDataRow; currentRow > 0; currentRow--) {
var cellName = column + currentRow;
var cellval = sheet.getRange( cellName ).getValue();
if (cellval != "") {
Logger.log("Last value in Column " + column + " is in cell " + currentRow);
break;
}
}
}
You can then use this function to figure out where to start your new data.

How to remove the marker from the cluster in google map?

I have implemented cluster in google map and I want to update the map with the markers based on the checkbox selection.
I want to remove the marker from the cluster based on the custom property that I have set in the marker.
var clust = new MarkerClusterer(map, markers, {maxZoom: 14});
How can I do this? Please help me.
Thanks in advance.
For each marker to remove:
clust.removeMarker(marker);
For each Marker to add:
clust.addMarker(marker);
You need to set map null for current markercluster and then create new marker array on the basis of property you want then create new markercluster again and set to map.
var clust = new MarkerClusterer(map, markers, {maxZoom: 14});
on update property
clust.setMap(null)
var newclust = new MarkerClusterer(map, newmarkers, {maxZoom: 14});
newclust.setMap(mapobject)

Resources