2D Trilateration using Trilateration Application - trilateration

I'm trying to implement Trilateration between 3 2D points. I was eventually tring to use this library Trilateration. I used the example which is given below and try to execute it. Below is the code
import org.apache.commons.math3.fitting.leastsquares.LeastSquaresOptimizer.Optimum;
import org.apache.commons.math3.fitting.leastsquares.LevenbergMarquardtOptimizer;
import com.lemmingapex.trilateration.NonLinearLeastSquaresSolver;
import com.lemmingapex.trilateration.TrilaterationFunction;
public class Pointofintersection {
public static void main() {
// TODO Auto-generated method stub
double[][] positions = new double[][] { { 5.0, -6.0 }, { 13.0, -15.0 }, { 21.0, -3.0 }, { 12.4, -21.2 } };
double[] distances = new double[] { 8.06, 13.97, 23.32, 15.31 };
NonLinearLeastSquaresSolver solver = new NonLinearLeastSquaresSolver(new TrilaterationFunction(positions, distances), new LevenbergMarquardtOptimizer());
Optimum optimum = solver.solve();
double[] centroid = optimum.getPoint().toArray();
System.out.println(centroid);
//System.out.println(centroid[1]);
}
}
So now what type of output I should expect. I got some weird output that i couldnt understand itself.
-2.0433926409457167E-7d,
-9.1973399031975E-8d,
-1.5723449006087263E-7d,
+7.887051614592191E-8d,
+1.4166246290402286E-7d,
+3.330146018487787E-8d,
+2.3278688667580978E-7d,
-2.1139124097042925E-7d,
+1.334449995534113E-7d,
-1.6104730195920897E-7d,
-1.3902314592614197E-7d,
+2.0169027167169864E-7d,
-9.040643863751471E-8d,
-5.946190852360168E-8d,
-1.8013411720005014E-7d,
+2.6595401669835947E-8d,
+8.607292924069425E-8d,
+4.84038176769263E-10d,
-2.2798356346688802E-7d,
-1.203028719549339E-7d,
-1.5111906039270745E-7d,
+1.5859915617670956E-7d,
-1.426262681506497E-7d,
-9.892260062323546E-8d,
-1.8492643515928268E-7d,
+7.840210076743552E-8d,
+2.1643071541578027E-7d,
+2.313664294893465E-7d,
+1.2541842003811723E-7d,
-9.920197743470107E-8d,
+3.655589133934081E-8d,
+5.807052689551411E-8d,
-3.244024724169575E-8d,
-2.327564406466327E-7d,
-6.38187356721971E-8d,
-2.3995994000400915E-10d,
-3.9793609609721186E-8d,
-1.802510054588344E-7d,
+5.745586744591196E-8d,
+1.987228872666507E-7d,
-2.3105188606976847E-7d,
+2.0088042407239129E-7d,
+6.624793114025702E-8d,
-1.5587043044056635E-7d,
+1.3606464059428694E-8d,
+1.0008761540741556E-7d,
+1.058213771597129E-7d,
+3.3058299602856804E-8d,
-1.1594886810010702E-7d,
+1.378919824418909E-7d,
-1.5683631181406778E-7d,
-4.4200075770425176E-8d,
+1.2250985436706623E-9d,
-1.8297013058336644E-8d,
-1.005004229646318E-7d,
+2.337202285991116E-7d,
+3.296104292035678E-8d,
-2.23668185816307E-7d,
-5.7055442971184756E-8d,
+5.82391923137467E-8d,
+1.244950238958056E-7d,
+1.4399358260219398E-7d,
+1.1901862840583523E-7d,
+5.1856152603337505E-8d,
-5.520562000491495E-8d,
-1.9987622893254038E-7d,
+9.697418238031897E-8d,
-1.1603376405901542E-7d,
+1.170714288147407E-7d,
-1.550851303094034E-7d,
+2.3472546699189522E-8d,
+1.78211222185955E-7d,
-1.6540009048230807E-7d,
-5.137865010872577E-8d,
+4.57490653163866E-8d,
+1.2829599363166098E-7d,
+1.985773325073412E-7d,
-2.1792661654989742E-7d,
-1.652218131743459E-7d,
-1.178234251477505E-7d,
-7.34071933723896E-8d,
-2.9646587857612632E-8d,
+1.5787194498912167E-8d,
+6.52252321321176E-8d,
+1.2100088103262734E-7d,
+1.8544977697201776E-7d,
-2.159273204728711E-7d,
-1.2711589287782304E-7d,
-2.2610609958205195E-8d,
+9.993330547750349E-8d,
-2.33974236642384E-7d,
-6.830955860192377E-8d,
+1.2244183812423448E-7d,
-1.3620325027706252E-7d,
+1.1178574689680927E-7d,
-8.490693031052439E-8d,
+2.2975389535985893E-7d,
+1.0445707500867073E-7d,
+1.8405243253979117E-8d,
-2.6033812325397097E-8d,
-2.6489990728664908E-8d,
+1.9409124727247465E-8d,
+1.1403826867020365E-7d,
-2.1706266226554237E-7d,
-1.7839974359909697E-8d,
+2.3725087624341041E-7d,
+7.37567604176979E-8d,
-2.9098805266958403E-8d,
-6.892713087722722E-8d,
-4.333719263537725E-8d,
+5.006436936098099E-8d,
+2.1367325342138113E-7d,
-2.6949659655907758E-8d,
-1.9256682968755803E-7d,
+1.960616287777496E-7d,
+1.876664741413704E-7d,
-2.1534486893602122E-7d,
-5.688830723853217E-8d,
+1.8861113228746644E-7d,
+4.6730779443102234E-8d,
-3.275360514112964E-9d,
+4.1011920825226876E-8d,
+1.820141955326842E-7d,
-5.468175655175594E-8d,
-1.8981247089866317E-7d,
-2.209492705846306E-7d,
-1.4566110577298295E-7d,
+3.848544860465368E-8d,
-1.429109630340783E-7d,
-2.105749999899302E-7d,
-1.6206609756618993E-7d,
+5.058693461947143E-9d,
-1.8359244902596882E-7d,
+2.2810251664891242E-7d,
-1.8791776732592608E-7d,
+1.3106843166204263E-9d,
-1.5543153797220025E-7d,
-1.7884997059081524E-7d,
-6.648490725635754E-8d,
+1.8412576154421806E-7d,
+9.860939269906055E-8d,
+1.5627006743114285E-7d,
-1.17260039161597E-7d,
+2.3416513526430908E-7d,
-2.1749172296989992E-7d,
-3.9242560971295217E-8d,
-1.822826971477839E-7d,
-1.6729355321895212E-7d,
+8.208715337901827E-9d,
-1.301267783434537E-7d,
-1.029741755377153E-7d,
+9.215765583599035E-8d,
-1.907487641016455E-8d,
+4.2661388254716074E-8d,
-1.9697226735187428E-7d,
+2.1819935527247946E-7d,
-1.398318929248588E-7d,
+1.6195123407015624E-7d,
+1.723826394935661E-7d,
-1.0602700638269148E-7d,
-1.9392742205954563E-7d,
-8.880302882034106E-8d,
+2.1186420987133E-7d,
+2.3375763256988976E-7d,
-2.0599801342241997E-8d,
-7.184550924856607E-8d,
+8.254840070367875E-8d,
};
LN_MANT
{
{+0.0d, +0.0d, }, // 0
{+9.760860120877624E-4d, -3.903230345984362E-11d, }, // 1
{+0.0019512202125042677d, -8.124251825289188E-11d, }, // 2
{+0.0029254043474793434d, -1.8374207360194882E-11d,}, // 3
{+0.0038986406289041042d, -2.1324678121885073E-10d,}, // 4
{+0.004870930686593056d, -4.5199654318611534E-10d,}, // 5
{+0.025073636323213577d, +1.2289023836765196E-9d, }, // 26
......
{+0.02602556347846985d, +1.7990281828096504E-9d, }, // 27
{+0.026976589113473892d, -1.4152718164638451E-9d, }, // 28
{+0.02792670577764511d, +7.568772963781632E-10d, }, // 29
{+0.0288759246468544d, -1.1449998592111558E-9d, }, // 30
{+0.029824241995811462d, -1.6850976862319495E-9d, }, // 31
{+0.030771657824516296d, +8.422373919843096E-10d, }, // 32
{+0.0317181795835495d, +6.872350402175489E-10d, }, // 33
{+0.03266380727291107d, -4.541194749189272E-10d, }, // 34
{+0.03360854089260101d, -8.9064764856495E-10d, }, // 35
{+0.034552380442619324d, +1.0640404096769032E-9d, }, // 36
{+0.0354953333735466d, -3.5901655945224663E-10d,}, // 37
{+0.03643739968538284d, -3.4829517943661266E-9d, }, // 38
{+0.037378571927547455d, +8.149473794244232E-10d, }, // 39
{+0.03831886500120163d, -6.990650304449166E-10d, }, // 40
{+0.03925827145576477d, +1.0883076226453258E-9d, }, // 41
{+0.040196798741817474d, +3.845192807999274E-10d, }, // 42
{+0.04113444685935974d, -1.1570594692045927E-9d, }, // 43
{+0.04207121580839157d, -1.8877045166697178E-9d, }, // 44
{+0.043007105588912964d, -1.6332083257987747E-10d,}, // 45
{+0.04394212365150452d, -1.7950057534514933E-9d, }, // 46
{+0.04487626254558563d, +2.302710041648838E-9d, }, // 47
{+0.045809537172317505d, -1.1410233017161343E-9d, }, // 48
{+0.04674194008111954d, -3.0498741599744685E-9d, }, // 49
{+0.04767347127199173d, -1.8026348269183678E-9d, }, // 50
{+0.04860413819551468d, -3.233204600453039E-9d, }, // 51
{+0.04953393340110779d, +1.7211688427961583E-9d, }, // 52
{+0.05046287178993225d, -2.329967807055457E-10d, }, // 53
{+0.05139094591140747d, -4.191810118556531E-11d, }, // 54
{+0.052318163216114044d, -3.5574324788328143E-9d, }, // 55
{+0.053244516253471375d, -1.7346590916458485E-9d, }, // 56
{+0.05417001247406006d, -4.343048751383674E-10d, }, // 57
{+0.055094651877880096d, +1.92909364037955E-9d, }, // 58
{+0.056018441915512085d, -5.139745677199588E-10d, }, // 59
{+0.05694137513637543d, +1.2637629975129189E-9d, }, // 60
{+0.05786345899105072d, +1.3840561112481119E-9d, }, // 61
{+0.058784693479537964d, +1.414889689612056E-9d, }, // 62
{+0.05970507860183716d, +2.9199191907666474E-9d, }, // 63
{+0.0606246218085289d, +7.90594243412116E-12d, }, // 64
{+0.06154331564903259d, +1.6844747839686189E-9d, }, // 65
{+0.06246116757392883d, +2.0498074572151747E-9d, }, // 66
{+0.06337818503379822d, -4.800180493433863E-9d, }, // 67
{+0.06429435312747955d, -2.4220822960064277E-9d, }, // 68
{+0.06520968675613403d, -4.179048566709334E-9d, }, // 69
{+0.06612417101860046d, +6.363872957010456E-9d, }, // 70
{+0.06703783571720123d, +9.339468680056365E-10d, }, // 71
{+0.06795066595077515d, -4.04226739708981E-9d, }, // 72
.......
{+0.47036975622177124d, +1.6922605350647674E-8d, }, // 615
{+0.4709796905517578d, +2.4667033200046904E-8d, }, // 616
.......
{+0.5952457189559937d, +3.67972590471072E-8d, }, // 833
{+0.595784068107605d, +4.566672575206695E-8d, }, // 834
{+0.5963221788406372d, +3.2813537149653483E-9d, }, // 835
{+0.5968599319458008d, +2.916199305533732E-8d, }, // 836
{+0.5973974466323853d, +4.410412409109416E-9d, }, // 837
{+0.5979346036911011d, +4.85464582112459E-8d, }, // 838
{+0.5984715223312378d, +4.267089756924666E-8d, }, // 839
{+0.5990082025527954d, -1.2906712010774655E-8d, }, // 840
{+0.5995445251464844d, +1.3319784467641742E-9d, }, // 841
{+0.6000806093215942d, -3.35137581974451E-8d, }, // 842
{+0.6006163358688354d, +2.0734340706476473E-9d, }, // 843
{+0.6011518239974976d, -1.0808162722402073E-8d, }, // 844
{+0.601686954498291d, +4.735781872502109E-8d, }, // 845
{+0.6022218465805054d, +5.76686738430634E-8d, }, // 846
{+0.6027565002441406d, +2.043049589651736E-8d, }, // 847
{+0.6032907962799072d, +5.515817703577808E-8d, }, // 848
{+0.6038248538970947d, +4.2947540692649586E-8d, }, // 849
{+0.6043586730957031d, -1.589678872195875E-8d, }, // 850
{+0.6048921346664429d, -1.8613847754677912E-9d, }, // 851
{+0.6054253578186035d, -3.3851886626187444E-8d, }, // 852
{+0.6059582233428955d, +7.64416021682279E-9d, }, // 853
.........
{+0.6872705221176147d, +4.995334552140326E-8d, }, // 1012
{+0.687761664390564d, -5.3763211240398744E-8d, }, // 1013
{+0.6882524490356445d, -4.0852427502515625E-8d, }, // 1014
{+0.688742995262146d, -3.0287143914420064E-8d, }, // 1015
{+0.6892333030700684d, -2.183125937905008E-8d, }, // 1016
{+0.6897233724594116d, -1.524901992178814E-8d, }, // 1017
{+0.6902132034301758d, -1.0305018010328949E-8d, }, // 1018
{+0.6907027959823608d, -6.764191876212205E-9d, }, // 1019
{+0.6911921501159668d, -4.391824838015402E-9d, }, // 1020
{+0.6916812658309937d, -2.9535446262017846E-9d, }, // 1021
{+0.6921701431274414d, -2.2153227096187463E-9d, }, // 1022
{+0.6926587820053101d, -1.943473623641502E-9d, }, // 1023
};
SINE_TABLE_A=
{
+0.0d,
+0.1246747374534607d,
+0.24740394949913025d,
+0.366272509098053d,
+0.4794255495071411d,
+0.5850973129272461d,
+0.6816387176513672d,
+0.7675435543060303d,
+0.8414709568023682d,
+0.902267575263977d,
+0.9489846229553223d,
+0.9808930158615112d,
+0.9974949359893799d,
+0.9985313415527344d,
};
SINE_TABLE_B=
{
+0.0d,
-4.068233003401932E-9d,
+9.755392680573412E-9d,
+1.9987994582857286E-8d,
-1.0902938113007961E-8d,
-3.9986783938944604E-8d,
+4.23719669792332E-8d,
-5.207000323380292E-8d,
+2.800552834259E-8d,
+1.883511811213715E-8d,
-3.5997360512765566E-9d,
+4.116164446561962E-8d,
+5.0614674548127384E-8d,
-1.0129027912496858E-9d,
};
COSINE_TABLE_A=
{
+1.0d,
+0.9921976327896118d,
+0.9689123630523682d,
+0.9305076599121094d,
+0.8775825500488281d,
+0.8109631538391113d,
+0.7316888570785522d,
+0.6409968137741089d,
+0.5403022766113281d,
+0.4311765432357788d,
+0.3153223395347595d,
+0.19454771280288696d,
+0.07073719799518585d,
-0.05417713522911072d,
};
COSINE_TABLE_B=
{
+0.0d,
+3.4439717236742845E-8d,
+5.865827662008209E-8d,
-3.7999795083850525E-8d,
+1.184154459111628E-8d,
-3.43338934259355E-8d,
+1.1795268640216787E-8d,
+4.438921624363781E-8d,
+2.925681159240093E-8d,
-2.6437112632041807E-8d,
+2.2860509143963117E-8d,
-4.813899778443457E-9d,
+3.6725170580355583E-9d,
+2.0217439756338078E-10d,
};
TANGENT_TABLE_A=
{
+0.0d,
+0.1256551444530487d,
+0.25534194707870483d,
+0.3936265707015991d,
+0.5463024377822876d,
+0.7214844226837158d,
+0.9315965175628662d,
+1.1974215507507324d,
+1.5574076175689697d,
+2.092571258544922d,
+3.0095696449279785d,
+5.041914939880371d,
+14.101419448852539d,
-18.430862426757812d,
};
TANGENT_TABLE_B=
{
+0.0d,
-7.877917738262007E-9d,
-2.5857668567479893E-8d,
+5.2240336371356666E-9d,
+5.206150291559893E-8d,
+1.8307188599677033E-8d,
-5.7618793749770706E-8d,
+7.848361555046424E-8d,
+1.0708593250394448E-7d,
+1.7827257129423813E-8d,
+2.893485277253286E-8d,
+3.1660099222737955E-7d,
+4.983191803254889E-7d,
-3.356118100840571E-7d,
};
So please let me know if im doing anything wrong or is it the real data that I should parse and use it for some other calculation.

