Override dimple tooltip text only - dimple.js

How do I override the label / value of a tooltip while maintaining all other formatting?
I have tried incorporating the following examples and have been able to override the text, but the formatting always follows the example. I end up with either the sketchy arrow which doesn't fit in my svg or the text is in top right corner.
http://dimplejs.org/advanced_examples_viewer.html?id=advanced_custom_styling
http://dimplejs.org/advanced_examples_viewer.html?id=advanced_bars_sketchy
http://annapawlicka.com/pretty-charts-with-dimple-js/

This is the code I eventually got around to using.
series.getTooltipText = function (e) {
var capitalized_metric = metric.charAt(0).toUpperCase() + metric.substring(1) + "s";
return [
"Date: " + moment(e.x).format("MM/DD/YYYY"),
capitalized_metric + ": " + e.y
];
};

Related

Create Google Script that saves sheet as pdf to specified folder in google drive

So thanks to other members I was able to piece together a script that does what I need except for 1 small hiccup. Rather than saving the single sheet as a pdf in the designated folder, it saves the entire workbook. I've tried multiple variations to get it to save just the sheet I want (named JSA) but it either gives me an error message or continues to download the whole spreadsheet. I'm sure it's something simple I'm missing, but I'm not as versed with Script as I am with writing Macros, so I'm stuck. The first part of the code, downloading it as a PDF works like a charm, it's the last section where I want it to save the PDF to a specified folder that's the issue. Any assistance would be appreciated.
function downloadPdf() {
var ss = SpreadsheetApp.getActive(),
id = ss.getId(),
sht = ss.getActiveSheet(),
shtId = sht.getSheetId(),
url =
'https://docs.google.com/spreadsheets/d/' +
id +
'/export' +
'?format=pdf&gid=' +
shtId
+ '&size=letter' // paper size legal / letter / A4
+ '&portrait=false' // orientation, false for landscape
+ '&scale=2' // 1= Normal 100% / 2= Fit to width / 3= Fit to height / 4= Fit to Page
+ '&fitw=true' // fit to width, false for actual size
+ '&top_margin=0.25' // All four margins must be set!
+ '&bottom_margin=0.25' // All four margins must be set!
+ '&left_margin=0.25' // All four margins must be set!
+ '&right_margin=0.25' // All four margins must be set!
+ '&sheetnames=false&printtitle=false' // hide optional headers and footers
+ '&pagenum=false&gridlines=false' // hide page numbers and gridlines
+ '&fzr=false' // do not repeat row headers (frozen rows) on each page
+ '&horizontal_alignment=CENTER' //LEFT/CENTER/RIGHT
+ '&vertical_alignment=TOP'; //TOP/MIDDLE/
var val = SpreadsheetApp.getActive().getRange('H2').getValues();//custom pdf name here
var val2= Utilities.formatDate(SpreadsheetApp.getActive().getRange("N2").getValue(), ss.getSpreadsheetTimeZone(), "MM/dd/YY");
var val3= " - "
val += val3 += val2 += '.pdf';
//can't download with a different filename directly from server
//download and remove content-disposition header and serve as a dataURI
//Use anchor tag's download attribute to provide a custom filename
var res = UrlFetchApp.fetch(url, {
headers: { Authorization: 'Bearer ' + ScriptApp.getOAuthToken() },
});
SpreadsheetApp.getUi().showModelessDialog(
HtmlService.createHtmlOutput(
'<a target ="_blank" download="' +
val +
'" href = "data:application/pdf;base64,' +
Utilities.base64Encode(res.getContent()) +
'">Click here</a> to download, if download did not start automatically' +
'<script> \
var a = document.querySelector("a"); \
a.addEventListener("click",()=>{setTimeout(google.script.host.close,10)}); \
a.click(); \
</script>'
).setHeight(50),
'Downloading PDF..'
);
const folderName = `Test`;
const fileNamePrefix = val += val3 += val2 += '.pdf';
var JSA = SpreadsheetApp.getActiveSpreadsheet();
var s = JSA.getSheetByName("JSA");
DriveApp.getFoldersByName(folderName)
.next()
.createFile(SpreadsheetApp.getActiveSpreadsheet()
.getBlob()
.getAs(`application/pdf`)
.setName(`${fileNamePrefix}`));
}
I believe your goal is as follows.
You want to create a PDF file, which is downloaded using the first part of your script, in the specific folder on Google Drive.
In this case, how about the following modification? I thought that res might be able to be used.
From:
var JSA = SpreadsheetApp.getActiveSpreadsheet();
var s = JSA.getSheetByName("JSA");
DriveApp.getFoldersByName(folderName)
.next()
.createFile(SpreadsheetApp.getActiveSpreadsheet()
.getBlob()
.getAs(`application/pdf`)
.setName(`${fileNamePrefix}`));
To:
DriveApp.getFoldersByName(folderName)
.next()
.createFile(res.getBlob().setName(`${fileNamePrefix}`));
In this modification, it supposes that sht = ss.getActiveSheet(), is JSA sheet. If the active sheet is not JSA sheet, please modify as follows.
To:
const url2 =
'https://docs.google.com/spreadsheets/d/' +
id +
'/export' +
'?format=pdf&gid=' +
ss.getSheetByName("JSA").getSheetId()
+ '&size=letter' // paper size legal / letter / A4
+ '&portrait=false' // orientation, false for landscape
+ '&scale=2' // 1= Normal 100% / 2= Fit to width / 3= Fit to height / 4= Fit to Page
+ '&fitw=true' // fit to width, false for actual size
+ '&top_margin=0.25' // All four margins must be set!
+ '&bottom_margin=0.25' // All four margins must be set!
+ '&left_margin=0.25' // All four margins must be set!
+ '&right_margin=0.25' // All four margins must be set!
+ '&sheetnames=false&printtitle=false' // hide optional headers and footers
+ '&pagenum=false&gridlines=false' // hide page numbers and gridlines
+ '&fzr=false' // do not repeat row headers (frozen rows) on each page
+ '&horizontal_alignment=CENTER' //LEFT/CENTER/RIGHT
+ '&vertical_alignment=TOP'; //TOP/MIDDLE/
const res2 = UrlFetchApp.fetch(url2, {
headers: { Authorization: 'Bearer ' + ScriptApp.getOAuthToken() },
});
DriveApp.getFoldersByName(folderName)
.next()
.createFile(res2.getBlob().setName(`${fileNamePrefix}`));
Reference:
fetch(url, params)

