« first day (3294 days earlier)      last day (1640 days later) » 
01:00 - 08:0008:00 - 00:00

1:27 AM
hola
my brain is frezzing up as I have a question
is there a way to take an object array and filter out duplicates but keep a certain duplicate over the others
if that makes any sense
 
1:42 AM
nm got it!!! love you guys miss you
 
 
2 hours later…
3:33 AM
@ShrekOverflow Whats wrong with links as buttons?
whats a better way to add links to buttons without js?
 
3:45 AM
@Neil Hey buddy, thanks a lot for your guidance. I have coordinate nodes working perfectly now.
All the paths can be found, and it finds the shortest path from the list of paths from the recursive function calls.
 
 
3 hours later…
6:19 AM
@HassanAlthaf take a step back there. I gave you an algorithm for finding all paths, not just the shortest
you'll need to calculate the distance afterwards and pick the path with the lowest distance
 
6:49 AM
@Neil Yes, I've done that already.
totalDistance += Math.sqrt(Math.pow(path[i].x - path[i + 1].x, 2) + Math.pow(path[i].y - path[i + 1].y, 2));
Iterate through every point and add up the total distance.
let totalDistance = 0;

            for (let i = 0; i < (path.length - 1); i++) {
                // Formula: sqrt[(x0 - x1)^2 + (y0 - y1)^2]
                totalDistance += Math.sqrt(Math.pow(path[i].x - path[i + 1].x, 2) + Math.pow(path[i].y - path[i + 1].y, 2));
            }
 
@HassanAlthaf nice
looks like you've obtained what you were looking for
 
Yes, thanks to you.
 
If you want it a little faster, you don't have to do the Math.sqrt at the end
 
the reason is because two points which are farther away will always result higher than two points which are closer together using that formula, regardless of whether or not you called Math.sqrt
actually come to think of it, is that true? that may not be actually
that would make longer lines "weigh" more
 
6:51 AM
It may not be, square root is not a linear function.
 
nevermind, leave it as it is
 
You can see the thing I'm working on right now at GitHub.
 
what I said is true only if you're not summing the distances
 
The function to add up distances.
Got permission to open-source the library :D
The next step would be making the elevator system.
/staircase.
I was guessing to do something like "floorChanger" and have direction (up|down|bi)
and how many floors you could go in that said direction incase an elevator can only go 3 up, but u need to go 5.
 
oh dear, you need to consider this too?
 
6:56 AM
it's a real app... have to consider every possible scenario...
 
you need to create a special type of room called an elevator, which specifies a range of floors it covers
 
Yeah, I think range should do it instead of direction.
and if I need to switch the floors,
 
actually no, this can get complicated very fast
 
suppose you cannot reach the destination floor, but there are two elevators..
the first can take you to the 5th floor from the ground floor, while the other takes you only to the 3rd floor
 
6:57 AM
what would the destination floor?
floor be*?
 
if you just assume the elevator taking you to the 5th floor is better, there may be no other elevators on that floor
 
5?
also true haha
 
for the sake of argument 10
So also the elevators is a pathfinding problem
 
so you need to find an elevation path. the most efficient one.
 
you can make this work by connecting all elevator floors just like you've done with the hallways and the rooms
then you have just one big graph
 
6:59 AM
with z-inedx.
 
it's slower, but your algorithm also works for this
 
z-index*
 
You can assume the distance between floors is 0
this way it won't factor in
in your algorithm, you'll have to simply check if the two nodes you're calculating for distance are both elevator nodes, in which case you use 0 instead
 
Yes, we only consider the distance between a building an elevator or an elevator to an elevator.
Oh.
I was thinking, separate everything by floors.
 
well me too
 
7:01 AM
let currentLevel = 0; // default 'G' floor.
 
but that complicates things
if you start having elevators which skip floors or don't reach the top floor
you can't handle that easily
in your model, represent elevators like your graph, so node for elevator at floor 1 and node for elevator at floor 2, then node for elevator at floor 2 to node for elevator at floor 3, etc
 
the actual json of your config can be elevator: { startFloor: 0, endFloor: 10 }
and you create the nodes yourself
 
I was thinking.
 
doing it this way lets you change it later without modifying the algorithm
 
7:03 AM
Instead of having nodes for the elevator to jump up/down
We already know start/endfloor. We use algorithm to find the best elevator setup.
Then show the path to the elevator
 
oh your building has multiple elevators?
 
