Charts do not render unless I reroute to another page and go back to my charts route - angularjs

I am working on dashboard chart. I am using chartjs for my charts and angularjs http.get method to get data from the server to my charts. I checked the console and the data is loaded and working properly, but the charts won't render unless I reroute to another page and then go back to my charts route page.
This is the code:
$scope.tripTotalts = "";
$scope.tripdstatus = "";
$scope.tripddstatus = "";
$scope.tripcstatus = "";
$scope.totalshow = "";
$scope.tripStatus = function() {
$http.get("/api/statusDispatched").success(function(response) {
dispatched = response;
$scope.tripdstatus = response[0];
});
$http.get("/api/statusDelivered").success(function(response) {
delivered = response;
$scope.tripddstatus = response[0];
});
$http.get("/api/totalTripsintheSystem").success(function(response) {
$scope.tripTotalts = response[0];
totalFleetTrips = response[0];
});
$http.get("/api/statusCompleted").success(function(response) {
completed = response;
$scope.tripcstatus = response[0];
});
$scope.totalshow = Math.round(((dispatched+delivered+completed) / totalFleetTrips) * 100)
console.log("CHECKOUT HERE");
console.log(dispatched);
console.log(delivered);
console.log(completed);
var tstatid = $("#tstatusChart");
tstatid.attr('height', 100);
var tripsatusChartInitiate = new Chart(tstatid, {
type: 'pie',
data: {
datasets: [{
data: [dispatched, delivered, completed],
backgroundColor: [
"rgba(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ", 1)",
"rgba(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ", 1)",
"rgba(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ", 1)"
],
borderColor: [
"rgba(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ", 1)",
"rgba(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ", 1)",
"rgba(" + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + "," + Math.floor(Math.random() * 255) + ", 1)"
], borderWidth: 1
}],
labels: ["Dispatched", "Delivered", "Completed"]
},
options: {
tooltips: {
callbacks: {
label: function(tooltipItem, data) {
var allData = data.datasets[tooltipItem.datasetIndex].data;
var tooltipLabel = data.labels[tooltipItem.index];
var tooltipData = allData[tooltipItem.index];
var total = 0;
for (var i in allData) {
total += allData[i];
}
var tooltipPercentage = Math.round((tooltipData / total) * 100);
return '[Day: ' +tooltipLabel + '] Data: ' + tooltipData + ' [Percentage: ' + tooltipPercentage + '%]';
}
}
},
animation: {
duration: 0
}
}
});
}

Related

display image in reactjs using local path

"display image in reactjs using local path"
I can only give a url to fetch the image,either from online or hosting the local image using localhost.How to fetch the image using local path destination instead of the urls.
if (myData["status"] == "Active") {
finalTable += " Status: ";
}
this is the part where i have to give the local path to fetch the image.
Please help,
Thank you.
const designHtml = (evt, mySource) => {
document.getElementById('popup-content').style.display = 'none';
let viewResolution = /** #type {number} */ (myView.getResolution());
let url = mySource.getFeatureInfoUrl(
evt.coordinate,
viewResolution,
'EPSG:3857',
{ 'INFO_FORMAT': 'application/json', }
);
if (url) {
fetch(url)
.then((response) => response.text())
.then((json) => {
var myJSON = json;
const myObj = JSON.parse(myJSON);
// console.log(myObj);
if (myObj.features.length != 0) {
document.getElementById('popup-content').style.display = 'block';
// var1.style.display ='block'
var myData = myObj.features[0].properties;
myOverlay.setPosition(evt.coordinate);
console.log("myData", myData);
var finalTable = "<tr class='row'>Table Row";
finalTable += "<table id='myTable' style='border: 1px solid red'>" + "<tbody>" +
"<tr><td> Cell Name: </td>" + "<td>" + myData["cell_name"] + "</td> </tr>" +
"<tr><td> Muncipal: </td>" + "<td>" + myData["municipio"] + "</td> </tr>" +
"<tr><td> Node Name: </td>" + "<td>" + myData["node_name"] + "</td> </tr>" +
"<tr><td> Provincia: </td>" + "<td>" + myData["provincia"] + "</td> </tr>" +
"<tr><td> Status: </td>" + "<td>" + myData["status"] + "</td> </tr>"
if (myData["status"] == "Active") {
finalTable += "<tr><td> Status:</td><td> <img src ='http://localhost/download.jpg' style ='height: 50px; width:50px'/> </td> </tr>";
}
else {
console.log(myData["status"]);
finalTable += "<tr><td> <img src ='https://scx1.b-cdn.net/csz/news/800/2017/theoreticala.jpg' style ='height: 50px; width:50px'/> </td></tr>";
//finalTable += "<tr><td> <img src=" + 'data:image/png;base64,' + inactiveImageURL + " /></td></tr>";
}
finalTable += "</tbody> </table> </tr>";
document.getElementById('popup-content').innerHTML += finalTable;
myOverlay.setPosition(evt.coordinate);
}
else {
document.getElementById('popup-content').style.display = 'none';
}
});
}
}
In reactJS if you want to load local image then you have to use require() like below
<img src={require('../assets/images/image.png')} style ='height: 50px; width:50px' />

