How to modify the label of Category Field in amCharts - angularjs

I am using amCharts in my AngularJS application and I am looking for a way to rename the label of the category field. Following is my code:
var configChart = function () {
employeeChart = new AmCharts.AmSerialChart();
employeeChart.categoryField = "empId";
var yAxis = new AmCharts.ValueAxis();
yAxis.position = "left";
employeeChart.addValueAxis(yAxis);
mcfBarGraph = new AmCharts.AmGraph();
mcfBarGraph.valueField = "employeeRating";
mcfBarGraph.type = "column";
mcfBarGraph.fillAlphas = 1;
mcfBarGraph.lineColor = "#f0ab00";
mcfBarGraph.valueAxis = yAxis;
employeeChart.addGraph(empBarGraph);
employeeChart.write('employee');
}
In the above coode if you observe the categoryField is empId so on the x-axis it shows employee Id's, I want to make it "dept-empId". For example if the department number is 1, on the x-axis it show display 1-1,1-2 etc. The department Id is not in the data provider but is one of the scope variables in my controller. Could you let me know how I could achieve this.

You can define a labelFunction in your chart object's categoryAxis to get the formatting you want.
var categoryAxis = employeeChart.categoryAxis;
categoryAxis.labelFunction = function(valueText) {
return dept + '-' + valueText;
};
Here's a fiddle that uses your setup with some dummy data to illustrate this: https://jsfiddle.net/by7grqjm/2/

Related

How do you use multiple scripts in the same spreadsheet?

