-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic Data + Advance Dynamically #12
Comments
Hey @toomas1968 thanks for checking out my code! So if I understand correctly, you are wanting to store/fetch the JS bracket in a tabular DB like mySQL, and the issue is when you store the entries that go on to the next round. Quick&DirtyIf you have a column with
so you know b and c are facing off in the final... PROBLEM - the problem with this though, is that your order might not be easy to preserve, and it could be a bother to have each round jumbled up, and you would have to jump around to see the player's previous matches. Sol? - I think you might be able to fix this problem by assigning a previous division like they do in sports with Northwest/Southeast conferences.
|
Hi again @XDwightsBeetsX . You are absolutely right. The Round 1 order is actually defined by fixed order meaning that drivers round 1 position are ordered according to predefined template. Perhaps I am overthinking it but I see couple issues ...
Do you think you could perhaps give me some sort of code example? |
NowDefault Bracket Construction
// Bracket.constructor()
// swap prettyEntries to set byes by default
for (let i = 1; i < nearestP2/2; i+=2) {
let swap = prettyEntries[i];
prettyEntries[i] = prettyEntries[nearestP2-i];
prettyEntries[nearestP2-i] = swap;
}
// determine bracket dimensions
let nearestP2 = 2**(Math.ceil(Math.log2(entries.length)))
this.Height = 2*nearestP2 - 1;
this.Depth = Math.log2(nearestP2) + 1; SuggestedSo to be able to update this dynamically, I think you should add a property to the each
function getEntriesInRound(int round) {
// hold the entries that are in this round
let roundEntries = [];
// go through and add entries that match the given round
for (int i = 0; i < this.RawEntries.length; i++) {
let e = this.RawEntries[i];
if (e.Round == round)
roundEntries.push(e);
}
return roundEntries;
}
|
Hi, Sorry but is somewhat still unclear to me. Particularly the part "do whatever you want with the entries in a round". Issue is that currently I don't see where I can add part where I can set return roundEntries; as a second row or third row etc. Currently the main logic goes to makeBracket() method in Bracket.js (tho I have modified it to fit my needs) Your suggestion does indeed return the list of entries that are in range of specified round. The 'round' is in your case Depth(right?) so comparing the entries to Depth and returning the corresponding list works. But then pushing this to the roundEntrie will result infinite loop where page crashes. (As I mentioned before. My limited JS skills) Check example below. As soon as I push entries. Site crashes. This loop is currently in makeBracket method. PS for example purpose I use prettyEntries but as soon as I get this logic working I will optimize the code to use rawEntries
Where would you add such logic in your current state of code? Thank you in advance and big thanks for helping me out in a first place :P |
Hi, I have tried several ways but still no luck. As you said in your last answer, math is mostly the blocker here. I am not a quitter but I think I am quitting this project of mine. Regardless your application did help me a lot so thank you for that :) As for math I though that since the Visual Graph goes like this
I thought that I would simply loop through Height again with i+=4 for second round etc and then loop through entries. Then if entries.round = 2 then somehow push? entries to second row. But this is the part where I got stuck and I have not been able to solve the issue. "NOTE: this will take some math. Note that every other row in the bracket is in the second round, and every fourth is in the third, and so forth. this is why Depth is important." |
All good @toomas1968 !
// Bracket
constructor(entries) {
this.RawEntries = deepCopy(entries);
// determine bracket dimensions
let nearestP2 = 2**(Math.ceil(Math.log2(entries.length)))
this.Height = 2*nearestP2 - 1;
this.Depth = Math.log2(nearestP2) + 1;
// make a filled list of Entries with BYEs
let prettyEntries = deepCopy(entries);
for (let i = prettyEntries.length; i < nearestP2; i++) {
prettyEntries.push(new Entry(BYE));
}
// swap prettyEntries to set byes by default
for (let i = 1; i < nearestP2/2; i+=2) {
let swap = prettyEntries[i];
prettyEntries[i] = prettyEntries[nearestP2-i];
prettyEntries[nearestP2-i] = swap;
}
// add in TBDs to prettyEntries
for (let i = 1; i < prettyEntries.length; i++) {
if (i % 2 == 1) {
prettyEntries.splice(i, 0, new Entry(TBD));
}
}
this.PrettyEntries = prettyEntries;
// fill initial bracket
this.makeBracket();
}
|
HI again. Do you think this is something that you will reopen and perhaps investigate by any chance? |
Hey @toomas1968! Sorry to say I don't think I will contribute to this issue, but if you would like to open a new issue and branch to add this feature, feel free! |
So I got the thing working exactly as I wanted. Wanted to say big thanks for your existing solution because it did give me a lot of new ideas and was very good example. One thing tho ... How would you add lines between .be boxes? So like in Tournament Bracket you see these lines between boxes indicating which pair is together and so forth? |
Oh nice @toomas1968! If you think this is something that could help others, feel free to make a pull and share! Well, that's something I initially thought about when making the site! It was easier to just make the Maybe from this picture you can see the issue... It could be easier to add elements made up of only a |
@XDwightsBeetsX I will think about it. The reason why I hesitate is because my solution is very custom. It requires to have Array items in certain order. For example API provides me array with currentPosition field what has participants in certain order. I will just order my array with the currentPosition asc and then will loop array. In fact it is not best solution but I will do loop for each round. If you are interested in checking my solution out then I can for sure commit it to my github and then lets go from there :P As for the lines I tried to implement https://codepen.io/grozzzny/pen/GRZNxqW example (silly me) but my CSS skills + JS skills are very very bad so thats why I came here asking for help. This codepen example is using pseudo elements ::after and ::before to draw lines. Issue is that it is relatively hard to access first column (first child) and last column (last child) because the technique of the bracket solution :D Perhaps I am mistaken and it can be solved easily. |
Hi, First of all I want to say that this is very well done piece of code. But I need tips of how to make it fit my needs.
Lets say that the Data comes from the DB. Meaning that instead of
let prettyEntries = this.deepcopy(entries)
I have
let prettyEntries = this.deepcopy(DBARRAY)
Assuming that the DB has column "Round". If the ROUND would change from 1 -> 2. How would you display it in the table? Obviously it would need to proceed from 2 -> 3 and so on (to the final).
The data is predefined meaning that the info going TO the DB is correct. Example
if there is 16 drivers in round 1 then round 2 has 8 drivers, round 3 has 4 drivers etc.
How to make it reflect in the brackets?
I am currently trying to change your solution to dynamic data but my limited knowledge of JS is stepping in my way :D
The text was updated successfully, but these errors were encountered: