Category labels having brackets([]) are not showing complete label - amcharts4

In am chart, labels having square bracket in it are ignoring the content between [] brackets on category axis . I checked and ensured that they are passed as string instead of array, even I tried to return this as html ,that also did not worked out for me
Now I am expecting the label to be shown completely irrespective of its content when it is string. Can any one suggest some ways to overcome this .Thanks in advance
My code:
am4core.useTheme(am4themes_animated);
var config = {
yAxes: [
{
id: "c1",
type: "CategoryAxis",
dataFields : {
category : "country"
},
renderer : {
minGridDistance : 20,
minWidth : 120,
grid : [{
location : 0
}]
}
}
],
xAxes: [
{
id: "v1",
type: "ValueAxis",
dataFields : {
value : "visits"
},
renderer : {
maxLabelPosition : 0.98
}
}
],
series: [
{
type: "ColumnSeries",
name: "Series Title",
dataFields: {
valueX: "visits",
categoryY: "country"
},
sequencedInterpolation : true,
sequencedInterpolationDelay : 100,
adapter : {
tooltipText : function(val) {
return 'hello' + val // doesn't work?
}
},
columns : [
{
strokeOpacity : 1, // has no effect?
template : {
adapter : {
"fill" : function (fill, target) {
return target.dataItem.index // not quite right
}
}
}
}
]
}
],
cursor : {
type : "XYCursor",
behavior : "zoomY"
},
colors : {
saturation : 0.4 // does not affect colors?
}
};
var chart = am4core.createFromConfig(config, "chartdiv", am4charts.XYChart);
chart.data = [{
"country": "[UAS]STATES",
"visits": 3025
}, {
"country": "China",
"visits": 1882
},{
"country": "Russia",
"visits": 580
}, {
"country": "South Korea",
"visits": 443
}, {
"country": "Canada",
"visits": 441}]

Brackets in amcharts are treated as reference to data.
Basically, it goes like this: whenever amCharts 4 displays a text, it passes it via text processor we call Text formatter. During the process anything contained within curly brackets { ... } is treated as a reference to some data value and is replaced with relative data. Similarly everything that goes within square brackets [ ... ] is treated as text formatting options, and again is not displayed but rather parsed for text styling instructions.
To solve your issue you need to escape brackets, like so:
country: "[[UAS]]STATES",
Take a look in Docs:
https://www.amcharts.com/docs/v4/concepts/formatters/formatting-strings/#Escaping

Related

monogdb full text search, ignore characters

Im implementing a mongodb search.
The search performs a find on field values:
[{
value: "my.string.here"
}, {
value: "my other here"
}{
...
}]
When i enter "my" both entries are found. What have my query to look like to ignore the dots on the first entry? So when i enter "my string" the first element gets returned?
Actually it works only when i enter "my.string" which is not nice.
let limit = Number(req.query.limit || 100);
let skip = Number(req.query.skip || 0);
collection.find({
$or: [{
value: new RegExp(req.body.search, "gi")
}, {
tags: {
$in: req.body.search.split(",").map((val) => {
return new RegExp(val, "gi")
})
}
}]
}).skip(skip).limit(limit).toArray((err, result) => {
if (err) {
res.status(500).json(err);
} else {
res.status(200).json(result);
}
});
EDIT:
A solution could look like this:
let query = {
$or: [{
name: new RegExp(req.body.search, "gi")
}, {
tags: {
$in: req.body.search.split(",").map((val) => {
return new RegExp(val, "gi")
})
}
}, {
name: new RegExp(req.body.search.split(' ').join('.'), "gi")
}, {
name: new RegExp(req.body.search.split(' ').join('_'), "gi")
}, {
name: new RegExp(req.body.search.split(' ').join('-'), "gi")
}]
};
But i find it ugly and not elegant. Is there a better way to do this ?

Adding string pluralization to amCharts tooltip