Can you print a double array using System.out.println() as you are doing?
double[] centroid = optimum.getPoint().toArray();
System.out.println(centroid);
Did you try something like this:
What's the simplest way to print a Java array?

Related

Forge Autodesk_Error_Customtooltip

Does anyone know how to fix the error. My goal is to put some graphs in a customtooltip.
I have taken the variables from the example on the web. I don't know what is causing me to not be able to see the customtooltip.
Thank you
const dataVizExtn = await viewer.loadExtension("Autodesk.DataVisualization");
const DataVizCore = Autodesk.DataVisualization.Core;
const DataVizUI = Autodesk.DataVisualization.UI;
function onSpriteHovering(event) {
const targetDbId = event.dbId;
var id = targetDbId;
var xcoord = 262.76056690205695;
var ycoord = 357.1343908626808;
var hoveredDeviceInfo = {
id,
xcoord,
ycoord
}
var currentDeviceData = {
"Device-01": {
"CO₂": "495.71 ppm",
"Humidity": "34.33 %RH",
"Temperature": "21.18 Celsius"
}
};
var chartData = {
"Device-01": {
name: "",
properties: {
"CO₂": {
dataUnit: "ppm",
seriesData: [{
value: [1612396800000, 492.55117490452676],
label: {}
},
{
value: [1612400400000, 494.27072441289187],
label: {}
}
],
yAxis: {
dataMin: 450,
dataMax: 680
}
},
"Humidity": {
dataUnit: "%RH",
seriesData: [{
value: [1612396800000, 34.58961659380417],
label: {}
}],
yAxis: {
dataMin: 25,
dataMax: 50
}
},
}
}
};
const bocadilloemergente = new DataVizUI.CustomToolTip(hoveredDeviceInfo, chartData, currentDeviceData);
}
Error in the console:
The variable was defined in a different context, and not available during the mouse event. The customtooltip is shipped using react component not data visualization extension so you need refer to the react component package to use the tooltip.
Look here
Install the package