And once they hit the elevator
Go up, once they reach the final elevator. Route from elevator to building
I mean elevator to room.
@KarelG Yes.
 
@HassanAlthaf ok, but again, what happens if you implement it this way and tomorrow someone says "this elevator doesn't arrive at floor -1"
 
Well before we do anything,
We find an elevator config
 
using a graph is the most flexible approach
 
7:06 AM
The elevator algorithm would figure out the possible elevator/staircase combination
(elevator preferred over staircase).
and like we have a list of paths,
 
the elevator/staircase combination is just the graph pathfinding problem all over again
 
you're trying to reinvent the wheel
add it to your existing graph and it still works
 
so going higher up,
will still be the same graph.
just re-drawing the graph
 
an elevator node is just a regular node with the same x/y coordinate
 
7:07 AM
Can we assume an elevator has the same x/y coordinate
 
probably easier that way too, because you wouldn't need to care if it is an elevator
 
Building layout is quite different in every floor.
 
calculating distance would result in 0
I'd do the same for staircase
though you may want there to be a "distance"
 
17
Q: using ajax beforeSend to modify data

devzeroLet's say I have an Ajax call from jQuery like this: $.ajax({ url: myUrl, data: myData, type:'post' }); I would like to be able to add to the myData using $.ajaxSetup({ beforeSend: function(call){...} }); The result should be that all ajax calls (both post and get) is modified...

 
That sounds like a good idea.
 
7:08 AM
@Shad Welcome to the JavaScript chat! Please review the room rules. If you have a question, just post it, and if anyone's free and interested they'll help. If you want to report an abusive user or a problem in this room, visit our meta.
 
I don't have to estimate the distance that needs to be travelled.
 
you could add the z coordinate, and that would allow maximum flexibility
then you could optionally provide an x,y coordinate or also an x,y,z coordinate
 
What can I do to modify my data before it gets serialized?
 
yeah, by default we have z as 0.
If they don't touch z, everything is on the same floor.
If there's a z, we have different floors.
Is that what you mean?
 
@Shad just modify your data
 
7:10 AM
So if current elevation is z = 0
We draw the stuff for z
 
actually, beforeSend may not be a way you can just change data before sending it so just do it before you call $.ajax
@HassanAlthaf yes exactly
if someone wants a staircase to have "distance"
 
Omg, why are you so good man.
 
they can do that by giving it a z axis do the nodes
 
By the way
If I was to simulate distance of a staircase,
How would I do that?
The displacement would only be +1 z
So we'd need a value for z if it was staircase, right?
Or should I do logic, suggest elevator over staircases.
 
7:12 AM
meh, I'd let them worry about that
they just provide the z value
 
And show staircases as slower.
 
imho, I wouldn't bother
most staircases are next to elevators anyway
so it probably won't matter
 
@HassanAlthaf wait until they asked to give an opt-in for staircases
"being healthy" ya know
 
Those are the only options
 
7:13 AM
Oh, ya. In the UI they could configure.
 
have a flexible model and you can make any new "features" work :)
 
don't bother with it
 
haha lol
 
x, y, z coordinates are maximum flexibility :P
 
The thing is.
I'm the one doing the mobile app LOL
 
7:13 AM
just keep it simple but functional with expand-ability in mind
 
So, I wanted to talk about the architecture.
I was thinking having JS for the map-rendeing.
rendering*
And path-finding.
 
@JBis You've copied Zirak's sandboxing code?
 
The data to be stored in a RDBMS like MSSQL/MySQL, whatever they opt in for.
 
I wouldn't necessarily do that with node, you have better sandboxing options there
 
Of course all this is flexible, you just need to pass in data to the library as JS Objects.
 
The data is taken from the DB, parsed and passed to the library and data is showed.
So, on my mobile app, I'd just do something like an <iframe> through the WebAPI that I'd do with PHP or whatever I use for the server-side
Right?
Or is there a simpler way?
 
iframes would probably be the best approach for dropping widgets into pages
 
But that would be in Android.
 
that's what google maps does for their interactive map widgets
 
So I'm guessing, it's gonna be calld WebView or something?
 
7:18 AM
first make the library do everything you require
then you can make the web application that uses it
 
yup
that's the plan :)
 
but keep them separate
 
@MadaraUchiha Ben (Fortune) has already an approach in node.js
he can use it
 