I have a spreadsheet that tracks legal cases from start to finish. In that spreadsheet I used a script to create dependent dropdown menus on multiple rows (I'll share the script at the end). The main dropdown menu tells me what Department the case is in. The Departments are Transcription; Doctor; Scheduling; Records; QA; and Billing.
I also have a script that is supposed to moves an entire row of data to a separate tab labeled Billing when the department dropdown menu is set to Billing. I had this script working before I made the dependent dropdown menus and was just using data validation to create my dropdown menu.
Both of these scripts work separately but when I try to use them together the dependent dropdown menus quit working and when the department is set to Billing that row disappears like its supposed to except it doesn't show up on the Billing tab like its supposed to. I have no idea where it goes.
Can someone please tell me how to get both scripts to work at the same time? And, why the row of data disappears when the department is set to Billing but doesn't go to the Billing tab?
Dependent Dropdown Menu Script
var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Database");
var wsOptions = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("options");
var options = wsOptions.getRange(2,1,wsOptions.getLastRow()-1,2).getValues();
function myFunction() {
var list = ["a","b","c","f"];
var cell = ws.getRange("J2");
applyValidationToCell(list,cell);
}
function onEdit(event){
var activeCell = event.range;
var value = activeCell.getValue();
var row = activeCell.getRow();
var column = activeCell.getColumn();
var wsName = activeCell.getSheet().getName();
if(wsName == "Database" && column === 5 && row > 1){
if(value === ""){
ws.getRange(row,10).clearContent();
ws.getRange(row,10).clearValidations();
} else{
ws.getRange(row,10).clearContent();
var filteredOptions = options.filter(function(options){ return options[0] === value });
var listToApply = filteredOptions.map(function(options){ return options[1] });
Logger.log(listToApply);
var cell = ws.getRange(row,10);
applyValidationToCell(listToApply,cell);
}
}
}
function applyValidationToCell(list,cell){
var rule = SpreadsheetApp
.newDataValidation()
.requireValueInList(list)
.setAllowInvalid(false)
.build();
cell.setDataValidation(rule);
}
Billing Script
var ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Database");
var wsOptions = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("options");
var options = wsOptions.getRange(2, 1,wsOptions.getLastRow()-1,2).getValues();
function myFunction() {
var list = ["a","b","g"];
var cell = ws.getRange("K2");
applyValidationToCell(list,cell);
}
function onEdit(e){
var activeCell = e.range;
var val = activeCell.getValue();
var r = activeCell.getRow();
var c = activeCell.getColumn();
var wsName = activeCell.getSheet().getName();
if(wsName == "Database" && c === 5 && r > 1){
var filteredOptions = options.filter(function(o){return o[0] === val});
var listToApply = filteredOptions.map(function(o){ return o[1]});
console.log(listToApply);
var cell = ws.getRange(r, 10);
applyValidationToCell(listToApply,cell);
}
}
function applyValidationToCell(list,cell){
var rule = SpreadsheetApp
.newDataValidation()
.requireValueInList(list)
.setAllowInvalid(false)
.build();
cell.setDataValidation(rule);
}
function onEdit(e) {
const src = e.source.getActiveSheet();
const r = e.range;
if (r.columnStart != 5|| r.rowStart == 2 || e.value == src.getName()) return;
const dest = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(e.value);
src.getRange(r.rowStart,1,1,30).moveTo(dest.getRange(dest.getLastRow()+1,1,1,30));
src.deleteRow(r.rowStart);
}
All functions have to have a unique name and all functions have access to all sheets. onedit triggers are generated on every user edit and it's up to the onEdit function to route edits from the appropriate sheets using information gathered from the event object. Note: Sheet Name = e.range.getSheet().getName() where e is populated by the event object in the function declaration function onEdit(e) {}
The if statement below limits access to edits that occur on Sheet name "Database" and e.range.columnStart == 5 and rows greater than one
if(wsName == "Database" && column === 5 && row > 1){
if(value === ""){
ws.getRange(row,10).clearContent();
ws.getRange(row,10).clearValidations();
} else{
ws.getRange(row,10).clearContent();
var filteredOptions = options.filter(function(options){ return options[0] === value });
var listToApply = filteredOptions.map(function(options){ return options[1] });
Logger.log(listToApply);
var cell = ws.getRange(row,10);
applyValidationToCell(listToApply,cell);
}
}
if you require actions from other sheets then you must add more if statements or other conditional logic to route the appropriate edit traffic to the the correct processing statements.

Aggregate GPM hourly data to daily in GEE

I need to aggregate the sum of 48 half-hourly images per day of a GPM collection getting an imageCollection with the band "precipitationCal" and daily images
I've tried to fill and iterate an empty featureCollection but I get an empty collection without images
var dataset = ee.ImageCollection('NASA/GPM_L3/IMERG_V05')
var startdate = ee.Date.fromYMD(2014,3,1)
var enddate = ee.Date.fromYMD(2014,4,1)
var precipitation = dataset.filter(ee.Filter.date(startdate,enddate)).select('precipitationCal')
print(precipitation)
var difdate = enddate.difference(startdate, 'day')
// Time lapse
var lapse = ee.List.sequence(0, difdate.subtract(1))
var startdate = ee.Date('2014-01-01')
var listdates = lapse.map(function(day){
return startdate.advance(day, 'day')
})
var pts = ee.FeatureCollection(ee.List([]))
var newft = ee.FeatureCollection(listdates.iterate(function(img, ft) {
// Cast
ft = ee.FeatureCollection(ft)
var day = ee.Date(img)
// Filter the collection in one day
var day_collection = precipitation.filterDate(day, day.advance(1, 'day'))
// Get the sum of all 24 images into one Image
var sum = ee.Image(day_collection.sum())
// Return the FeatureCollection with the new properties set
return sum
}, listdates))
Please have a try about my package pkg_trend. aggregate_prob function in it, works just like aggregate in R language.
var imgcol_all = ee.ImageCollection('NASA/GPM_L3/IMERG_V06');
function add_date(img){
var date = ee.Date(img.get('system:time_start'));
var date_daily = date.format('YYYY-MM-dd');
return img.set('date_daily', date_daily);
}
var startdate = ee.Date.fromYMD(2014,3,1);
var enddate = ee.Date.fromYMD(2014,4,1);
var imgcol = imgcol_all
.filter(ee.Filter.date(startdate,enddate)).select('precipitationCal')
.map(add_date);
// imgcol = pkg_trend.imgcol_addSeasonProb(imgcol);
print(imgcol.limit(3), imgcol.size());
var pkgs = require('users/kongdd/pkgs:pkgs.js');
var imgcol_daily = pkgs.aggregate_prop(imgcol, "date_daily", 'sum');
print(imgcol_daily);
Map.addLayer(imgcol_daily, {}, 'precp daily');
The GEE link is https://code.earthengine.google.com/3d8c7e68e0a7a16554ff8081880bfdad
According to GEE GPM page, This product is a half-hour precipitation rate. So, to get daily sum with the code above you should divide every image in collection by 2.

How to find an element by text and use isPresent() for a non angular application using protractor?

I have an iframe inside an angularjs application. I am switching to the iframe using switchTo().
I need to get the table first which has the value I'm looking for. I need to get the Yield total from within the table. I need to find the yieldtotal inside the table using cssContainingText() beacuse the attributes for everything inside the table are the same. The yield total may or may not be present. I used yieldTotal.isPresent() but it throws an error saying "window.angular is undefined. It may be because it is not an angular application"
I cannot use browser.driver.findElement because I cannot find elementbytext that way.
function verifyGrossInvoiceTotal(){
browser.ignoreSynchronization = true;
browser.driver.switchTo().frame('viewDocumentInFrame');
var ProductTable = $('table.invoice-details'));
var sum = 0;
var YieldTotal = ProductTable .element(by.cssContainingText('td', 'Yield Total')).element(by.xpath('..'));
**YieldTotal.isPresent()**.then(function (isPresent){
if(isPresent){
var totalAmount = YieldTotal .$$('td').get(3);
totalAmount.getText().then(function (text) {
text = parseFloat(text.replace(/[^0-9.]/g, '')).toFixed(2);
sum = parseFloat(sum) + parseFloat(text);
});
}
});
});
I think this is because td is not directly under ProductTable. Can you try something like below? Basically 'table.invoice-details td' CSS means, find any td anywhere under table.invoice-details
function verifyGrossInvoiceTotal(){
browser.ignoreSynchronization = true;
browser.driver.switchTo().frame('viewDocumentInFrame');
var sum = 0;
var YieldTotal = element(by.cssContainingText('table.invoice-details td', 'Yield Total'));
YieldTotal.isPresent().then(function (isPresent){
if(isPresent){
var totalAmount = YieldTotal .$$('td').get(3);
totalAmount.getText().then(function (text) {
text = parseFloat(text.replace(/[^0-9.]/g, '')).toFixed(2);
sum = parseFloat(sum) + parseFloat(text);
});
}
});
});