React—catch scroll wheel, but ignore scrollbar

I'm trying to create a scroll-in-viewport-height-increments function and I'm realizing that I only want it to apply to the mousewheel.
Suggestions on how to do this?
Extra credit if you can tell me why my handleScroll function repeats over and over after a single scroll action.
FIDDLE:
componentDidMount() {
window.addEventListener('scroll', this.handleScroll)
}
componentWillUnmount() {
window.removeEventListener('scroll', this.handleScroll)
}
handleScroll(e) {
var didScroll;
var delta = 71;
clearTimeout($.data(this, 'scrollTimer'));
$.data(this, 'scrollTimer', setTimeout(() => {
didScroll = true;
if (didScroll) {
var vh = $(window).height();
hasScrolled(vh);
didScroll = false;
}
}, 40));
function hasScrolled(vh) {
var st = $('body').scrollTop();
var scrolldown = st + vh;
var scrollup = st - vh;
if (Math.abs(lastScrollTop - st) <= delta)
return;
if (st > lastScrollTop && st > 70) {
console.log('scrolltop: ' + st + ', viewport height: ' + vh + ', scrolltop DOWN: ' + scrolldown);
$('body').animate({
scrollTop: scrolldown
}, 300, 'swing');
} else {
console.log('scrolltop: ' + st + ', viewport height: ' + vh + ', scrolltop UP: ' + scrollup);
$('body').animate({
scrollTop: scrollup
}, 300, 'swing');
}
lastScrollTop = st;
}
}

How to have smart-table parse content as HTML / conditional formatting

I know that I can format a cell to parse content as a link in ng-repeat:
<a ng-href="{{::domainname}}/{{::row.sector}}/{{::row.cname}}/ipo-{{::row.tickerbb}}.html">{{::row.cname}}</a>
Here is the fiddle.
How do I make it dynamic, so that if row.tickerbb is null - show a different URL?
I tried to do it in the controller, looping through the data:
var i = 0;
$.each(data, function () {
if (data[i].tickerbb != null) {
data[i].cname = '<a title="' + data[i].cname + '"' + ' ng-href="' + domainname + '/' + data[i].sector + '/' + data[i].shortcname + '/ipo-' + data[i].tickerbb + '.html">' + data[i].cname + '</a>';
}
else {
data[i].cname = '<a title="' + data[i].cname + '" href="Holdings">' + data[i].cname + '</a>';
}
i += 1;
})
But the results show up as raw html tags:
How do I do conditional formatting of the smart-table cell? Or is there a way to sanitize cells in smart-tables?
Resolved it by constructing my link in the controller:
var i = 0;
$.each(data, function () {
data[i].weight = (data[i].weight * 100).toFixed(2) + '%';
if (data[i].shortcname != null) {
var cname = data[i].cname;
var sector = data[i].sector;
var shortcname = data[i].shortcname;
var tic = data[i].tickerbb;
var url = '<a title="' + cname + '" href="' + $scope.domainname + '/' + sector + '/' + shortcname + '/ipo-' + tic + '.html">' + cname + '</a>';
data[i].cname = url;
}
else
{
data[i].cname = '<a title="' + data[i].cname + '" href="Holdings">' + data[i].cname + '</a>';
}
i += 1;
})
And then sanitizing it inside ng-repeat:
<td ng-bind-html="row.cname"></td>

