react-portal loads data then doesn't re-render - reactjs

I have been trying to render ParticleJS as a background to the root div of my create-react-app and I have had success of it loading initially, but when changing routes and then visiting the homepage again, the particlejs is gone. Below is my configuration, please let me know if there is something I am missing.
import React, { Component } from 'react';
import { Portal } from 'react-portal';
import Particles from 'react-particles-js';
class Particle extends Component {
render() {
return (
<Portal node={document && document.getElementById('root')}>
<div id="particles">
<Particles
params={{
particles: {
number: {
value: 20,
density: {
enable: true,
value_area: 800
}
},
color: {
value: "#ffffff"
},
shape: {
type: "circle",
stroke: {
width: 0,
color: "#000000"
},
},
"polygon": {
"nb_sides": 5
},
"image": {
"src": "",
"width": 100,
"height": 100
},
"opacity": {
"value": 0.6,
"random": false,
"anim": {
"enable": false,
"speed": 1,
"opacity_min": 0.5,
"sync": false
}
},
"size": {
"value": 3,
"random": true,
"anim": {
"enable": false,
"speed": 40,
"size_min": 0.1,
"sync": false
}
},
"line_linked": {
"enable": true,
"distance": 150,
"color": "#FFFFFF",
"opacity": 0.6,
"width": 1
},
"move": {
"enable": true,
"speed": 4,
"direction": "none",
"random": false,
"straight": false,
"out_mode": "out",
"bounce": false,
"attract": {
"enable": false,
"rotateX": 600,
"rotateY": 1200
}
},
"interactivity": {
"detect_on": "canvas",
"events": {
"onhover": {
"enable": true,
"mode": "repulse"
},
"onclick": {
"enable": true,
"mode": "push"
},
"resize": true
},
"modes": {
"grab": {
"distance": 400,
"line_linked": {
"opacity": .6
}
},
"bubble": {
"distance": 400,
"size": 40,
"duration": 2,
"opacity": 8,
"speed": 3
},
"repulse": {
"distance": 200,
"duration": 0.4
},
"push": {
"particles_nb": 4
},
"remove": {
"particles_nb": 2
}
}
},
"retina_detect": true
}
}} />
</div>
</Portal>
);
}
}
export default Particle;
And I have this for the following component to render this file
class HomePage extends Component {
componentWillMount() {
window.scrollTo(0,0);
}
render() {
return (
<ScrollAnimation animateIn='fadeIn'>
<Particles/>
</ScrollAnimation>
Is there something I should be doing to re-render this?

Ah.... It was CSS, did not realize the background of particles was being affected.

Related

I want to align x axis labels with its respective bar in bar chart of highcharts. Currently, the labels are one line above the bars

I want to align x axis labels with its respective bar in bar chart of highcharts as it is not aligned as seen in picture.
code -
"chartOptions": {
"xAxis":
{
"type": "category",
"labels": {
"align": "left",
"reserveSpace": true
},
"scrollbar": {
"enabled": true
},
"max": 4,
"min": 0,
"minorTickLength": 0,
"tickLength": 0
} ,
"plotOptions": {
"bar": {
"grouping": false
}
},
"yAxis": [
{
"title": {
"text": "Blocked Orders Volume"
},
"labels": {
"format": "{value}"
}
},
{
"title": {
"text": "Blocked Orders Value"
},
"labels": {
"format": "${value}"
},
"opposite": true
}
],
"colors": [
"#14AFF1",
"#FC7500"
],
"series": [
{
"borderRadius": 0,
"pointWidth": 18
},
{
"type": "spline",
"yAxis": 1
}
],
"tooltip": {
"enabled": true,
"shared": true
},
"legend": {
"enabled": true,
"itemStyle": {
"color": "#666668",
"font-family": "Poppins",
"fontWeight": "normal"
}
}
},
I want x axis labels to line up with bars

Highcharts: Custom area outline for line joining each marker

I'm trying to get a gradient color applied onto outline of an area series and the color depends on colors of both markers at the two ends, which'll be different for each line.
Used, highcharts multicolor_series module, for some reason it only draws and colors outline for 2 lines and doesn't draw/completes the last one. Here's my JSFiddle link: https://jsfiddle.net/pgkk/s29d51zt/872/
Can you please help me solve this, where am I going wrong? Thanks in advance.
"credits": {
"enabled": false
},
"chart": {
// backgroundColor: '#F5F7F7',
"polar": true,
"height": 190,
"width": 290,
"minWidth": 250,
"marginBottom": -25,
"style": {
"fontFamily": [
"WhitneyNarrBook",
"Roboto",
"Arial",
"sans-serif"
],
"fontWeight": 400,
"fontSize": 11,
"letterSpacing": "-0.06px",
"lineHeight": "16px"
}
},
"tooltip": {
"enabled": false
},
"title": {
"text": ""
},
"xAxis": {
"min": 0,
"gridZIndex": 4,
"gridLineColor": "#dce1e6",
"lineColor": "#dce1e6",
"categories": [
"Cat1",
"Cat2",
"Cat3"
],
"tickmarkPlacement": "on",
"lineWidth": 0,
"labels": {
"useHTML": true,
"align": "center",
"style": {
"whiteSpace": "nowrap",
"color": "#26415e",
"fontSize": "12px"
}
}
},
"yAxis": {
"gridLineInterpolation": "polygon",
"gridZIndex": 4,
"gridLineColor": "#dce1e6",
"lineColor": "#dce1e6",
"min": 0,
"max": 100,
"showFirstLabel": false,
"showLastLabel": true,
"tickInterval": 25,
"labels": {
"align": "center",
"y": 5,
"x": 0,
"style": {
"color": "#333333",
"fontSize": "10px"
}
}
},
"plotOptions": {
"series": {
"marker": {
"radius": 2.5
},
"states": {
"hover": {
"enabled": false
},
"inactive": {
"enabled": false
}
}
},
"area": {
"dataLabels": {
"enabled": false
}
}
},
"series": [{
"showInLegend": false,
"data": [
100,
100,
100
],
"color": {
"radialGradient": {
"cx": 0.5,
"cy": 0.7,
"r": 0.5
},
"stops": [
[
0,
"#DFA124"
],
[
0.55,
"#AF9D3F"
],
[
0.75,
"#5A9772"
],
[
1,
"#229595"
]
]
},
"pointPlacement": "on",
"marker": {
"symbol": "circle"
},
"fillOpacity": 0.5,
"type": "area",
"lineColor": "transparent"
},
{
"showInLegend": false,
"data": [{
"y": 33,
"color": "#AF9D3F"
},
{
"y": 65,
"color": "#229595"
},
{
"y": 28,
"color": "#DFA124"
}
],
zIndex: 5,
"pointPlacement": "on",
"type": "area",
//lineWidth: 5,
//lineColor: 'gray',
"color": "transparent",
"marker": {
"symbol": "circle"
}
},
{
"showInLegend": false,
"data": [
[
33,
100
],
[
65,
100
],
[
28,
100
]
],
"pointPlacement": "on",
"type": "arearange",
"fillColor": "white",
"opacity": 1,
"lineColor": "transparent",
"marker": {
"fillColor": "#dce1e6",
"lineColor": "#dce1e6"
}
},
{
type: 'coloredline',
showInLegend: false,
pointPlacement: "on",
data: [{
y: 33,
segmentColor: {
linearGradient: {
x1: 0,
x2: 0,
y1: 0,
y2: 1
},
stops: [
//[0, '#AF9D3F'], // start
[0.5, '#AF9D3F'], // middle
[1, '#229595'] // end
]
}
}, {
y: 65,
segmentColor: {
linearGradient: {
x1: 0,
x2: 0,
y1: 0,
y2: 1
},
stops: [
//[0, '#AF9D3F'], // start
[0.25, '#DFA124'],
[1, '#229595'] // middle
]
}
}, {
y: 28,
"segmentColor": {
"linearGradient": {
"x1": 0,
"x2": 0,
"y1": 0,
"y2": 1
},
"stops": [
[
0.5,
"#229595"
],
[
1,
"#DFA124"
]
]
}
},
]
}
]
For each outline you can add separate line series and with corresponding gradient and disabled marker.
Try fiddle link
{
"pointPlacement": "on",
"showInLegend": false,
data: [
[33],
[65],
[null]
],
type: 'line',
marker: {
enabled: false
},
color: {
linearGradient: {
x1: 0,
x2: 0,
y1: 0,
y2: 1
},
stops: [
[0, '#AF9D3F'],
[1, '#229595']
]
}
}, {
"showInLegend": false,
"pointPlacement": "on",
data: [
[null],
[65],
[28],
],
type: 'line',
marker: {
enabled: false
},
color: {
linearGradient: {
x1: 0,
x2: 0,
y1: 0,
y2: 1
},
stops: [
[0, '#AF9D3F'],
[1, '#229595']
]
}
}, {
"showInLegend": false,
"pointPlacement": "on",
data: [
[33],
[null],
[28],
],
type: 'line',
marker: {
enabled: false
},
color: {
linearGradient: {
x1: 0,
x2: 0,
y1: 0,
y2: 1
},
stops: [
[0, '#AF9D3F'],
[1, '#AF9D3F']
]
}
}
https://jsfiddle.net/koushlendra/o5dujm0z/719/

Bing Maps - Can't set a custom map style

I'm trying to use a custom style on my map, but no matter what I do, I can't them them working. My initialize function is:
this.init = (mapSelector, api, title = '', poi = false, prefix = '', cache = true) => {
return new Promise((r, j) => {
if (api.slice(-1) !== '/')
this.setPrefix(prefix);
this.setCache(cache);
this.setPOI(poi);
this.setTitle(title);
try {
getMapKey().then(key => {
if(mapSelector) {
_map = new Microsoft.Maps.Map(mapSelector, {
credentials: key,
center: new Microsoft.Maps.Location(_latitude, _longitude),
zoom: 13,
disableBirdseye: true,
disableStreetside: true,
showDashboard: false,
customMapStyle: JSON.parse(sampleStyle),
});
} else {
j('error');
}
});
} catch (error) {
console.log(error);
}
});
};
It currently renders the standard map just fine. but no matter what I pass into customMapStyle nothing works, JSON.parse was added to make sure the data was in JSON format, because I'm running out of ideas.. I've copied the JSON from the examples on:
https://bingmapsv8samples.azurewebsites.net/#Set%20Custom%20Map%20Style
Some of the styles I've tried to use are:
const darkMode = {
"version": "1.0",
"settings": {
"landColor": "#0B334D"
},
"elements": {
"mapElement": {
"labelColor": "#FFFFFF",
"labelOutlineColor": "#000000"
},
"political": {
"borderStrokeColor": "#144B53",
"borderOutlineColor": "#00000000"
},
"point": {
"iconColor": "#0C4152",
"fillColor": "#000000",
"strokeColor": "#0C4152"
},
"transportation": {
"strokeColor": "#000000",
"fillColor": "#000000"
},
"highway": {
"strokeColor": "#158399",
"fillColor": "#000000"
},
"controlledAccessHighway": {
"strokeColor": "#158399",
"fillColor": "#000000"
},
"arterialRoad": {
"strokeColor": "#157399",
"fillColor": "#000000"
},
"majorRoad": {
"strokeColor": "#157399",
"fillColor": "#000000"
},
"railway": {
"strokeColor": "#146474",
"fillColor": "#000000"
},
"structure": {
"fillColor": "#115166"
},
"water": {
"fillColor": "#021019"
},
"area": {
"fillColor": "#115166"
}
}
};
const sampleStyle = {
"elements": {
"park": { "fillColor": "#A9A9D4BE" },
"controlledAccessHighway": { "fillColor": "#e6c317", "strokeColor": "#D3B300", "labelColor": "#444444", "labelOutlineColor": "#60ffffff" },
"highway": { "fillColor": "#e6c317", "strokeColor": "#D3B300", "labelColor": "#444444", "labelOutlineColor": "#60ffffff" },
"water": { "fillColor": "#B7CDDE" },
"medicalBuilding": { "fillColor": "#fceced" },
"majorRoad": { "fillColor": "#f0d85a" },
"education": { "fillColor": "#f0e8f8" },
"arterialRoad": { "fillColor": "#ffed91" },
"structure": { "fillColor": "#faf8ed" },
"buildinglobal": { "fillColor": "#e5e0d8" },
"forest": { "fillColor": "#deebdd" },
"vegetation": { "fillColor": "#deebdd" },
"reserve": { "fillColor": "#deebdd" },
"street": { "fillColor": "#ffffff", "strokeColor": "#e6e3df" },
"roadShield": { "fillColor": "#ffffff" },
"medical": { "fillColor": "#ffddee" },
"educationBuildinglobal": { "fillColor": "#f6f0f1" },
"golfCourse": { "fillColor": "#c5dabb" }
},
"settings": { "landColor": "#F6F4E3" }
};
Does anyone know how to get a custom style activated? If that's not possible, is there a dark mode that I can activate, which is what I'm trying to do.
Thanks
I would suggest taking a look at the map style sheet editor app - it will allow you to interactively adjust the style and shows sample code for how to initialize that style in all of the Bing maps controls (HTML, UWP and Static maps).
https://www.microsoft.com/en-us/p/map-style-sheet-editor/9nbhtcjt72ft
I had to set setOption, it had nothing to do with the map style I was trying to apply.

How to have Alexa perform button "SetLight" directives consecutively?

I'm working on having Alexa display a pattern of blinks utilizing two buttons for a second of orange each with a half second of black buffer. So the pattern would be:
button 1 for 1 second of orange with half a second of black.
button 2 for one second of orange with half a second of black.
button 2 for one second of orange with half a second of black.
button 1 for one second of orange with half a second of black.
I'm trying to stack them, but it never really works. Here is the code I'm using:
this.response._addDirective({
"type": "GadgetController.SetLight",
"version": 1,
"targetGadgets": ["amzn1.ask.gadget.XXX1"],
"parameters": {
"triggerEvent": "none",
"triggerEventTimeMs": 0,
"animations": [{
"repeat": 1,
"targetLights": ["1"],
"sequence": [
{
"durationMs": 1000,
"blend": false,
"color": "000000"
},
{
"durationMs": 1000,
"blend": false,
"color": "b32d00"
}
]
}]
}
});
this.response._addDirective({
"type": "GadgetController.SetLight",
"version": 1,
"targetGadgets": ["amzn1.ask.gadget.XXXX2"],
"parameters": {
"triggerEvent": "none",
"triggerEventTimeMs": 0,
"animations": [{
"repeat": 1,
"targetLights": ["1"],
"sequence": [{
"durationMs": 1500,
"blend": false,
"color": "000000"
},
{
"durationMs": 1000,
"blend": false,
"color": "b32d00"
}
]
}]
}
});
this.response._addDirective({
"type": "GadgetController.SetLight",
"version": 1,
"targetGadgets": ["amzn1.ask.gadget.XXXX2"],
"parameters": {
"triggerEvent": "none",
"triggerEventTimeMs": 0,
"animations": [{
"repeat": 1,
"targetLights": ["1"],
"sequence": [
{
"durationMs": 2000,
"blend": false,
"color": "000000"
},
{
"durationMs": 1000,
"blend": false,
"color": "b32d00"
}
]
}]
}
});
this.response._addDirective({
"type": "GadgetController.SetLight",
"version": 1,
"targetGadgets": ["amzn1.ask.gadget.XXXX1"],
"parameters": {
"triggerEvent": "none",
"triggerEventTimeMs": 0,
"animations": [{
"repeat": 1,
"targetLights": ["1"],
"sequence": [
{
"durationMs": 2500,
"blend": false,
"color": "000000"
},
{
"durationMs": 1000,
"blend": false,
"color": "b32d00"
}
]
}]
}
});
I'm guessing my issue lies around the "none" trigger events cancelling each other out, but there has to be a way to do it. Any thoughts?
I did end up figuring this out and wanted to update this in case someone else stumbles across it.
I was trying to run 4 animations consecutively running over two buttons, but this isn't possible. You can only have one animation (SetLight) directive running per button, so this this case I ended up using two. Once I changed my way of thinking to this, I was able to have two animations, one for each button which had the proper button light up one the other one was dark. Examples are below:
Button 1's setLight directive:
this.response._addDirective({
"type": "GadgetController.SetLight",
"version": 1,
"targetGadgets": [`${deviceIds[0]}`],
"parameters": {
"animations": [{
"repeat": 1,
"targetLights": ["1"],
"sequence": [{
"durationMs": 3000,
"blend": false,
"color": "000000"
},
{
"durationMs": 1000,
"blend": false,
"color": b32d00
},
{
"durationMs": 500,
"blend": false,
"color": "000000"
},
{
"durationMs": 1000,
"blend": false,
"color": 000000
},
{
"durationMs": 500,
"blend": false,
"color": "000000"
}
]
}],
"triggerEvent": "none",
"triggerEventTimeMs": 0
}
Button 2's setLight directive:
this.response._addDirective({
"type": "GadgetController.SetLight",
"version": 1,
"targetGadgets": [`${deviceIds[0]}`],
"parameters": {
"animations": [{
"repeat": 1,
"targetLights": ["1"],
"sequence": [{
"durationMs": 3000,
"blend": false,
"color": "000000"
},
{
"durationMs": 1000,
"blend": false,
"color": 000000
},
{
"durationMs": 500,
"blend": false,
"color": "000000"
},
{
"durationMs": 1000,
"blend": false,
"color": b32d00
},
{
"durationMs": 500,
"blend": false,
"color": "000000"
},
{
"durationMs": 10000,
"blend": false,
"color": "b32d00"
}
]
}],
"triggerEvent": "none",
"triggerEventTimeMs": 0
}
Thats the basic jist, hope it helps someone else.

Angular states not showing amcharts after switching back to that state

I have two charts divs in html which I am able to display first time. but when my state changes and I come back to the state where I displayed charts. Then charts are not shown. I think I have to re-attach the dataProvider and render it again but i don't know how.
this is my controller
.controller('HomeCtrl', function ($location,$window) {
AmCharts.makeChart("chartdiv-pie", {
"type": "pie",
"theme": "light",
"dataProvider": [{
"title": "20%",
"value": 3852,
"color": "#18aa9f"
}, {
"title": "40%",
"value": 3899,
"color": "#e65548"
},
{
"title": "40%",
"value": 4899,
"color": "#e1e3e4"
}
],
"title": "AmCharts",
"color": "black",
"titleField": "title",
"valueField": "value",
"radius": "25%",
"outlineAlpha":0,
"innerRadius": "40%",
"balloonText": "[[value]]",
"labelText": "[[title]]",
"labelsEnabled": true,
"colorField": "color",
"labelText": "[[title]]",
"export": {
"enabled": true
},
});
var chart = AmCharts.makeChart( "chartdiv-male", {
"type": "serial",
"addClassNames": true,
"theme": "light",
"autoMargins": false,
"marginLeft": 30,
"marginRight": 8,
"marginTop": 10,
"marginBottom": 26,
"balloon": {
"adjustBorderColor": false,
"horizontalPadding": 10,
"verticalPadding": 8,
"color": "#ffffff"
},
"dataProvider": [ {
"year": "Pos",
"income": 30.1,
"color": "#FF0F00",
"expenses": 34.9,
}, {
"year": "Neg",
"income": 29.5,
"expenses": 31.1
}, {
"year": "Neu",
"income": 30.6,
"expenses": 28.2,
"dashLengthLine": 5,
"columnColor": 'green'
} ],
"valueAxes": [ {
"axisAlpha": 0,
"position": "left"
} ],
"startDuration": 1,
"graphs": [ {
"alphaField": "alpha",
"balloonText": "<span style='font-size:12px;'>[[title]] in [[category]]:<br><span style='font-size:20px;'>[[value]]</span> [[additional]]</span>",
"fillAlphas": 1,
"title": "Income",
"type": "column",
"valueField": "income",
"dashLengthField": "dashLengthColumn"
}, ],
"categoryField": "year",
"categoryAxis": {
"gridPosition": "start",
"axisAlpha": 0,
"tickLength": 0
},
"export": {
"enabled": true
}
} );
}
these are my states
.state('home.stats', {
url:'/stats',
templateUrl: 'views/stats.html',
controller: 'StatsCtrl',
controllerAs: 'stats'
})
.state('home.posts', {
url:'/posts',
templateUrl: 'views/posts.html',
controller: 'PostsCtrl',
controllerAs: 'posts'
});

Resources