How to loop range of cells and set value in adjacent column

I'm learning Google Apps Scripts for use with Google Spreadsheets.
I have a list of URLs in one column and I want to write a script to get the title element from each URL and write it in the adjacent cell. I have accomplished this for one specific cell as per the following script:
function getTitles() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("url_list");
var range = sheet.getRange("G3");
var url = range.getValue();
var response = UrlFetchApp.fetch(url);
var doc = Xml.parse(response.getContentText(),true);
var title = doc.html.head.title.getText();
var output = sheet.getRange("H3").setValue(title);
Logger.log(title);
return title;
}
This gets the URL in G3, parses it, pulls the element and writes the output in H3.
Now that I have this basic building block I want to loop the entire G column and write the output to the adjacent cell but I'm stuck. Can anyone point me in the right direction?
May look something like this:
function getTitles() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("url_list");
var urls = sheet.getRange("G3:G").getValues();
var titleList = [], newValues = [],
response, doc, title;
for (var row = 0, var len = urls.length; row < len; row++) {
if (urls[row] != '') {
response = UrlFetchApp.fetch(urls[row]);
doc = Xml.parse(response.getContentText(),true);
title = doc.html.head.title.getText();
newValues.push([title]);
titleList.push(title);
Logger.log(title);
} else newValues.push([]);
}
Logger.log('newValues ' + newValues);
Logger.log('titleList ' + titleList);
// SET NEW COLUMN VALUES ALL AT ONCE!
sheet.getRange("H3").offset(0, 0, newValues.length).setValues(newValues);
return titleList;
}