Openseadragon - Custom Tiles, there is navigator do not showing the image

i am using OpenSeaDragon, there is Customtiles to showup the images, i can not see the the image exactly for the navigation... please check the issue for the screenshot : http://screencast.com/t/BeP6nyA6M
The code is here :
<script type="text/javascript">
var viewer = OpenSeadragon({
id: "example-custom-tilesource",
//debugMode: true,
navigatorSizeRatio: 0.25,
wrapHorizontal: true,
showNavigator: true,
tileSources: {
height: 512 * 256,
width: 512 * 256,
tileSize: 256,
minLevel: 8,
getTileUrl: function (level, x, y) {
console.log("URL::->" + "http://s3.amazonaws.com/com.modestmaps.bluemarble/" + (level - 8) + "-r" + y + "-c" + x + ".jpg")
return "http://s3.amazonaws.com/com.modestmaps.bluemarble/" +
(level - 8) + "-r" + y + "-c" + x + ".jpg";
}
}
});
</script>
This issue is discussed in https://github.com/openseadragon/openseadragon/issues/325. It's a bug in OpenSeadragon, but you can fix it by removing the minLevel and adjusting getTileUrl so it works for all levels.

getClass for actionColumn only in a few rows

I'm using the code below, to set the css class for an action column.
But even if the result is null, some elements are inserted by extjs.
getClass: function(v, meta, data) {
if (data.myDate < new Date())
return null;
else
return 'insert';
}
Generated html for return null:
<img alt="" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="
class="x-action-col-icon x-action-col-1 null">
The major problem is that cursor is changed to a hand pointer when moving this "blank" space.
There is a way to not generate elements when no icon is to be shown?
I don't see any way to do it without extending action column. IMO easiest way is to provide custom renderer function. Example:
Ext.define('Ext.grid.column.MyAction', {
extend: 'Ext.grid.column.Action',
constructor: function(config) {
var me = this,
cfg = Ext.apply({}, config),
items = cfg.items || [me],
l = items.length,
i,
item,
cls;
me.callParent(arguments);
me.renderer = function(v, meta) {
v = Ext.isFunction(cfg.renderer) ? cfg.renderer.apply(this, arguments)||'' : '';
meta.tdCls += ' ' + Ext.baseCSSPrefix + 'action-col-cell';
for (i = 0; i < l; i++) {
item = items[i];
item.disable = Ext.Function.bind(me.disableAction, me, [i]);
item.enable = Ext.Function.bind(me.enableAction, me, [i]);
cls = (Ext.isFunction(item.getClass) ? item.getClass.apply(item.scope||me.scope||me, arguments) : (me.iconCls || ''));
if (cls !== null) {
v += '<img alt="' + (item.altText || me.altText) + '" src="' + (item.icon || Ext.BLANK_IMAGE_URL) +
'" class="' + Ext.baseCSSPrefix + 'action-col-icon ' + Ext.baseCSSPrefix + 'action-col-' + String(i) + ' ' + (item.disabled ? Ext.baseCSSPrefix + 'item-disabled' : ' ') + (item.iconCls || '') +
' ' + cls + '"' +
((item.tooltip) ? ' data-qtip="' + item.tooltip + '"' : '') + ' />';
}
}
return v;
};
}
});

Resources