How do I use toCSS() in paper.js? - javascript

Paper.js says it has a function toCSS(hex) which returns the color as a CSS string, either in hex or not.
http://paperjs.org/reference/color/#tocss-hex
Does anyone know how to use this I have had no luck and can find no examples.
I am trying to convert a var Color which =hit.item.fillcolor which appears to be a ctor.
If I try to use toCSS I get Color.toCSS is not a function.
The function above toCSS in the documentation - toString() works fine.
Any clues?

I'm not exactly sure what you're asking but here is an issue.
The fill color is item.fillColor, not item.fillcolor, which is undefined.
That's why you get Color.toCSS() is not a function.
toCSS(false) returns this format: "rgb(0,230,191)"
toCSS(true) returns this format: "#00e6bf"

Related

OpenLayers.Control.Scale.template - how does it work and does it work at all?

The OpenLayers2 Doc here
http://dev.openlayers.org/docs/files/OpenLayers/Control/Scale-js.html#OpenLayers.Control.Scale.template
says Openlayers.Control.Scale has a Property called "template".
As far as i understood i tried to set it like:
new OpenLayers.Control.Scale('nodelist',
{ template: 'ca. 1: ${scaleDenom}' }
)
but it seems to have no effect at all.
The actual Scale-Control shown in the resulting div-Element remains defaultish as if it (if its set at all) is overridden.
So what would be the proper way to use Openlayers.Control.Scale.template Property or what is it for?
One close look into the OpenLayers 2.13 library itself revealed that the documentation is somehow malicous because there is no way to set something like a template property using the OpenLayers.Control.Scale constructor.
Though its possible to override the Scale class and use the modified one like an ordinary control.
Sorry for answering my own Question but it sure helps someone out there :)

converting a string to float doesn't work

I got a variable Javascrpit which has a number as a string in this case 0.84. I'm trying to convert it into a float but when I try to it appears a 0 as float instead the 0.84.
I'm using this:
var pot="0.84";
var asd = parseFloat(pot);
console.log(asd);
EDIT:
This is not exactly the example. I recover data from the HTML and it works for other numbers but not for this. It is difficult to explain my problem exactly. It is a lot of code and works for other numbers so don't know exactly.
Your input is not "0.84". If you test with that, you will get the correct answer. Your input has something else inside, like spaces, for example:
"0 .84"
This should be the solution:
parseFloat(pod.replace(/ /g, ""))
I have tried this example on my end and it completely worked. However, you can try to instead input the string value directly into the parse float() function and it should print our your expected value. If you still want to assign the parsefloat() to a variable, then try to either rewrite the code or re-open your IDE because the code should work.
var pot = "0.84"
console.log(parseFloat(pot))
or you can just write it in one line
console.log(parseFloat("0.84"))

Jasper Reports - HTML5 Reports(highcharts) - String Replace for Labels

Hoping someone can help. Trying to do a string replace on the labels for my bar chart. So this is built on jasper studio and is a html5 report.
Trying to add the replace function as a javascript function in the report "Advanced Properties". Previously I have successfully set a function here for xAxis.labels.formatter to append labels,
"function(){return this.value.toString().substring(0,5)}"
I have tried to update this for string replace and came up with the below:
"function(){return this.value.toString().str.replace("Section7","W3Schools")}"
This is not working.I dont have much javascript experience and I have tried different formats of the above but no luck so far, any suggestions would be much appreciated?
Got it working. The replace function, works with the below:
Set property name as:
xAxis.labels.formatter
Use as expression:
true
3.Property Value:
"function(){return this.value.replace(\"Section 7\",\"W3Schools\")}"
Or
<hc:chartProperty name="xAxis.labels.formatter">
<hc:propertyExpression><![CDATA["function(){return this.value.replace(\"Section 7\",\"W3Schools\")}"]]></hc:propertyExpression>
</hc:chartProperty>

How would I return 165 from the attached class

I haven't touched JavaScript in a while and thought since the Olympics are on currently, I could use the opportunity to play around with returning countries with at least 1 medal, etc. I am trying to find out, through Javascript, how many countries at the moment have got at least 1 medal in the Commonwealth Games. I am stuck at a point of getting the value from the class. To get to this point, on the tenplay.com.au website I have gone into the console and done:
var check = document.getElementsByClassName("medal-tally")[0].children[1].children[0];
check.getElementsByClassName("total");
This returns:
<td class=​"total" title=​"Total">​165​</td>
This is probably very very simple, but I have failed so far. I have tried .value, .className, checking if it returns true with == 165 and === "165", I believe these are all valid but I am a bit rusty as you can tell.
Thank you in advance for the help,
Daniel.
document.getElementsByClassName return an array like object. You can use index to fetch its element then You can use innerHTML property
Use
var text = check.getElementsByClassName("total")[0].innerHTML;

Fix JS object replacing/encoding of strings?

I have an object with a value that has spaces in it, and it gets replaced with an encoded string, like:
alldata["test"] will return "Long+name"
or something like
alldata["test"] will return "%BLong+name%B"
when it's set by using
alldata["test"] = "Long name" (or "[Long name]") via a series of code.
Am I missing something? I don't think using $.toEvalJSON is the right way to go because I haven't transformed the object into JSON. I'd rather not do a string.replace either because I'd have to capture every possible type of input that is encoded.
Thank you!
If your question is how to remove the encoding, you could always use
unescape(s)
See Escape and Unescape Functions
The issue is related to the fact that I failed to mention that the object was being assigned the string as a result of a .serialize() command. Hence a urldecode() will work perfectly.

Categories