how to auto select a grid record in extjs by using id?

I want to load a grid by highlighting a specific row by sending id attribute in extjs. I cannot choose the record for now. How can i do it? thanks....
I tried some codes which are commented in the code are. you can see below.
var GrideAktar = function (bilgim) {
arr = bilgim.split(",");
bilgi = arr[0];
secilecek_id = arr[1];
harita.hide();
izgaralar.hide();
chartlar.hide();
izgara_yp_is_emirleri.hide();
izgaralar.show();
izgaralar.setHeight(merkez.getHeight());
fileStore_yon.loadById(bilgi);
tree.treeRefresh();
cuIzgaraKay = null;
cuAgacNode = bilgi;
cuAgacSeciliNode = NodeParser(bilgi);
cuAgacSeciliSehir = SehirParser(bilgi)
fileGrid_yon.setHeight(merkez.getHeight());
//fileGrid_yon.getSelectionModel().selectFirstRow();
//fileGrid_yon.getSelectionModel().valueOf(id);
//fileGrid_yon.getSelectionModel().selectRow(1);
// var idx = fileGrid_yon.getStore().indexOfId(secilek_id);
//var rowEl = fileGrid_yon.getView().getRow(idx);
//rowEl.scrollIntoView(fileGrid_yon.getGridEl(),false);
Ext.select(secilecek_id);
raporAlanListesiWindow.hide();
//fileGrid_yon.getSelectionModel().selectRow( this.getStore().indexOfId(id) ); //raporSecenekleriForm.hide();
}
Use:
grid.getSelectionModel().select(store.getById(id));
Which will select the record in store by id in grid.
This looks like a race condition issue. I'm guessing that your code creates a grid that loads from a remote source using ajax or something. Try imbedding the row selection code in the 'load' event of the store:
var GrideAktar = function (bilgim) {
arr = bilgim.split(",");
bilgi = arr[0];
secilecek_id = arr[1];
harita.hide();
izgaralar.hide();
chartlar.hide();
izgara_yp_is_emirleri.hide();
izgaralar.show();
izgaralar.setHeight(merkez.getHeight());
fileStore_yon.on("load", function(){
fileGrid_yon.getSelectionModel().select(fileStore_yon.getById(id));
});
fileStore_yon.loadById(bilgi);
tree.treeRefresh();
cuIzgaraKay = null;
cuAgacNode = bilgi;
cuAgacSeciliNode = NodeParser(bilgi);
cuAgacSeciliSehir = SehirParser(bilgi)
fileGrid_yon.setHeight(merkez.getHeight());
//fileGrid_yon.getSelectionModel().selectFirstRow();
//fileGrid_yon.getSelectionModel().valueOf(id);
//fileGrid_yon.getSelectionModel().selectRow(1);
// var idx = fileGrid_yon.getStore().indexOfId(secilek_id);
//var rowEl = fileGrid_yon.getView().getRow(idx);
//rowEl.scrollIntoView(fileGrid_yon.getGridEl(),false);
Ext.select(secilecek_id);
raporAlanListesiWindow.hide();
//fileGrid_yon.getSelectionModel().selectRow( this.getStore().indexOfId(id) ); //raporSecenekleriForm.hide();
}
var index = gridPanel.store.find('fieldName', fieldValue);
gridPanel.getSelectionModel().select(gridPanel.store.getAt(index));

Resources