How to make legend's line wider in a react-vis XYPlot - clojurescript

The DiscreteColorLegends of an XYPlot are a little narrow for me:
Specially when I want to make them other than solid:
I browsed the documentation, and even the source code; I think that the length is determined in line 59 of this file: https://github.com/uber/react-vis/blob/master/packages/react-vis/src/legends/discrete-color-legend-item.js :
d="M 0, 1 L 14, 1"
Can I change it in my own local source code?

I found a 'semi' solution. I'm not proud of it, but maybe can help others. I did two things:
After compiling (with clojure -A:fig:min), I changed the string cited above using sed (28 doubled the size of the legend):
sed -i 's/"M 0, 1 L 14, 1"/"M 0, 1 L 28, 1"/' dev-main.js
Then, in the file legends.css, I changed this:
.rv-discrete-color-legend-item__title {
margin-left: 10px;
}
into this:
.rv-discrete-color-legend-item__title {
margin-left: 20px;
}
Now, al least, it looks better:

Related

word() function returns the different results depending on gnuplot version 5.06 and 5.22

I recently updated gnuplot latest version, 5.22 and my code didn't work properly. I debugged and found the reasons.
str="1 2"
print word(str,3)+0
In the previous version, 5.06 or older, the print shows 0 values without error.
But the latest version got error, "Non-numeric string found where a numeric expression was expected"
Without +0, both results are the same, blank (no output), but the latest version treats it as string I think.
My code has lots of routine related to word(), so how do I resolve this problem in the new version?
Your code seems to make two potentially dangerous assumptions:
that requesting the third element from a list of two elements returns an empty string, rather than causing an error, and
that converting that empty string to a number will yield 0.
Assumption 1 seems to still hold in gnuplot 5.2.2, but assumption 2 does not. If you really wanted that then you could create a wrapper
f(x) = (x eq "" ? 0 : x)
and use f(word(str,3)) instead of word(str,3). However, there might be a better way to deal with non-existing elements.
Use words to check the index:
w2num(list, i) = (i > 0 && i <= words(list)) ? word(list, i)+0 : 0
Example:
w2num(list, i) = (i > 0 && i <= words(list)) ? word(list, i)+0 : 0
l = "10 20"
do for [i=-1:3] { print w2num(l, i) }
prints
0
0
10
20
0

How do I format a new line in a SASS (Syntactically Awesome Stylesheets) file? [duplicate]

I love Sass's indented syntax (as opposed to SCSS, which is whitespace agnostic and uses brackets and semicolons). I think it's much cleaner.
There's one issue I have with it. If I have a really long line, there's no way to split it into multiple lines (obeying the 80 character limit, for example)
Take this example of a really long mixin declaration, first written in SCSS.
#mixin col($cols, $mleft: 0, $mright: 0, $include-margin: false, $border: 0,
$pleft: 0, $pright: 0, $include-padding: true, $extra: 0,
$clear: false, $lead: true, $container: false) {
color: red;
display: block;
}
I'm able to split up one long declaration in to multiple lines. With the indented syntax, I don't think there's a way. I have to put the declaration on one line, which is way less readable.
#mixin col($cols, $mleft: 0, $mright: 0, $include-margin: false, $border: 0, $pleft: 0, $pright: 0, $include-padding: true, $extra: 0, $clear: false, $lead: true, $container: false)
color: red
display: block
Is there some way I don't know of? :(
Multiline is not supported by sass. Reading the doc, there is one exception, when it comes to multiple css selectors like in this example:
.users #userTab,
.posts #postTab
width: 100px
height: 30px
Read the doc here: http://sass-lang.com/docs/yardoc/file.INDENTED_SYNTAX.html#multiline_selectors
So, sadly: There is no possibility to get multi-line support for an argument list in sass.
First: do not create mixins with so many arguments. Divide it to many small mixins or insert some similar arguments as arrays (Sass have data maps for it).
Second: you can use temporary variables just for readability of your large code.
For example:
=mixin($argument)
body::before
content: $argument
$v1: 'foo-'
$v2: 'bar-'
$v3: 'baz.'
$var: $v1+$v2+$v3
+mixin($var)
This will get you mixin with all your $v# strings joined to one $var.
body::before {
content: 'foo-bar-baz';
}
If someone knows better way to join many strings into one in indented Sass syntax, I will be happy to know. Because I write complex gradients and inline generated SVG with this.

Adding the results of multiple functions

