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.
Related
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
I am working on a project with React and Redux hooks. It has recursively nested kanban boards. When you add a new card to a kanban column that is scrolled all of the way to the right, the component re-renders and jerks the kanban board back to x=0, y-0 scroll. It is not the window that is scrolling. It is the kanban's parent element.
Does anyone know how you need to re-structure the List component (or any other part of the code), so that you can add a card to the columns (that are in a scrolled container), and not ruin the scroll position?
Thank you for any pointers!
I have tried using a ref to get the scroll position of the scrolled div right before the dispatch to add new card, and then set that position again as soon as the dispatch has added the card; but this did not work.
The data on the redux state is:
listSlice.js
list.nodes:
{
"0": {
"text": "board-one",
"id": 0,
"view": "board",
"childIds": [
100,
101,
102,
103,
104
],
"parentId": null,
"order": 0,
"isExpanded": true
},
"1": {
"text": "board-two",
"id": 1,
"view": "board",
"childIds": [
200,
201,
202,
203,
204
],
"parentId": null,
"order": 1,
"isExpanded": true
},
"2": {
"text": "board-three",
"id": 2,
"view": "board",
"childIds": [
300,
301,
302,
303,
304
],
"parentId": null,
"order": 2,
"isExpanded": true
},
"3": {
"text": "board-four",
"id": 3,
"view": "board",
"childIds": [
400,
401,
402,
403,
404
],
"parentId": null,
"order": 3,
"isExpanded": true
},
"100": {
"text": "backlog",
"id": 100,
"childIds": [
1000,
1001
],
"view": "column",
"order": 0,
"isExpanded": true
},
"101": {
"text": "to do",
"id": 101,
"childIds": [
2000,
2001
],
"view": "column",
"order": 1,
"isExpanded": true
},
"102": {
"text": "in progress",
"id": 102,
"childIds": [
3000,
3001
],
"view": "column",
"order": 2,
"isExpanded": true
},
"103": {
"text": "blocked",
"id": 103,
"childIds": [
4000,
4001
],
"view": "column",
"order": 3,
"isExpanded": true
},
"104": {
"text": "complete",
"id": 104,
"childIds": [
5000,
5001
],
"view": "column",
"order": 4,
"isExpanded": true
},
"200": {
"text": "backlog",
"id": 200,
"childIds": [
1000,
1001
],
"view": "column",
"order": 0,
"isExpanded": true
},
"201": {
"text": "to do",
"id": 201,
"childIds": [
2000,
2001
],
"view": "column",
"order": 1,
"isExpanded": true
},
"202": {
"text": "in progress",
"id": 202,
"childIds": [
3000,
3001
],
"view": "column",
"order": 2,
"isExpanded": true
},
"203": {
"text": "blocked",
"id": 203,
"childIds": [
4000,
4001
],
"view": "column",
"order": 3,
"isExpanded": true
},
"204": {
"text": "complete",
"id": 204,
"childIds": [
5000,
5001
],
"view": "column",
"order": 4,
"isExpanded": true
},
"300": {
"text": "backlog",
"id": 300,
"childIds": [
1000,
1001
],
"view": "column",
"order": 0,
"isExpanded": true
},
"301": {
"text": "to do",
"id": 301,
"childIds": [
2000,
2001
],
"view": "column",
"order": 1,
"isExpanded": true
},
"302": {
"text": "in progress",
"id": 302,
"childIds": [
3000,
3001
],
"view": "column",
"order": 2,
"isExpanded": true
},
"303": {
"text": "blocked",
"id": 303,
"childIds": [
4000,
4001
],
"view": "column",
"order": 3,
"isExpanded": true
},
"304": {
"text": "complete",
"id": 304,
"childIds": [
5000,
5001
],
"view": "column",
"order": 4,
"isExpanded": true
},
"400": {
"text": "backlog",
"id": 400,
"childIds": [
1000,
1001
],
"view": "column",
"order": 0,
"isExpanded": true
},
"401": {
"text": "to do",
"id": 401,
"childIds": [
2000,
2001
],
"view": "column",
"order": 1,
"isExpanded": true
},
"402": {
"text": "in progress",
"id": 402,
"childIds": [
3000,
3001
],
"view": "column",
"order": 2,
"isExpanded": true
},
"403": {
"text": "blocked",
"id": 403,
"childIds": [
4000,
4001
],
"view": "column",
"order": 3,
"isExpanded": true
},
"404": {
"text": "complete",
"id": 404,
"childIds": [
5000,
5001
],
"view": "column",
"order": 4,
"isExpanded": true
},
"1000": {
"text": "card-one",
"id": 1000,
"childIds": [],
"order": 0,
"isExpanded": true,
"view": "card"
},
"1001": {
"text": "card-two",
"id": 1001,
"childIds": [],
"order": 1,
"isExpanded": true,
"view": "card"
},
"2000": {
"text": "card-one",
"id": 2000,
"childIds": [],
"order": 0,
"isExpanded": true,
"view": "card"
},
"2001": {
"text": "card-two",
"id": 2001,
"childIds": [],
"order": 1,
"isExpanded": true,
"view": "card"
},
"3000": {
"text": "card-one",
"id": 3000,
"childIds": [],
"order": 0,
"isExpanded": true,
"view": "card"
},
"3001": {
"text": "card-two",
"id": 3001,
"childIds": [],
"order": 1,
"isExpanded": true,
"view": "card"
},
"4000": {
"text": "card-one",
"id": 4000,
"childIds": [],
"order": 0,
"isExpanded": true,
"view": "card"
},
"4001": {
"text": "card-two",
"id": 4001,
"childIds": [],
"order": 1,
"isExpanded": true,
"view": "card"
},
"5000": {
"text": "card-one",
"id": 5000,
"childIds": [],
"order": 0,
"isExpanded": true,
"view": "card"
},
"5001": {
"text": "card-two",
"id": 5001,
"childIds": [],
"order": 1,
"isExpanded": true,
"view": "card"
}
}
listSlice.js
list.visibleIds:
[
"0",
"1",
"2",
"3"
]
The component:
(to keep the example simple, there is only an add button on the column. The error occurs when the board is scrolled, to see a column at the end; and you try to add a card to one of those columns at the end).
List.js
import React, { useEffect } from "react";
import { useSelector, useDispatch } from "react-redux";
import { v4 as uuid } from "uuid";
import {
fetchNodesAsync,
selectVisibleIds,
selectParentId,
addNewNodeAsync,
selectNodes
} from "./listSlice";
import "./List.css";
export function List(props = {}) {
let { isRoot } = props;
const nodes = useSelector(selectNodes);
const visibleIds = useSelector(selectVisibleIds);
const parentId = useSelector(selectParentId);
const dispatch = useDispatch();
useEffect(() => {
if (isRoot) {
dispatch(fetchNodesAsync());
}
}, []);
const renderList = (params) => {
let { ids, parentView } = params;
return (
// This is the element that is scrolled when the error occurs. It is scrolled to the left, so that you can see the last columns in the list:
<ul className={`${parentView || "root"}-container`}>
{ids.map((id) => {
let node = nodes[id];
return (
<li key={uuid()} className={node.view}>
<div className="header">
{node.view === "column" && (
<button
onClick={(e) => {
e.preventDefault();
dispatch(addNewNodeAsync({ parentId: id }));
}}
>
+ add item
</button>
)}
id: {node.id} {node.text}
</div>
<div className={`${node.view}-scroll`}>
{node.isExpanded &&
node.childIds.length >= 1 &&
renderList({
ids: node.childIds,
parentId: id,
parentView: node.view
})}
</div>
</li>
);
})}
</ul>
);
};
return <ul className="List">{renderList({ ids: visibleIds, parentId })}</ul>;
}
I'm trying to implement the data-structure that Dan Abramov describes here:
https://github.com/reduxjs/redux/issues/1629
You cannot do this: <li key={uuid()} ... /> because uuid will generate a new random ID at every render, which will make React generate new DOM nodes at every state change and therefore will lose the scroll amount stored inside the previous nodes. You should use <li key={id} ... /> instead, so that the IDs stay the same.
I have one system that is connected to some sensors. The main job is to send error numbers when one or more of the sensors are on.
In order to print the error description I have one csv-File with two columns, the first one with the numbers and the second one with the description.
In order to make this task I have created one flow in Node-Red:
In one line I save the array with the error numbers coming from the system in one flow variable (RandomNum).
In another line I read the csv-file with the error description, I transform it in an array of objects and then in fuction node I make a search in order to find the error number and the description.
The search function has as entance the array of objects. I save the flow variable (RandomNum) in an array (ranNum) and I define a new array (newMsg) where I save the description of the errors.
Then I use a while-loop in order to go through the array of objects and compare the value of the first column of this array with the number in ranNum. Then I save the description of the error in the array newMsg and I do this while-loop for each value of the ranNum array.
And here is my problem. When I execute the flow, it works correctly for the first value of the array ranNum but only for this. I get only the description of the first number in the ranNum array as payload, it looks like as the while-loop is used only once, and then it breaks and gives me the array newMsg.
When I check in the Conetxt, RandomNum is one array,
An when I ask to get the array ranNum, it's also an array,
I have check the while-loop at least 20-times, and I have did not found why it does not work.
Can anyone help me with this topic? Is there a problem with the flow variable or there is big difference between JavaScript and NodeJS that I did not found?
Here is the flow I have created:
[
{
"id": "b1d8b61d0ed5a5da",
"type": "tab",
"label": "Flow Test",
"disabled": false,
"info": ""
},
{
"id": "d677b342ccc51f1b",
"type": "inject",
"z": "b1d8b61d0ed5a5da",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 140,
"y": 280,
"wires": [
[
"e2d5187d2e705892",
"a167b5a81e0b36ba"
]
]
},
{
"id": "7aa6e0bcbdf67c1c",
"type": "file in",
"z": "b1d8b61d0ed5a5da",
"name": "ReadAlarms",
"filename": "/home/DMT/Dokumente/DB_Test/alarms.csv",
"format": "utf8",
"chunk": false,
"sendError": false,
"encoding": "none",
"allProps": false,
"x": 530,
"y": 280,
"wires": [
[
"f2ab599d26fd7ca5",
"94ae4b1ea29d9fe2"
]
]
},
{
"id": "f2ab599d26fd7ca5",
"type": "debug",
"z": "b1d8b61d0ed5a5da",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 750,
"y": 220,
"wires": []
},
{
"id": "94ae4b1ea29d9fe2",
"type": "csv",
"z": "b1d8b61d0ed5a5da",
"name": "ConvertAlarms",
"sep": ",",
"hdrin": false,
"hdrout": "all",
"multi": "mult",
"ret": "\\n",
"temp": "",
"skip": "0",
"strings": true,
"include_empty_strings": "",
"include_null_values": "",
"x": 760,
"y": 280,
"wires": [
[
"9a3547cc81c2d2bb",
"ff9175d01efa5ce4"
]
]
},
{
"id": "9a3547cc81c2d2bb",
"type": "debug",
"z": "b1d8b61d0ed5a5da",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 990,
"y": 220,
"wires": []
},
{
"id": "1a270df6276485c4",
"type": "debug",
"z": "b1d8b61d0ed5a5da",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1230,
"y": 220,
"wires": []
},
{
"id": "ff9175d01efa5ce4",
"type": "function",
"z": "b1d8b61d0ed5a5da",
"name": "SearchFailureS7",
"func": "let i=0;\nlet ranNum = [];\nranNum = flow.get(\"RandomNum\");\nlet newMsg = [];\n\nwhile (i<ranNum.length){\n\n let n = ranNum[i];\n newMsg[newMsg.length] = {payload: msg.payload[n].col2};\n i = i + 1;\n \n}\n\nreturn newMsg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1010,
"y": 280,
"wires": [
[
"1a270df6276485c4"
]
]
},
{
"id": "a167b5a81e0b36ba",
"type": "function",
"z": "b1d8b61d0ed5a5da",
"name": "RandomArray",
"func": "const num=[];\nvar i;\n\nfor (i=0; i<3; i++){\n \nnum[i] = Math.floor(Math.random() * 9);\n\n}\n\nrandArray = {payload: num}\n\nreturn randArray;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 340,
"y": 400,
"wires": [
[
"c011fa2387db0d18",
"9c400785174973e9"
]
]
},
{
"id": "c011fa2387db0d18",
"type": "debug",
"z": "b1d8b61d0ed5a5da",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 530,
"y": 340,
"wires": []
},
{
"id": "9c400785174973e9",
"type": "function",
"z": "b1d8b61d0ed5a5da",
"name": "",
"func": "flow.set(\"RandomNum\",msg.payload);\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 520,
"y": 400,
"wires": [
[]
]
},
{
"id": "e2d5187d2e705892",
"type": "delay",
"z": "b1d8b61d0ed5a5da",
"name": "Delay 10ms",
"pauseType": "delay",
"timeout": "10",
"timeoutUnits": "milliseconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 330,
"y": 280,
"wires": [
[
"7aa6e0bcbdf67c1c"
]
]
}
]
So, I finally found it. The payload in the while-loop was breaking the loop immediately. So I changed the code in the while-loop using a similar code I found on the net. Now it works.
Old code:
let i=0;
let ranNum = [];
ranNum = flow.get("RandomNum");
let newMsg = [];
while (i<ranNum.length){
let n = ranNum[i];
newMsg[newMsg.length] = {payload: msg.payload[n].col2};
i = i + 1;
}
return newMsg;
New code
let i=0;
let ranNum = [];
ranNum = flow.get("RandomNum");
let newMsg = [];
while (i<ranNum.length){
let n = ranNum[i];
let description = msg.payload[n].col2;
newMsg.push(description);
i = i + 1;
}
msg.payload = newMsg;
return msg;
I have a this json that has a arrays in it.
How can i get :
- full_text,
- picture link : media_url_https from media and from extended_entities
- url from entities in urls
- lang
[{
"created_at": "Thu Oct 12 14:42:03 +0000 2017",
"id": 9184869314823331890,
"id_str": "9184869314823331890",
"full_text": "trying some stuff! \nhttps://somewebsite.com/emjc1MLAbD\n\uf6430\nWhat bird is this? What is its name? It has beautiful feathers. Love the mix of green, white. https://somewebsite.com/q3IqrfVcUz",
"truncated": false,
"display_text_range": [0, 139],
"entities": {
"hashtags": [],
"symbols": [],
"user_mentions": [],
"urls": [{
"url": "https://somewebsite.com/emjc1MLAbD",
"expanded_url": "https://www.pexels.com/royalty-free-images/",
"display_url": "pexels.com/royalty-free-i\u2026",
"indices": [20, 43]
}],
"media": [{
"id": 918486209067827200,
"id_str": "918486209067827200",
"indices": [140, 163],
"media_url": "http://pbs.twimg.com/media/DL8eVz6VQAA4VHn.jpg",
"media_url_https": "https://pbs.twimg.com/media/DL8eVz6VQAA4VHn.jpg",
"url": "https://somewebsite.com/q3IqrfVcUz",
"display_url": "pic.twitter.com/q3IqrfVcUz",
"expanded_url": "https://twitter.com/DevAdama/status/918486931482333189/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 680,
"h": 482,
"resize": "fit"
},
"medium": {
"w": 1200,
"h": 850,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 1939,
"h": 1374,
"resize": "fit"
}
}
}]
},
"extended_entities": {
"media": [{
"id": 918486209067827200,
"id_str": "918486209067827200",
"indices": [140, 163],
"media_url": "http://pbs.twimg.com/media/DL8eVz6VQAA4VHn.jpg",
"media_url_https": "https://pbs.twimg.com/media/DL8eVz6VQAA4VHn.jpg",
"url": "https://somewebsite.com/q3IqrfVcUz",
"display_url": "pic.twitter.com/q3IqrfVcUz",
"expanded_url": "https://twitter.com/DevAdama/status/918486931482333189/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 680,
"h": 482,
"resize": "fit"
},
"medium": {
"w": 1200,
"h": 850,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"large": {
"w": 1939,
"h": 1374,
"resize": "fit"
}
}
}]
},
"metadata": {
"iso_language_code": "en",
"result_type": "recent"
},
"source": "Twitter Web Client",
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 915243599930982401,
"id_str": "915243599930982401",
"name": "devAdama",
"screen_name": "DevAdama",
"location": "",
"description": "",
"url": null,
"entities": {
"description": {
"urls": []
}
},
"protected": false,
"followers_count": 0,
"friends_count": 0,
"listed_count": 0,
"created_at": "Tue Oct 03 15:54:13 +0000 2017",
"favourites_count": 0,
"utc_offset": null,
"time_zone": null,
"geo_enabled": false,
"verified": false,
"statuses_count": 2,
"lang": "en",
"contributors_enabled": false,
"is_translator": false,
"is_translation_enabled": false,
"profile_background_color": "000000",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_tile": false,
"profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png",
"profile_image_url_https": "https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png",
"profile_link_color": "981CEB",
"profile_sidebar_border_color": "000000",
"profile_sidebar_fill_color": "000000",
"profile_text_color": "000000",
"profile_use_background_image": false,
"has_extended_profile": false,
"default_profile": false,
"default_profile_image": true,
"following": false,
"follow_request_sent": false,
"notifications": false,
"translator_type": "none"
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 0,
"favorite_count": 0,
"favorited": false,
"retweeted": false,
"possibly_sensitive": false,
"lang": "en"
}, {
"created_at": "Wed Oct 04 17:33:29 +0000 2017",
"id": 915630969218064385,
"id_str": "915630969218064385",
"full_text": "hola!",
"truncated": false,
"display_text_range": [0, 5],
"entities": {
"hashtags": [],
"symbols": [],
"user_mentions": [],
"urls": []
},
"metadata": {
"iso_language_code": "es",
"result_type": "recent"
},
"source": "Twitter Web Client",
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 915243599930982401,
"id_str": "915243599930982401",
"name": "devAdama",
"screen_name": "DevAdama",
"location": "",
"description": "",
"url": null,
"entities": {
"description": {
"urls": []
}
},
"protected": false,
"followers_count": 0,
"friends_count": 0,
"listed_count": 0,
"created_at": "Tue Oct 03 15:54:13 +0000 2017",
"favourites_count": 0,
"utc_offset": null,
"time_zone": null,
"geo_enabled": false,
"verified": false,
"statuses_count": 2,
"lang": "en",
"contributors_enabled": false,
"is_translator": false,
"is_translation_enabled": false,
"profile_background_color": "000000",
"profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
"profile_background_tile": false,
"profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png",
"profile_image_url_https": "https://website.com/sticky/default_profile_images/default_profile_normal.png",
"profile_link_color": "981CEB",
"profile_sidebar_border_color": "000000",
"profile_sidebar_fill_color": "000000",
"profile_text_color": "000000",
"profile_use_background_image": false,
"has_extended_profile": false,
"default_profile": false,
"default_profile_image": true,
"following": false,
"follow_request_sent": false,
"notifications": false,
"translator_type": "none"
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 0,
"favorite_count": 0,
"favorited": false,
"retweeted": false,
"lang": "es"
}]
Maybe not tidy but still you can try do the following:
require 'json'
test = JSON.parse(json)
test.each {|k|
p "============================"
full_text = k['full_text'] unless k['full_text'].nil?
urls = k['entities']['urls'] unless k['entities']['urls'].nil?
urls.each {|u|
entities_url = u['url'] unless u['url'].nil?
p "Url: #{entities_url}" }
lang = k['lang'] unless k['lang']
media = k['entities']['media']
extended_media = k['extended_entities']['media'] unless k['extended_entities'].nil?
p "Full text: #{full_text}" unless full_text.nil?
media.each {|u|
p "Media url: #{u['media_url_https']}" unless u['media_url_https'].nil?
} unless media.nil?
extended_media.each {|u|
p "Extended url: #{u['media_url_https']}" unless u['media_url_https'].nil?
} unless extended_media.nil?
p "Lang: #{lang}" unless lang.nil?
p "============================="
}
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'
});