Hey Neil, this question would be somethnig related to SVG
Can you set the zoom of SVGs?
So everything fits in the page?
 
@KarelG What is Ben using?
If it's Node's native vm that's not considered a secure sandbox
 
7:21 AM
@HassanAlthaf I think you can use javascript to set it to fill the page
but there's no zoom for filling the page to my knowledge
 
@Neil
 
also a browser will show a svg as the entire page if what gets returned is only a svg file
 
@Neil how'd that be? What do you call this kind of thing? I can't find any resource on this matter.
I do only an <svg> tag
Inside body. Should I change that?
 
86
Q: How to scale SVG image to fill browser window?

MiralThis seems like it ought to be easy, but I'm just not getting something. I want to make an HTML page containing a single SVG image that automatically scales to fit the browser window, without any scrolling and while preserving its aspect ratio. For example, at the moment I have a 1024x768 SVG i...

 
I meant this.
Do you see the big brown box in the bottom?
Next to it is a black box, that cannot fit into the screen. It just continues.
Can I make the SVG to scale and display the whole thing?
 
7:26 AM
when you're generating the svg, you don't add rooms to a fixed box
the size is the maximum width and height of all rooms/hallways added
so that there won't be a black box
 
No, wat I meant is, that black-box too needs to be visible.
It's a room as well.
I made the SVG so that it does 100% width, 100% height of the website.
 
well again, I repeat.. doing what I suggest would ensure that the size is the maximum width and height of all rooms/hallways added
 
Ok, but lets say the screen width is 1920
But the actual width is 2500
 
the svg is stretched to fit the page
 
How'd I tackle the extra 580 pixels?
 
7:28 AM
and the svg is only as large as the content
so if you add a room, the rest will shrink accordingly
 
It doesn't unfortunately.
 
well that's what you should try to obtain :P
 
How would I do that
 
what I linked earlier will make it so that your svg stretches to the page
 
Yes.
But the black box still gets cut off.
 
7:29 AM
all you have to do is generate your svg and ensure its width and height will always include the content you add
you can make a svg with width 16 pixels by 16 pixels, and add a box 1024 by 1024 in it
the svg will clip it in that case
you need to make sure the width becomes 1024 by 1024
 
Yes, it clips it off.
 
understand?
 
So, do I need to resize all the boxes?
 
the width and height of your svg varies
 
I get the width and height of the display.
Get a ratio of the required screen size
 
7:31 AM
not of the display
the svg stretches
 
I mean the available screen
 
don't consider the size of the display
 
size of the svg?
 
yes
 
so if that example, it's 100%.
 
7:31 AM
if it is larger than the page, it will shrink it to fit the page, I promise
you need to declare where the content is in your svg by setting its height and width
 
I just do getElementById("map") // Get the width and height.
 
@HassanAlthaf ok, returning back to my example earlier..
Suppose you create a svg of size 16 x 16 that stretches to the full page
 
everything in the first 16 pixels of width and height are shown to the user on the full page
 
Right.
 
7:32 AM
despite the fact that your svg has a lot more content perhaps
 
But, I want the whole thing
 
so in a sense, the 16x16 of the svg is your view of the image
 
To be shown.
 
ok, so change it
it's arbitrary, but it depends on how you made the svg
it has nothing to do with page size ok?
 
7:34 AM
@MadaraUchiha ugh, I did not even got time to go through his project. I only know that he was working on a serverside Caprica. But it has been a year ago TMK
 
So what would you recommend me
 
not sure if his project is still on GH. Gotcha check it
 
Specific lines for how I create the SVG>
I have the styling from what u recommended.
 
if you fit everything you design into that 16x16 square, it will all be visible on your page
take what I've told you and apply it, I won't write it for you
 
I don't understand.
Should I give the SVG a fixed size?
 
7:36 AM
the size of the svg is arbitrary..
 
So, I don't define the sie?
size*
 
if I so wanted, I could make a svg existing entirely in one pixel.. with every shape existing between 0 and 1
 
I define it after adding all elements, and adding up the totals?
 
that svg gets stretched to the entire page size and it would show it perfectly
you decide the size based on what you put in your svg
the svg size dictates the size it would have if it weren't stretched
but if you're stretching it, it's arbitrary
 
Could you please give me a reference to this? I can't grasp this concept.
 
7:38 AM
do some experimenting. Change the size of your svg arbitrarily and you'll see what I mean I think
 