Using python 3.3
Stumbled upon another problem with my program. Its the same solar program. Again i decided to add more functionality. Its basically ad-hoc. I'm adding things as i go along. I realize it can be made more efficient but once i decide its done, I'll post the whole coding up.
Anyway, i need to add the results from multiple functions. Here's a part of my coding:
def janCalc():
for a in angle(0,360,10): #angle of orientation
for d in days(1,32,1.0006630137): #day number of year
for smodule in equation(): #equation() function not shown in this coding
total_jan+=smodule #total_jan is already defined elsewhere
avg_jan=total_jan/(60*(1.0006630137*31))
ratio_jan=avg_jan/5.67
calcJan=(ratio_jan*4.79)
yield calcJan
total_jan=0 #necessary to reset total to 0 for next angle interval
def febCalc():
for a in angle(0,360,10):
for d in days ((1.0006630137*31),61,1.0006630137):
for smodule in equation():
total_feb+=smodule
avg_feb=total_feb/(60*(1.0006630137*28))
ratio_feb=avg_feb/6.56
calcFeb=(ratio_feb*4.96)
yield calcFeb
total_feb=0
#etc..............
Is there anyway to add the yield of each function?
for e.g: calcJan+calcFeb+.....
I would like to get the total results under each angle interval and then dividing by 12 to get the average value per interval. Like so:-
0 degrees---->total/12
10 deg ---->total/12
20 deg ---->total/12
30 deg ---->total/12
........
360 deg ---->total/12
If you need more info, let me know.
ADDENDUM
The solution was essentially solved by #jonrsharpe. But i encountered a bit of a problem.
Traceback (most recent call last):
File "C:\Users\User\Documents\Python\Solar program final.py", line 247, in <module>
output=[sum(vals)/12 for vals in zip(*(gen() for gen in months))]
File "C:\Users\User\Documents\Python\Solar program final.py", line 247, in <listcomp>
output=[sum(vals)/12 for vals in zip(*(gen() for gen in months))]
File "C:\Users\User\Documents\Python\Solar program final.py", line 103, in janCalc
for smodule in equation():
File "C:\Users\User\Documents\Python\Solar program final.py", line 63, in equation
d=math.asin(math.sin(math.radians(23.45))*math.sin(math.radians((360/365.242)*(d-81))))
NameError: global name 'd' is not defined
I've isolated it to:
for d in days ((1.0006630137*31),61,1.0006630137):
for smodule in equation():
It turns out i can't reference a function from inside a function? I'm not too sure. So even my original coding did not work. I assumed it was working because previously i had not defined each month as a function. I should have tested it out first.
Do you know how to get around this?
A simple example to demonstrate how to combine multiple generators:
>>> def gen1():
for x in range(5):
yield x
>>> def gen2():
for x in range(5, 10):
yield x
>>> [sum(vals) for vals in zip(*(gen() for gen in (gen1, gen2)))]
[5, 7, 9, 11, 13]
Or, written out long hand:
output = list(gen1())
for index, value in enumerate(gen2()):
output[index] += value
You can modify either version to include a division, too, so your case would look something like:
months = [janCalc, fabCalc, ...]
output = [sum(vals) / 12 for vals i zip(*(gen() for gen in months))]

Character confidence for Tesseract 3.02 using config file

How would I get the % confidence per character detected?
By searching around I found that you should set save_blob_choices to T.
So I added that to as a line in the hocr config file in tessdata/configs and called tesseract with it.
This is all I'm getting in the generated html file:
<span class='ocr_line' id='line_1' title="bbox 0 0 50 17"><span class='ocrx_word' id='word_1' title="bbox 3 2 45 15"><strong>31,835</strong></span>
As you can see there isn't any confidence annotations not even per word.
I don't have visual studio so I'm not able to make any code changes. But I'm also open to answers describing code changes as well as how I would compile the code without VS.
Here is the sample code of getting confidence of each word.
You can even replace RIL_WORD with RIL_SYMBOL to get confidence of each character.
mTess.Recognize(0);
tesseract::ResultIterator* ri = mTess.GetIterator();
if(ri != 0)
{
do
{
const char* word = ri->GetUTF8Text(tesseract::RIL_WORD);
if(word != 0 )
{
float conf = ri->Confidence(tesseract::RIL_WORD);
printf(" word:%s, confidence: %f", word, conf );
}
delete[] word;
} while((ri->Next(tesseract::RIL_WORD)));
delete ri;
}
You will have to write a program to do this. Take a look at the ResultIterator API example at Tesseract site. For your case, be sure to set save_blob_choices variable and iterate at RIL_SYMBOL level.