Receiving JSON Data from a server and storing it in an array

I am creating a react native application with a tinder-like UI. Although instead of displaying users, it should display videogame covers. I have my nodejs server setup and I can receive information from it through postman.
Upon sending a get request to my server at http://localhost:9000/coverInfo,
I get this json as a response:
[
{
"id": 110592,
"alpha_channel": false,
"animated": false,
"game": 96367,
"height": 800,
"image_id": "co2dc0",
"url": "//images.igdb.com/igdb/image/upload/t_thumb/co2dc0.jpg",
"width": 800,
"checksum": "04a45b3f-4f90-f4a1-cc0d-1483f0cc2612"
},
{
"id": 65483,
"game": 100547,
"height": 800,
"image_id": "pkkd08qhfxt5cosp3hra",
"url": "//images.igdb.com/igdb/image/upload/t_thumb/pkkd08qhfxt5cosp3hra.jpg",
"width": 1260,
"checksum": "e09f916b-04fe-8993-594e-b18435438a35"
},
{
"id": 96891,
"alpha_channel": false,
"animated": false,
"game": 132099,
"height": 933,
"image_id": "co22rf",
"url": "//images.igdb.com/igdb/image/upload/t_thumb/co22rf.jpg",
"width": 700,
"checksum": "2452703f-4092-bb6f-d52c-51eb30a4ab94"
},
....
From the client side, I am trying to retrieve this data and store it in an array. This is what my code looks like from the client side:
export default function App() {
const [games, setGames] = useState([])
const [currentIndex, setCurrentIndex] = useState(0)
const swipesRef = useRef(null)
async function fetchGames() {
try {
const {data} = await axios.get('http://localhost:9000/coverInfo')
setGames(data.results)
console.log(data.results)
} catch (error) {
console.log
Alert.alert('Error getting games', '', [{text: 'Retry', onPress: () => fetchGames()}])
}
}
useEffect(() => {
fetchGames()
}, [])
function handleLike() {
console.log('like')
nextGame()
}
function handlePass() {
console.log('pass')
nextGame()
}
function nextGame() {
const nextIndex = games.length - 2 == currentIndex ? 0 : currentIndex + 1
setCurrentIndex(nextIndex)
}
function handleLikePress() {
swipesRef.current.openLeft()
}
function handlePassPress(){
swipesRef.current.openRight()
}
return (
<View style={styles.container}>
<TopBar />
<View style = {styles.swipes}>
{games.length > 1 &&
games.map(
(u, i) =>
currentIndex == i && (
<Swipes
key = {i}
ref={swipesRef}
currentIndex={currentIndex}
games={games}
handleLike={handleLike}
handlePass={handlePass}
></Swipes>
)
)}
</View>
<BottomBar handlePassPress={handlePassPress} handleLikePress={handleLikePress}/>
</View>
);
}
However, I get the following error when running:
TypeError: Cannot read property 'length' of undefined
App
C:/Users/matth/Joystik/App.js:62
59 | return (
60 | <View style={styles.container}>
61 | <TopBar />
> 62 | <View style = {styles.swipes}>
| ^ 63 | {games.length > 1 &&
64 | games.map(
65 | (u, i) =>
View compiled
▶ 17 stack frames were collapsed.
fetchGames$
C:/Users/matth/Joystik/App.js:23
20 | async function fetchGames() {
21 | try {
22 | const {data} = await axios.get('http://localhost:9000/coverInfo')
> 23 | setGames(data.results)
| ^ 24 | console.log(data.results)
25 | } catch (error) {
26 | console.log
View compiled
▶ 6 stack frames were collapsed.
The Code on my server side looks like this:
router.get("/", function(req, res, next) {
axios({
url: "https://api.igdb.com/v4/covers",
method: 'POST',
headers: {
'Accept': 'application/json',
'Client-ID' : '----------------------------',
'Authorization' : 'Bearer ------------------',
},
data: "fields alpha_channel,animated,checksum,game,height,image_id,url,width;"
})
.then(response => {
//console.log(response.data);
const testing = response.data;
res.json(testing);
})
.catch(err => {
console.error(err);
});
});
I tried changing the "data.results" to just data but it doesn't work. The client is not getting anything from the node js server.
It can also be noted that I was able to successfully receive information from another client project that looked like this:
class App extends React.Component{
constructor(props){
super(props);
this.state = {apiResponse: ""};
}
callAPI() {
fetch("http://localhost:9000/coverInfo")
.then(res => res.text())
//.then(res => console.log(res.json))
.then(res => this.setState({apiResponse: res}));
}
componentWillMount(){
this.callAPI();
}
render(){
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
</header>
<p>
{this.state.apiResponse}
</p>
</div>
);
}
}
export default App;
This returned the following text at the bottom of a webpage:
[{"id":110592,"alpha_channel":false,"animated":false,"game":96367,"height":800,"image_id":"co2dc0","url":"//images.igdb.com/igdb/image/upload/t_thumb/co2dc0.jpg","width":800,"checksum":"04a45b3f-4f90-f4a1-cc0d-1483f0cc2612"},{"id":65483,"game":100547,"height":800,"image_id":"pkkd08qhfxt5cosp3hra","url":"//images.igdb.com/igdb/image/upload/t_thumb/pkkd08qhfxt5cosp3hra.jpg","width":1260,"checksum":"e09f916b-04fe-8993-594e-b18435438a35"},{"id":96891,"alpha_channel":false,"animated":false,"game":132099,"height":933,"image_id":"co22rf","url":"//images.igdb.com/igdb/image/upload/t_thumb/co22rf.jpg","width":700,"checksum":"2452703f-4092-bb6f-d52c-51eb30a4ab94"},{"id":9331,"game":8938,"height":750,"image_id":"ikjcylxero1pb1sl9clj","url":"//images.igdb.com/igdb/image/upload/t_thumb/ikjcylxero1pb1sl9clj.jpg","width":640,"checksum":"0519ea95-feda-c674-1e6a-88a388ba5899"},{"id":900,"game":194,"height":362,"image_id":"fl0bjezupibkettkmsyg","url":"//images.igdb.com/igdb/image/upload/t_thumb/fl0bjezupibkettkmsyg.jpg","width":300,"checksum":"ffbf4f5b-99b9-eab3-1eb6-ea7f4f9c2df1"},{"id":28001,"game":46426,"height":2156,"image_id":"arzwj3bju1aoakgufnku","url":"//images.igdb.com/igdb/image/upload/t_thumb/arzwj3bju1aoakgufnku.jpg","width":1539,"checksum":"fb9fae9b-d717-d1d1-a3ee-ef6191af168d"},{"id":6424,"game":2410,"height":150,"image_id":"y7otr2cfclfpfuhtzhzq","url":"//images.igdb.com/igdb/image/upload/t_thumb/y7otr2cfclfpfuhtzhzq.jpg","width":342,"checksum":"d41815d5-85a7-ac17-c067-ac88563578e9"},{"id":15242,"game":18896,"height":360,"image_id":"dq7tvq2dub1xj0jnqafe","url":"//images.igdb.com/igdb/image/upload/t_thumb/dq7tvq2dub1xj0jnqafe.jpg","width":480,"checksum":"35bd8f63-6766-5426-d7c2-aaa34e8d8a19"},{"id":6432,"game":6264,"height":341,"image_id":"rii076tdl6uy1tnhohsg","url":"//images.igdb.com/igdb/image/upload/t_thumb/rii076tdl6uy1tnhohsg.jpg","width":500,"checksum":"f48c9e58-b52f-382b-9d92-4031e5a5a15c"},{"id":27255,"game":48063,"height":2100,"image_id":"unmgn234f5uesld8nfcn","url":"//images.igdb.com/igdb/image/upload/t_thumb/unmgn234f5uesld8nfcn.jpg","width":1528,"checksum":"fec3c3a3-6edd-5a35-5440-f1a19455a9
Would be helpful to see your server side code if possible. cause seeing your
server response i think you should be just using data rather than data.results as your provided JSON is just data and has no other object (i might be wrong on the terminology here).
Because to use data.results you should have:
{
"results": [{
"id": 110592,
"alpha_channel": false,
"animated": false,
"game": 96367,
"height": 800,
"image_id": "co2dc0",
"url": "//images.igdb.com/igdb/image/upload/t_thumb/co2dc0.jpg",
"width": 800,
"checksum": "04a45b3f-4f90-f4a1-cc0d-1483f0cc2612"
}, {
"id": 65483,
"game": 100547,
"height": 800,
"image_id": "pkkd08qhfxt5cosp3hra",
"url": "//images.igdb.com/igdb/image/upload/t_thumb/pkkd08qhfxt5cosp3hra.jpg",
"width": 1260,
"checksum": "e09f916b-04fe-8993-594e-b18435438a35"
}]
}
And your comment specifying your console doesn't log anything gives me more confidence in my answer
Here is the code that you can use to use data.results (Under presumption that you are using nodeJS)
res.send({results: yourjsondata}).status(200)
And to avoid your app constantly crashing if you get no data (Good practice for production too).
const {data} = await axios.get('http://localhost:9000/coverInfo')
if(data.results){
setGames(data.results)
console.log(data.results)
}else{
console.error("No data received from server")
I was able to get it working by not using localhost as the url because it was not loading on the android emulator.
The code that I used looked like this:
async function fetchGames() {
try {
const {data} = await axios.get('http://10.0.2.2:9000/coverInfo')
//console.log("ata", data)
setGames(data)
} catch (error) {
console.log("error", error)
Alert.alert('Error getting users', '', [{text: 'Retry', onPress: () => fetchGames()}])
}
}

Getting error dia.ElementView: markup required from graph.fromJSON(json)

While doing one of my assignment where I want to draw diagram form json with help of rappidJS/JointJS. I was referring to below link
https://resources.jointjs.com/tutorial/serialization
I am getting below error
dia.ElementView: markup required
The json I am using to populate is
{
"cells": [{
"type": "standard.Rectangle",
"position": {
"x": 70,
"y": 70
},
"size": {
"width": 70,
"height": 70
},
"angle": 0,
"id": "79e30352-ad4f-417a-807a-0427d605a9f4",
"z": 1
}]
}
and the graph and paper code are as follow
var graph = new joint.dia.Graph;
var paper = new joint.dia.Paper({
width: $('.paper-container').width(),
height: $('.paper-container').height(),
gridSize: 10,
drawGrid: true,
model: graph,
interactive: {linkMove: false},
defaultLink: new joint.dia.Link({
attrs: { '.marker-target': { d: 'M 10 0 L 0 5 L 10 10 z' }}
}),
async: true
});
and the error I am getting is
Uncaught Error: dia.ElementView: markup required
at child.renderMarkup (rappid.min.js:14)
at child.render (rappid.min.js:14)
at child.e.render (rappid.min.js:14)
at child.confirmUpdate (rappid.min.js:14)
at child.updateView (rappid.min.js:14)
at child.updateViewsBatch (rappid.min.js:14)
at child.updateViewsAsync (rappid.min.js:14)
I am using Rappid 3.0 version here.
Make sure you have the cellNamespace of the graph set on creation and also have the
cellViewNamespace of the paper set.
const graph = new joint.dia.Graph({}, {cellNamespace: joint.shape});
const paper = new joint.dia.Paper({model: graph, cellViewNamespace: joint.shapes});
After that, make sure that all custom element extends are on the joint.shape object. So if you have a custom element defined like so:
const NewElement = joint.dia.Element.define("node.NewElement", {size: {width:70,height: 70},... });
Then ensure that the node.NewElement element is on the joint.shapes object like this.
joint.shapes.node = {}; joint.shapes.node.NewElement = NewElement;

It is possible an synchronous mysql query in nodejs?

I try find solutions like "Promices" or modules like "synchronize" or "sync", but I donsen't fine a properly solution ):
The way its I have like 10 tables 'user', 'data', 'game'. And functions like:
getUsers(){} // UserTable
getData(){} // DataModel
getGames(){} // GameTable
getUserByGames(){} // UserModel
And some funtions have needs to return me a model or table... and in some cases I need that model or that 'answer' to make another query and another stuff.
So, i need to do synchronous querys to make that in the best way, no use '.then' or stuff like that :/
Did you know how I can doit in nodejs?
(Maybe a solution can be put a flag in true each async function and in the callback change the flag to false. With a while for dosent end the original function?)
You can mix callbacks, sequential and parallel execution, loops, recursion with SynJS. Here is an example to illustrate:
var SynJS = require('synjs');
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'tracker',
password : 'tracker123',
database : 'tracker'
});
function runSQLQuery(modules,connection,context,query,queryParams) {
var res = {done: false};
connection.query(query,queryParams, function(err, rows, fields) {
res.err = err;
res.rows = rows;
res.done = true;
//console.log('got rows:',rows);
modules.SynJS.resume(context);
});
return res;
}
function myFunc(modules,connection) {
for(var i=0; i<3; i++) {
console.log('Iteration:',i);
// sequential execution
var res1 = modules.runSQLQuery(modules,connection,_synjsContext,"SELECT 100+? as id",[i]);
SynJS.wait(res1.done);
console.log("res1=", res1.rows);
var res2 = modules.runSQLQuery(modules,connection,_synjsContext,"SELECT 200+? as id",[i]);
SynJS.wait(res2.done);
console.log("res2=", res2.rows);
// parallel execution
var res3 = modules.runSQLQuery(modules,connection,_synjsContext,"SELECT 300+? as id",[i]);
var res4 = modules.runSQLQuery(modules,connection,_synjsContext,"SELECT 400+? as id",[i]);
SynJS.wait(res3.done && res4.done);
console.log("res3,4=", res3.rows, res4.rows);
}
};
var modules = {
SynJS: SynJS,
mysql: mysql,
runSQLQuery: runSQLQuery,
};
SynJS.run(myFunc,null,modules,connection,function () {
console.log('done');
connection.end();
});
It produces following output:
Iteration: 0
res1= [ { id: 100 } ]
res2= [ { id: 200 } ]
res3,4= [ { id: 300 } ] [ { id: 400 } ]
Iteration: 1
res1= [ { id: 101 } ]
res2= [ { id: 201 } ]
res3,4= [ { id: 301 } ] [ { id: 401 } ]
Iteration: 2
res1= [ { id: 102 } ]
res2= [ { id: 202 } ]
res3,4= [ { id: 302 } ] [ { id: 402 } ]
done

How to change x-axis label in Stacked Area Chart NVD3.js? [duplicate]

I have a simple line graph with data in the format:
[
{
label: "lebel1",
x: 0,
y: 128
},
{
label: "lebel1",
x: 1,
y: 128
},
....
{
label: "lebel2",
x: 25,
y: 128
},
....
{
label: "lebel8",
x: 285,
y: 128
},
....
}
and I pass this into my nvd3 object:
nv.addGraph(function()
{
var chart = nv.models.lineChart();
chart.xAxis
.axisLabel("My X-Axis")
.ticks(36)
.tickFormat(function(d) { return d; });
chart.yAxis
.axisLabel('Voltage (v)')
.tickFormat(d3.format('.02f'));
d3.select('div svg')
.datum(myData)
.transition().duration(500)
.call(chart);
nv.utils.windowResize(function() { d3.select(gridSvgId).call(chart) });
return chart;
});
How can I have my x-axis ticks to show:
* eight labels: label1 - label8
Rather than have the grids broken up into a variable number of lines?
Try something like this
chart.xAxis.tickValues(['Label 1','Label 2','Label 3','Label 4','Label 5','Label 6','Label 7','Label 8']);
or if you want to get it from the dataset, you could try something like this,
chart.xAxis.tickValues(function(d) {
// do all you stuff and return an array
var dataset = ['Build Array from data'];
return dataset;
};)
Hope it helps