Photoshop action for changing text number and saving with variable

I have a lot of graphic buttons that I need to make. I have 2 layers
TEXT (This is going to be numbers 1-48 for instance)
White Button image
I'm not sure how to go about writing this action or if I need a script. I need to have the text layer start at 1 and follow this progression.
save file w1.png (this yields a png with a button labeled with a "1"
change text to 2
save file w2.png (this yields a png with a button labeled with a "2"
change text to 3
. . . .
ect. . .all the way to 48. So this would make 48 images automatically. Can this be done with "actions" or do I need to learn scripting?
Save
You'll need a script for this, but it's going to be a rather simple one
function main() {
//this just checks if you have a text layer selected
try {
var textLayer = activeDocument.activeLayer.textItem
} catch (e) {
alert("active layer isn't a text layer");
return
};
var loops = 48,
pngSaveOptions = new PNGSaveOptions(),
outputFolder = Folder.selectDialog('', Folder.desktop); //this will ask for an output folder
for (var i = 0; i < loops; i++) {
var myNum = i + 1;
textLayer.contents = myNum; //this will change layer contents to number only. if you need some text here, write it in quotes like textLayer.contents = "my text" + myNum;
activeDocument.saveAs(new File(outputFolder + "/w" + myNum + ".png"), pngSaveOptions, true, Extension.LOWERCASE);
}
}
app.activeDocument.suspendHistory("temp", "main()");

Google Apps script created file is not PDF

I'm trying to create a PDF file with this code:
var name = "test.pdf";
var url = 'https://docs.google.com/spreadsheets/d/' + newSpreadsheetID + '/export?exportFormat=pdf&format=pdf' +
'&size=A4' +
'&portrait=true' +
'&fitw=true' + // fit to width, false for actual size
'&sheetnames=false&printtitle=false&pagenumbers=false' +
'&gridlines=false' +
'&fzr=false' + // do not repeat frozen rows on each page
'&gid='+SheetID; //the sheet's Id
var pdf = UrlFetchApp.fetch(url);
var pdf = pdf.getBlob().setName(name);
DocsList.createFile(pdf);
This code creates a file but the file contains just plain text, can you guys help me to get it into PDF format?
First off, DocsList was deprecated (https://developers.google.com/apps-script/reference/docs-list/docs-list). So I think we should use DriveApp this time.
I ignored the parameters you used to format the pdf, the script can be simply as -
var sheet = DriveApp.getFileById(spreadsheetId);
DriveApp.createFile(sheet.getAs("application/pdf"));
Please let me know if you want more elaboration. :)
I made a few changes and got your call working. I don't know where the documentation for the export settings are, but some of them don't work such as "gridlines". Also below is a 2 line example of the same thing.
function makePDF(){
var newSpreadsheetID = SpreadsheetApp.getActive().getId()
var SheetID="Sheet1";
var name = "test.pdf";
var url = 'https://docs.google.com/spreadsheets/d/' + newSpreadsheetID + '/export?exportFormat=pdf&format=pdf'; +
'&size=A4' +
'&portrait=true' +
'&fitw=true' + // fit to width, false for actual size
'&sheetnames=false&printtitle=false&pagenumbers=false' +
'&gridlines=false' +
'&fzr=false'; + // do not repeat frozen rows on each page
'&gid='+SheetID; //the sheet's Id
var pdf = UrlFetchApp.fetch(url,{headers: {authentication:"Bearer " + ScriptApp.getOAuthToken()}, muteHttpExceptions:true}).getBlob();
pdf.setName(name);
DriveApp.createFile(pdf);
}
function simplePDFConvert(){
var ss = SpreadsheetApp.openById( spreadSheetId );
DriveApp.createFile(ss.getBlob());
}

is there any more standard way to resume function from jQuery ajax call?

I am trying to write a big project which involves of a lot of code. That's why I want to separate functionalities from different files.
the first file, dataJS, I make an AJAX call to get data from a JSON file.
the second file, showJS I want to display the data obtained from the dataJS file.
When it comes to implementation, I realise that AJAX call takes longer time and even though I include dataJS and showJS in order, showJS will still get a null data
therefore I made a function called continueFromDataJS() in showJS file
and call continueFromDataJS() at the end of the AJAX success function.
I think it's a rather makedo solution. Is there any standard way to do it?
In addition, all intellisense in my Visual Studio is gone. Despite separate files, is there any way to make visual studio get intellisense from the dataJS?
Thank you
sorry, I don't know how to add a follow up question
this is the code
for simplicity I rename some of the files and only take some part out of it. Hope that helps
code in html
code in dataJS.js
var planets = [];
var jsonData = null;
$(function () {
$.getJSON("Scripts/planetData.js", function (data) {
//planets[0] = new planet("uranus", "career", 45, 700, 400, 0.1, 5, 3);
jsonData = data;
for (var i = 0; i < data.planets.length; i++) {
var curPlanet = data.planets[i];
planets[i] = new planet(curPlanet.graphic, i, curPlanet.field, curPlanet.planetInitialAngle, curPlanet.distanceFromStar, curPlanet.planetRadius, curPlanet.planetRevolvingSpeed, curPlanet.planetRotationSpeed, curPlanet.contents.length);
$("#result").append("<p>" + curPlanet.graphic + " " + curPlanet.field + " " + curPlanet.planetInitialAngle + " " + curPlanet.distanceFromStar + " " + curPlanet.planetRadius + " " + curPlanet.planetRevolvingSpeed + " " + curPlanet.planetRotationSpeed + " " + curPlanet.contents.length + "</p>");
}
callDisplayScript(); //**continue from showJS.js file is that the way to do this?**
});
});
// more functions below in dataJS.js
showJS.js
function callDisplayScript() { **// this is the ugly part. What's the proper way to do it?**
$("#display #close").click(function () {
$("#display").fadeOut('slow');
});
$article = $("#display article");
$article.empty();
var data = jsonData.planets[pID].contents; // **this line won't get jsonData if it's out this curly brace.**
for (var i = 0; i < data.length; i++) {
$article.append(data[i].title);
$article.append(data[i].content);
}
$("#display").fadeIn('slow');
};
don't forget to answer my intellisense question. I want in datajs.js automatically hint planets and jsonData declared in datajs.js
is it possible?

prefuse axis title

How does one go about giving a title to the axis in prefuse scatter plot?
At the moment my code reads the data from the file and a range for both x and y axis works in the code. All I need to do now is to add titles/names for the axis. The code I have at the moment shows:
//set up the actions
AxisLayout xaxis = new AxisLayout(group, "GD",
Constants.X_AXIS, VisiblePredicate.TRUE);
AxisLayout yaxis = new AxisLayout(group, POINTS,
Constants.Y_AXIS, VisiblePredicate.TRUE);
//yaxis.setScale(Constants.LOG_SCALE);
yaxis.setRangeModel(receiptsQ.getModel());
receiptsQ.getNumberModel().setValueRange(0,120,0,120);
xaxis.setLayoutBounds(m_dataB);
yaxis.setLayoutBounds(m_dataB);
// sets group,axis,values,bounds
AxisLabelLayout ylabels = new AxisLabelLayout("ylab", yaxis, m_ylabB);
NumberFormat nf= NumberFormat.getInstance();
nf.setMaximumFractionDigits(0);
ylabels.setNumberFormat(nf);
// AxisLabelLayout xlabels = new AxisLabelLayout("goal diff", xaxis, m_xlabB, 15);
AxisLabelLayout xlabels = new AxisLabelLayout("xlab",xaxis,m_xlabB,5);
// vis.putAction("xlabels", xlabels);
vis.putAction("xlabels", xlabels);
You have to do it by hand. I've done this and my code is open source, so you're welcome to take a look at it:
https://github.com/brycecr/msmexplorer/blob/acacia/MSMExplorer/src/edu/stanford/folding/msmexplorer/util/axis/AxisRotateRenderer.java
https://github.com/brycecr/msmexplorer/blob/acacia/MSMExplorer/src/edu/stanford/folding/msmexplorer/util/axis/AxisLabelLabelLayout.java
In the label renderer, all the labels are drawn as a combination of a line and a label. In this class, we just add an additional item to the layout with our graph.
This is not super clean at all...in particular, a line (actually one pixel) is still rendered for the label, but I'm lazy and this suits my needs...I think you could improve this if necessary, but you'd probably need to reach into the axis renderer and make it draw no line for your label items.
Let me know if you have any questions about the operation of this.
#Override
public void run(double frac) {
super.run(frac);
setLabPos(item, length/2.0d + width, bounds);
}
/**
* Set the layout values for an axis label item.
*/
protected void setLabPos(VisualItem item, double xOrY, Rectangle2D b) {
switch (getAxis()) {
case Constants.X_AXIS:
xOrY = super.isAscending() ? xOrY + b.getMinX() : b.getMaxX() - xOrY;
PrefuseLib.updateDouble(item, VisualItem.X, xOrY);
PrefuseLib.updateDouble(item, VisualItem.Y, b.getMaxY() + label.getFont().getSize()/3.0d + gridLab.getFont().getSize());
PrefuseLib.updateDouble(item, VisualItem.X2, xOrY);
PrefuseLib.updateDouble(item, VisualItem.Y2, b.getMaxY() + label.getFont().getSize()/3.0d + gridLab.getFont().getSize());
break;
case Constants.Y_AXIS:
xOrY = super.isAscending() ? b.getMaxY() - xOrY - 1 : xOrY + b.getMinY();
PrefuseLib.updateDouble(item, VisualItem.X, b.getMinX());
PrefuseLib.updateDouble(item, VisualItem.Y, xOrY);
PrefuseLib.updateDouble(item, VisualItem.X2, b.getMinX());
PrefuseLib.updateDouble(item, VisualItem.Y2, xOrY);
}
}
}