Is there an HTML safe truncate method in Rails?

I have a string of HTML in Rails. I'd like to truncate the string after a certain number of characters not including the HTML markup. Also, if the split happens to fall in the middle of an opening and closing tag, I'd like to close the open tag/s. For example;
html = "123<a href='#'>456</a>7890"
truncate_markup(html, :length => 5) --> "123<a href='#'>45</a>"
the regular truncate function works fine, just pass :escape => false as an option to keep the HTML intact. eg:
truncate(#html_text, :length => 230, :omission => "" , :escape => false)
RubyOnRails.org
*Edit I didn't read the question very carefully (or at all TBH), so this answer does not solve this question... It IS the answer I happened to be looking for though, so hopefully it helps 1 or 2 people :)
There are two completely different solutions both with the same name: truncate_html
https://github.com/ianwhite/truncate_html : This is a gem and uses an html parser (nokogiri)
https://github.com/hgmnz/truncate_html : This is a file you put in your helpers directory. It uses regular expressions and has no dependencies.
You should solve this problem with CSS rather than Ruby. You are doing something that affects the DOM layout, and there is no way to programmatically devise a solution that will work consistently.
Let's say you get your HTML parser gem working, and you find a lowest common denominator character count that will work most of the time.
What happens if you change font sizes, or your site layout? You'll have to recalculate the character count again.
Or let's say your html has something like this in it: <p><br /></p><br /> That is zero characters, however it would cause a big chunk of blank text to be inserted. It could even be a <blockquote> or <code> tag with too much padding or margin to throw your layout totally out of whack.
Or the inverse, let's say you have this 3 ≅ λ (3 ≅ λ) That is 26 characters long, but for display purposes it is only 5.
The point being that character count tells you nothing about how something will render in the browser. Not to mention the fact HTML parsers are hefty pieces of code that can at times be unreliable.
Here is some good CSS to deal with this. The :after pseudo class will add a white fade to the last line of content. Very nice transition.
body { font-size: 16px;}
p {font-size: 1em; line-height: 1.2em}
/* Maximum height math is:
line-height * #oflines - 0.4
the 0.4 offset is to make the cutoff look nicer */
.lines-3{height: 3.2em;}
.lines-6{height: 6.8em;}
.truncate {overflow: hidden; position:relative}
.truncate:after{
content:"";
height: 1em;
display: block;
width: 100%;
position:absolute;
background-color:white;
opacity: 0.8;
bottom: -0.3em
}
You can add as many .lines-x classes as you see fit. I used em but px is just as good.
Then apply this to your element: <div class="truncate lines-3">....lots of stuff.. </div>
and the fiddle: http://jsfiddle.net/ke87h/
You could use the truncate_html plugin for this. It uses nokogiri and htmlentities gems and does exactly what the plugin name suggests.
We had this need in zendone.com. The problem was that the existing solutions were very slow when truncating long HTML documents (MBs) into shorter ones (KBs). I ended up coding a library based in Nokogiri called truncato. The library includes some benchmarks comparing its performance with other libs.
This will help you without any extra effort
raw your_string.truncate(200)
your_tagged_string.truncate(60).html_safe
You can use
truncate(html.gsub(/(<[^>]+>)/, ''), 5)
We can do that with the help of simple_format http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#method-i-simple_format
html = "123<a href='#'>456</a>7890"
simle_format(truncate_markup(html, :length => 5))
=> "123 456 7890"
You can use the truncate method in combination with sanitize.
truncate(sanitize(html_content), length: 100, separator: '</p>', escape: false)
This will truncate your HTML using the separator but it can produce HTML without closing tags. To fix this we can use the sanitize method again, which will clean the HTML and add the missing tags.
sanitize(truncate(sanitize(html_content), length: 100, separator: '</p>', escape: false))
Solving this problem from the client side:
view:
<script>
$(function() {
$('.post-preview').each(function() {
var tmp_height = $(this).innerHeight();
if ((tmp_height > 100) && (tmp_height < 200)) {
$(this).addClass("preview-small");
}
else if (tmp_height >= 200) {
$(this).addClass("preview-large")
}
else {
//do nothing
}
});
});
</script>
css
.preview-small {
height: 100px;
overflow: hidden;
}
.preview-large {
height: 200px;
overflow: hidden;
}