statgen / locuszoom

A Javascript/d3 embeddable plugin for interactively visualizing statistical genetic data from customizable sources.
https://statgen.github.io/locuszoom/
MIT License
156 stars 29 forks source link

Treat zero as truthy in conditions #101

Closed pjvandehaar closed 7 years ago

pjvandehaar commented 7 years ago

In PheWeb, I'm generating tooltips based on the list of fields defined in my parser, even though each trait might have different fields actually present. So, I make a big template like:

{{#if rsid}}<b>{{rsid}}</b><br>{{/if}}
{{#if pvalue}}pvalue: {{pvalue|scinotation}}{{/if}}
{{#if beta}}beta: {{beta}}{{#if sebeta}} ({{sebeta}}){{/if}}{{/if}}

But this won't show pvalue or beta if they are 0. (I know, pval oughtn't be zero, but I didn't make the data.)

I could just do

LocusZoom.TransformationFunctions.add("truthy_or_0", x => (x || x === 0))

and then replace the above template with

{{#if rsid|truthy_or_0}}<b>{{rsid}}</b><br>{{/if}}
{{#if pvalue|truthy_or_0}}pvalue: {{pvalue|scinotation}}{{/if}}
{{#if beta|truthy_or_0}}beta: {{beta}}{{#if sebeta|truthy_or_0}} ({{sebeta}}){{/if}}{{/if}}

but I suspect that almost all users would prefer to treat 0 as truthy.

pjvandehaar commented 7 years ago

I think the travis setup is broken.