I'm using an amCharts v4 Pie chart and currently I have this tooltip that appears when hovering on the slices:
series.slices.template.tooltipText = "{category}: {value.percent.formatNumber('#.')}% ({value} hours)
However, I would like to have the "hours" pluralized correctly, i.e. when {value} equals 1, I would like to have the text hour instead of hours.
Is something like this possible?
I've found the Adapters, but I don't think they will be usable here because I'm using a special format with category, percentage and the text.
Adapters are the perfect use case for this. You can look at the dataItem associated with the tooltip and use that logic to determine whether return the pluralized version of your tooltip or use the default one, for example:
pieSeries.slices.template.adapter.add('tooltipText', function(tooltipText, target) {
if (target.dataItem && target.dataItem.value == 1) {
return tooltipText.replace('hours', 'hour')
}
else {
return tooltipText;
}
});
Demo below:
var chart = am4core.create("chartdiv", am4charts.PieChart);
chart.data = [{
"country": "Lithuania",
"hours": 1
}, {
"country": "Czechia",
"hours": 2
}, {
"country": "Ireland",
"hours": 3
}, {
"country": "Germany",
"hours": 1
}, {
"country": "Australia",
"hours": 1
}, {
"country": "Austria",
"hours": 1
}];
var pieSeries = chart.series.push(new am4charts.PieSeries());
pieSeries.dataFields.value = "hours";
pieSeries.dataFields.category = "country";
pieSeries.slices.template.tooltipText = "{category}: {value.percent.numberFormatter('#.')}% ({value} hours)";
pieSeries.slices.template.adapter.add('tooltipText', function(tooltipText, target) {
if (target.dataItem && target.dataItem.value == 1) {
return tooltipText.replace('hours', 'hour')
}
else {
return tooltipText;
}
});
chart.legend = new am4charts.Legend();
#chartdiv {
width: 100%;
height: 400px;
}
<script src="https://www.amcharts.com/lib/4/core.js"></script>
<script src="https://www.amcharts.com/lib/4/charts.js"></script>
<div id="chartdiv"></div>

What are the default expressions of skewness and kurtosis used in Scipy?

Scipy's (to date, version 0.19.1) Statistical Functions module (aka scipy.stats) contains the functions of scipy.stats.skew and scipy.stats.kurtosis to compute skewness and kurtosis of a data set (3rd and 4th statistical moments, respectively). Moreover, scipy.stats.describe calls these functions.
The definitions of skewness and kurtosis may vary; hence, no consensus on them in the literature. Then, which mathematical expressions are used in Scipy to define skewness and kurtosis in the two aforementioned functions with their default settings?
Both scipy.stats.skew and scipy.stats.kurtosis call the function of scipy.stats.moment, which computes the following for the k-th central moment of a data sample:
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML-full"></script> <script type="text/x-mathjax-config"> MathJax.Hub.Config({"HTML-CSS": { preferredFont: "TeX", availableFonts:["STIX","TeX"], linebreaks: { automatic:true }, EqnChunk:(MathJax.Hub.Browser.isMobile ? 10 : 50) }, tex2jax: { inlineMath: [ ["$", "$"], ["\\\\(","\\\\)"] ], displayMath: [ ["$$","$$"], ["\\[", "\\]"] ], processEscapes: true, ignoreClass: "tex2jax_ignore|dno" }, TeX: { noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } }, Macros: { href: "{}" } }, messageStyle: "none" }); </script>
$$m_k = \frac{1}{n} \sum_{i = 1}^n (x_i - \bar{x})^k$$
Accordingly, scipy.stats.skew with default settings (e.g. bias=True) computes:
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML-full"></script> <script type="text/x-mathjax-config"> MathJax.Hub.Config({"HTML-CSS": { preferredFont: "TeX", availableFonts:["STIX","TeX"], linebreaks: { automatic:true }, EqnChunk:(MathJax.Hub.Browser.isMobile ? 10 : 50) }, tex2jax: { inlineMath: [ ["$", "$"], ["\\\\(","\\\\)"] ], displayMath: [ ["$$","$$"], ["\\[", "\\]"] ], processEscapes: true, ignoreClass: "tex2jax_ignore|dno" }, TeX: { noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } }, Macros: { href: "{}" } }, messageStyle: "none" }); </script>
$$ S = \frac{m_3}{(m_2)^{1.5}} $$
scipy.stats.kurtosis with default settings:
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS_HTML-full"></script> <script type="text/x-mathjax-config"> MathJax.Hub.Config({"HTML-CSS": { preferredFont: "TeX", availableFonts:["STIX","TeX"], linebreaks: { automatic:true }, EqnChunk:(MathJax.Hub.Browser.isMobile ? 10 : 50) }, tex2jax: { inlineMath: [ ["$", "$"], ["\\\\(","\\\\)"] ], displayMath: [ ["$$","$$"], ["\\[", "\\]"] ], processEscapes: true, ignoreClass: "tex2jax_ignore|dno" }, TeX: { noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } }, Macros: { href: "{}" } }, messageStyle: "none" }); </script>
$$ K = \frac{m_4}{(m_2)^{2}} $$

Format tooltip content of Google column chart generated via Keen

