@sehgalsunny My apologies for the late response. your snippet provided above did nothing to help the situation, and even if it had, it would have made all events an even 100px apart, instead of the variable spacing shown in your demo pictures. I’ve come up with a fix myself. See below
/metabox.php
lines 66 – 69
// Stop debug.log from filling to the brim with undefined index notices.
if(isset($_POST['_inline_edit'])){
if (wp_verify_nonce($_POST['_inline_edit'], 'inlineeditnonce')) // KT - protect from custom fields clears while quick edit
return;
}
js/history.js
lines 21 – 24
//assign a left postion to the single events along the timeline
var totWidth = setDatePosition(timelineComponents, eventsMinDistance);
//assign a width to the timeline
var timelineTotWidth = setTimelineWidth(timelineComponents, totWidth);
lines 130 – 143
function setDatePosition(timelineComponents, min) {
var totWidth = 0;
for (i = 0; i < timelineComponents['timelineDates'].length; i++) {
var distance = daydiff(timelineComponents['timelineDates'][0], timelineComponents['timelineDates'][i]),
distanceNorm = Math.round(distance/timelineComponents['eventsMinLapse']) + 2;
var finalDist = Math.round((distanceNorm*0.1)+(min*(i+1)));
timelineComponents['timelineEvents'].eq(i).css('left', finalDist+'px');
totWidth = finalDist + min;
}
return totWidth;
}
lines 145 – 153
function setTimelineWidth(timelineComponents, width) {
var divWidth = $('.cd-horizontal-timeline').css('width').replace(/[a-z]/ig, "");
var totWidth = Math.max.apply(0, [width, divWidth]);
timelineComponents['eventsWrapper'].css('width', totWidth+'px');
updateFilling(timelineComponents['timelineEvents'].eq(0), timelineComponents['fillingLine'], totWidth);
return totWidth;
}
As you can see, I corrected the setDatePosition function to now create a fair distance between points, and return the last element’s final position plus the minimum width. From there I compare there total width returned from setDatePosition to the width of the parent div, and pick the maximum of the two for final width of the timeline.
Maybe this only works for large time frames, maybe not. Either way, I hope you learn from this, and I’d recommend you review your math next time to put out an update.
-
This reply was modified 6 years, 3 months ago by ghudson. Reason: formatting and added another part I fixed, metabox.php
-
This reply was modified 6 years, 3 months ago by ghudson. Reason: More formatting
-
This reply was modified 6 years, 3 months ago by ghudson.