It just cuts off the content.
It doesn't stretch. I did width of 2000px too which should cover everything,
But still the content gets cut off when the screen's last column of width has been occupied.
 
@BenFortune where is your serverside caprica project?
 
@HassanAlthaf There is content width/height, svg width/height and page width/height
 
svg width/height will clip content width/height and page width/height will clip svg width/height unless you stretch it
 
7:42 AM
You see the first one, 50x25, it gets cut off that's the problem I am facing. How do I make the contents of the svg re-size them-selves.
 
You make the svg width/height equal to the maximum content x and y values to fit everything in perfectly, understand?
200x100 is larger than the content and 50x25 is smaller..
 
Yes, I've done that.
Maximum width is 600px
 
well you didn't otherwise it wouldn't clip the black box
 
maximum height is 240px
Should I define that in CSS? Or HTML?
 
focus on making the svg perfectly fit its content
once you have that, use css to make the svg fit the page
and you're done
it doesn't matter what the size is of the content.. just that the svg width/height perfectly fits its content. period
 
7:45 AM
I'm confused man. I still don't get yo.
 
which part of this is confusing?
 
Let me try to run over what I understand so far.
And you can correct me.
My SVG is 600x240px
My screen width is 1366x768px
For some reason, the svg gets cut off at the 310-320-ish mark because it's soo zoomed in.
 
if you're using zoom, remove it
i don't know what impact that has, but probably not good
what is 310-320-ish mark? x coordinates?
 
yes pixels
I'm not using any zoom.
How do I explain man.
 
so your 600px svg is getting clipped after the 300 x pixel mark?
so half your svg is gone?
 
7:50 AM
svg's width and height are set to 100%
 
@HassanAlthaf ok, well I believe it.. your svg is 600 pixels wide
how can you show content of a black box 2000 pixels wide?
 
i was giving an example
 
6 mins ago, by Neil
focus on making the svg perfectly fit its content
 
So, lets say, if my svg is 1000*500
 
to make it show everything, your svg would have to be 2000x240px
 
7:52 AM
and my contents are 2000*1000
 
at least per your example
@HassanAlthaf then you're showing a fourth of your content
 
I chop their dimensons and coordinates into half?
 
content is 2000x1000, then your svg width/height must be 2000x1000 to show everything
 
So, if I have something 2000 pixels wide, 100 pixels height, i make it 1000*50
 
^
your best approach is to follow Neil's suggestion
 
7:53 AM
@HassanAlthaf why would you make it 1000x50?
explain me the logic behind that?
 
once you got that solution, you can apply CSS to have the window smaller with a zoom functionality
and draggability
 
Lets say I have an SVG width=100% height=100%
 
good problem solving = thinking in steps
 
^of the screen
 
imagine that you lay a sheet of paper on the ground and the floor itself is paper.. you can draw whevever you want, but the part of the image you can pick up and put on the refrigerator is ONLY what is on that sheet of paper
 
7:54 AM
Yes.
So how do I make the larger image smaller and make it fit on the sheet of paper.
 
so draw ON the sheet of paper only
 
I'm confused lol
 
sigh
forget page size for a second, it's irrelevant
 
you're making a drawing and you want it to show a nice little house and sun, and a little garden underneath.. so you make sure that the size of your image fits all the content
the image is the house with the sun and the little garden underneath.. it isn't just the sun in the top left corner
 
7:57 AM
I get what you mean by that.
 
you can draw anywhere you want, including hidden areas outside your designated width/height
 
You want me to make sure that the svg has a fixed width/height.
 
no..
 
And all the contents are ensured to fit within that.
No?
 
the svg width/height is arbitrary
you determine what is inside the drawing and what isn't
if you draw a black box 2000x1000 and make your svg dimensions 100x100, you're going to clip it off
 
7:58 AM
Neil you make it difficult for him
 
@KarelG take a crack at it if you think you can explain it better
 
Hassan, remove all dimension settings of your svg window
 
just draw your room(s)
and other things you want to draw on the svg
 
html, body {
            width: 100%;
            height: 100%;
            margin: 0 !important;
            padding: 0 !important;

        overflow:hidden }
        svg { position:fixed; top:0; bottom:0; left:0; right:0 }
And I have that CSS.
 
7:58 AM
delete that
 
now write code to draw your svg until you got everything on it
 
Defaults to 300x150
 
01:00 - 08:0008:00 - 00:00

« first day (3294 days earlier)      last day (1640 days later) »