We use Keen on a site to track view data. This works well but I’m having an issue with how some of the data is presented in the graphs (using v3.0.5 of the JS SDK). On the users dashboard we have a graph showing the last 4 months data (timeframe : this_4_months). I have a query though -
When the user hovers over one of the columns you see detail in a tooltip e.g. "April 1, 2015 12:00:00 AM" - is there any way to format this tooltip into something more user-friendly? e.g. "April 2015"
Keen.ready(function() {
var query = new Keen.Query('count', {
'eventCollection' : 'profile_views',
'timeframe' : 'this_4_months',
'interval' : 'monthly',
'groupBy' : 'view.membership_type',
'filters' : [
{
'property_name' : 'view.user_id',
'operator' : 'eq',
'property_value' : String(user_id)
}
]
});
client.draw(query, document.getElementById(element_id), {
chartType: 'columnchart',
width : graph_width,
height : 250,
colors : ['#abdd99', '#8dc7d9', '#eeeeee'],
colorMapping : {
'pro' : '#abdd99',
'basic' : '#8dc7d9'
},
labelMapping: {
"basic": "BASIC",
"pro": "PRO"
},
title : '',
chartOptions: {
width : '100%',
height : '100%',
isStacked: true,
fontName : 'Helvetica',
fontSize : '11px',
chartArea : {
left : '10px',
top : '0',
width : '90%',
height : '90%'
},
axisTitlesPosition : 'in',
vAxis : {
viewWindowMode : 'pretty',
gridlines : { color : '#eeeeee' },
baselineColor : '#eeeeee',
textPosition : 'in'
},
hAxis : {
viewWindowMode : 'pretty',
gridlines : {
color : '#eeeeee'
},
baselineColor : '#eeeeee',
textPosition : 'none'
},
legend : {
position : 'in'
},
titlePosition : 'none'
}
});
});
Here is a screenshot of how the tooltip appears :
Instead of
var chart = keenIoClient.draw(query, document.getElementById("chart2"), options );
Collect all your data to array manually, so you can add more columns there. Here is example with dates and pageviews:
keenIoClient.run(query, function(err, response){
if (err) {
// there was an error!
}
else {
var arrayData = [];
arrayData.push(['Day','Views']);
response.result.forEach(function (element, index, array) {
var date = new Date(element.timeframe.start);
arrayData.push([date.getDate() + '/' + (date.getMonth() + 1) + '/' + date.getFullYear() , element.value]);
});
var data = google.visualization.arrayToDataTable(arrayData);
var chart = new google.visualization.ColumnChart( document.getElementById('chart2'));
chart.draw(data, options);
}
});
The "options" variable stays the same.
P.S. on the way you can set up the format for your dates.
P.P.S. in my case the Query was:
var query = new Keen.Query("count", {
eventCollection: "views",
interval: "daily",
timeframe: "this_7_days",
});

Sencha touch 2. Text doesn't obey the flex parameter in list item

I have defined this Ext.dataview.component.ListItem which renders some data from store into a list, but I cannot make the first text item to obey the flex rule and it's really annoying. It doesn't obey absolute width either. I have read all the documentation, but cannot figure this out by my self.
Ext.define('MyProgram.view.DataItem', {
extend : 'Ext.dataview.component.ListItem',
xtype : 'basic-dataitem',
requires : [
'Ext.Button',
'Ext.Component',
'Ext.layout.HBox',
'Ext.field.Checkbox'
],
config : {
text : {
flex : 1//This text doesn't take one out of two space in my list item
},
moreText : {
flex : 1//This text takes one out of one space???
},
dataMap :{
getText : {
setHtml : 'text'
},
getMoreText : {
setHtml : 'moreText'
}
},
layout : {
//I want texts to obey hbox layout
type : 'hbox',
align: 'center'
}
}
});
And here is the code for my Ext.dataview.List which uses the previously introduced list item MyProgram.view.DataItem:
Ext.define('MyProgram.view.Main', {
extend : 'Ext.dataview.List',
xtype : 'main',
id: 'MainList',
requires : [
'Ext.TitleBar',
'Ext.dataview.List',
'Ext.data.Store',
'Ext.plugin.PullRefresh',
'Ext.plugin.ListPaging',
'MyProgram.view.DataItem'
],
config : {
store : 'TodoItems',
useSimpleItems : false,
defaultType : 'basic-dataitem',
plugins : [
{
xclass : 'Ext.plugin.PullRefresh',
pullText : 'Pull down to refresh!'//Valid
//pullRefreshText : 'Pull down to refresh!'//Deprecated
},
{
xclass : 'Ext.plugin.ListPaging',
autoPaging : true
}
],
scrollable : {
direction : 'vertical',
directionLock : true
},
items : [
{
docked : 'top',
xtype : 'titlebar',
title : 'List using list items'
}
]
}
});
Looks like I want to disable the default itemTpl, so I can prevent sencha from adding raw htlm before my containers. I set my itemTpl in my list view to '' so it won't use the default '{text}' template for my model which ruins my styling.