Best JavaScript code snippet using wpt
DiscreetDataColumn.js
Source:DiscreetDataColumn.js
1define([2 'dojo/dom-construct',3 "dojo/_base/array",4 'dojo/_base/lang',5 "dojo/date/locale",6 'stalker/js/HeaderCell'7], function (domConstruct, array, lang, locale, draw_header_cell) {8 // module:9 // DiscreetDataColumn10 // summary:11 // A dgrid column plugin that generates box charts in a column.12 'use strict';13 /**14 * Render the given data under to the given parent15 *16 * The options.data should have the following methods:17 *18 * data_in_between(start, end)19 * showing the amount of data supplied20 * in between the start and end dates.21 *22 * data_labels(start, end)23 * showing the data labels24 *25 * data_scale()26 * showing the scale of the data27 *28 * @param options29 * @returns {*|jQuery|HTMLElement}30 */31 var draw_cell = function (options) {32 var parent = options.parent;33 var data = options.data;34 var start = options.start;35 var end = options.end;36 var scale = options.scale;37 var step_size = options.step_size;38 var step_unit = options.step_unit;39 var period_unit = options.period_unit;40 var height = options.height;41 var millies_possible_in_period = options.millies_possible_in_period;42 var original_start = moment(start).startOf('day');43 var start_date = moment(start).startOf(period_unit).startOf('day');44 var end_date = moment(end).endOf(period_unit).endOf('day');45 // find the start and end of the period46 var period_start = moment(start_date.startOf(period_unit));47 var period_end = moment(start_date.endOf(period_unit));48 var data_in_between;49 var log_bar, data_bar, data_value, data_labels;50 var log_bar_container;51 var parent_div = jQuery(jQuery.parseHTML('<div class="logContainer"></div>'));52 parent_div.css({53 width: Math.floor((end_date - start_date) / scale),54 left: Math.floor((start_date - original_start) / scale), // offset as necessary55 height: height,56 position: 'absolute'57 });58 jQuery(parent).append(parent_div);59 var added_first_data = false;60 var data_scale = data.data_scale();61 // calculate once62 var denominator = height / (millies_possible_in_period * data_scale);63 while (period_start < end_date) {64 // millies_possible_in_period * data.resource_count65 // works beautifully both for Departments and Resources, bravo!!!66 data_in_between = Math.min(millies_possible_in_period * data.resource_count, data.data_in_between(+period_start, +period_end));67 data_labels = data.data_labels(period_start, period_end);68 // draw a div at that range with the height of data_in_between69 added_first_data = true;70 log_bar_container = jQuery(jQuery.parseHTML('<div class="log_bar layout"></div>'));71 log_bar_container.css({72 left: Math.floor((period_start - start_date) / scale),73 width: Math.floor((period_end - period_start) / scale)74 });75 log_bar = jQuery(jQuery.parseHTML('<div class="log_bar log"></div>'));76 log_bar.css({77 height: Math.floor(data_in_between * denominator)78 });79 var total_hours = (data_in_between / 3600000).toFixed(0);80 data_bar = jQuery(jQuery.parseHTML(81 '<div class="data_bar" ></div>'82 ));83 data_value = jQuery(jQuery.parseHTML(84 '<div class="data_value"></div>'85 ));86 data_value.attr('data-content', data_labels).attr('data-rel', 'popover');87 data_value.text(total_hours);88 log_bar_container.append(data_bar);89 log_bar_container.append(log_bar);90 log_bar_container.append(data_value);91 parent_div.append(92 log_bar_container93 );94 // get the new start and end values95 period_start.add(step_size, step_unit).startOf(step_unit);96 period_end.add(step_size, step_unit).endOf(step_unit);97 }98 return parent_div;99 };100 var zoom_levels = {101 "h": {102 scale: 120000, // 1 hour is 30 px103 table_width: function (start, end) {104 var start_date = moment(start).startOf('day');105 var end_date = moment(end).endOf('day');106 return Math.floor((end_date - start_date) / this.scale);107 },108 headers: [109 {110 draw: function (parent, start, end) {111 return draw_header_cell({112 parent: parent,113 start: start,114 end: end,115 scale: 120000,116 step_size: 7,117 step_unit: 'day',118 period_unit: 'isoweek',119 height: 26,120 format: '[Week] w'121 });122 }123 },124 {125 draw: function (parent, start, end) {126 return draw_header_cell({127 parent: parent,128 start: start,129 end: end,130 scale: 120000,131 step_size: 1,132 step_unit: 'day',133 period_unit: 'day',134 height: 26,135 format: 'ddd, DD-MMM-YYYY'136 });137 }138 },139 {140 draw: function (parent, start, end) {141 return draw_header_cell({142 parent: parent,143 start: start,144 end: end,145 scale: 120000,146 step_size: 1,147 step_unit: 'hour',148 period_unit: 'hour',149 height: 26,150 format: 'H'151 });152 }153 }154 ],155 'chart': {156 'element_width': 30, // in px157 'draw': function (parent, data, start, end) {158 return draw_cell({159 parent: parent,160 data: data,161 start: start,162 end: end,163 scale: 120000,164 step_size: 1,165 step_unit: 'hour',166 period_unit: 'hour',167 height: 24,168 millies_possible_in_period: 3600000 // 1 hours for anima169 });170 }171 }172 },173 "d": {174 scale: 2880000, // 1 day is 30 px175 table_width: function (start, end) {176 var start_date = moment(start).startOf('day');177 var end_date = moment(end).endOf('day');178 return Math.floor((end_date - start_date) / this.scale);179 },180 headers: [181 {182 draw: function (parent, start, end) {183 return draw_header_cell({184 parent: parent,185 start: start,186 end: end,187 scale: 2880000,188 step_size: 1,189 step_unit: 'month',190 period_unit: 'month',191 height: 26,192 format: 'MMM YYYY'193 });194 }195 },196 {197 draw: function (parent, start, end) {198 return draw_header_cell({199 parent: parent,200 start: start,201 end: end,202 scale: 2880000,203 step_size: 7,204 step_unit: 'day',205 period_unit: 'isoweek',206 height: 26,207 format: '[Week] w'208 });209 }210 },211 {212 draw: function (parent, start, end) {213 return draw_header_cell({214 parent: parent,215 start: start,216 end: end,217 scale: 2880000,218 step_size: 1,219 step_unit: 'day',220 period_unit: 'day',221 height: 26,222 format: 'D'223 });224 }225 },226 {227 draw: function (parent, start, end) {228 return draw_header_cell({229 parent: parent,230 start: start,231 end: end,232 scale: 2880000,233 step_size: 1,234 step_unit: 'day',235 period_unit: 'day',236 height: 26,237 format: 'dd'238 });239 }240 }241 ],242 'chart': {243 'element_width': 30, // in px244 'draw': function (parent, data, start, end) {245 return draw_cell({246 parent: parent,247 data: data,248 start: start,249 end: end,250 scale: 2880000,251 step_size: 1,252 step_unit: 'day',253 period_unit: 'day',254 height: 24,255 millies_possible_in_period: 9 * 3600000 // 9 hours for anima256 });257 }258 }259 },260 "w": {261 scale: 21600000, // 1 week is 28 px262 table_width: function (start, end) {263 var start_date = moment(start).startOf('day');264 var end_date = moment(end).endOf('day');265 return Math.floor((end_date - start_date) / this.scale);266 },267 headers: [268 {269 draw: function (parent, start, end) {270 return draw_header_cell({271 parent: parent,272 start: start,273 end: end,274 scale: 21600000,275 step_size: 1,276 step_unit: 'year',277 period_unit: 'year',278 height: 26,279 format: 'YYYY'280 });281 }282 },283 {284 draw: function (parent, start, end) {285 return draw_header_cell({286 parent: parent,287 start: start,288 end: end,289 scale: 21600000,290 step_size: 1,291 step_unit: 'month',292 period_unit: 'month',293 height: 26,294 format: 'MMM'295 });296 }297 },298 {299 draw: function (parent, start, end) {300 return draw_header_cell({301 parent: parent,302 start: start,303 end: end,304 scale: 21600000,305 step_size: 7,306 step_unit: 'day',307 period_unit: 'isoweek',308 height: 26,309 format: 'w'310 });311 }312 }313 ],314 'chart': {315 'element_width': 28, // in px316 'draw': function (parent, data, start, end) {317 return draw_cell({318 parent: parent,319 data: data,320 start: start,321 end: end,322 scale: 21600000,323 step_size: 7,324 step_unit: 'day',325 period_unit: 'isoweek',326 height: 24,327 millies_possible_in_period: 183600000 // 51 hours for anima328 });329 }330 }331 },332 "m": { // 333 scale: 86400000, // 1 month is 30 px334 table_width: function (start, end) {335 var start_date = moment(start).startOf('day');336 var end_date = moment(end).endOf('day');337 return Math.floor((end_date - start_date) / this.scale);338 },339 headers: [340 { // years341 draw: function (parent, start, end) {342 return draw_header_cell({343 parent: parent,344 start: start,345 end: end,346 scale: 86400000,347 step_size: 1,348 step_unit: 'year',349 period_unit: 'year',350 height: 26,351 format: 'YYYY'352 });353 }354 },355// { // quarters356// draw: function (parent, start, end) {357// return draw_header_cell({358// parent: parent,359// start: +moment(start).startOf('year'),360// end: end,361// scale: 86400000,362// step_size: 3,363// step_unit: 'month',364// period_unit: 'month',365// height: 26,366// format: function (region_start, region_end) {367// return 'Q' + Math.floor(moment(region_start).month() / 4);368// }369// });370// }371// },372 { // months373 draw: function (parent, start, end) {374 return draw_header_cell({375 parent: parent,376 start: start,377 end: end,378 scale: 86400000,379 step_size: 1,380 step_unit: 'month',381 period_unit: 'month',382 height: 26,383 format: 'M'384 });385 }386 }387 ],388 'chart': {389 'element_width': 30, // in px390 'draw': function (parent, data, start, end) {391 return draw_cell({392 parent: parent,393 data: data,394 start: start,395 end: end,396 scale: 86400000,397 step_size: 1,398 step_unit: 'month',399 period_unit: 'month',400 height: 24,401 millies_possible_in_period: 183600000 * 4 // 204 hours for anima402 });403 }404 }405 },406 "y": { // 407 scale: 315360000, // 1 year is 100 px 31536000000/100408 table_width: function (start, end) {409 var start_date = moment(start).startOf('day');410 var end_date = moment(end).endOf('day');411 return Math.floor((end_date - start_date) / this.scale);412 },413 headers: [414 { // years415 draw: function (parent, start, end) {416 return draw_header_cell({417 parent: parent,418 start: start,419 end: end,420 scale: 315360000,421 step_size: 1,422 step_unit: 'year',423 period_unit: 'year',424 height: 26,425 format: 'YYYY'426 });427 }428 }429 ],430 'chart': {431 'element_width': 100, // in px432 'draw': function (parent, data, start, end) {433 return draw_cell({434 parent: parent,435 data: data,436 start: start,437 end: end,438 scale: 315360000,439 step_size: 1,440 step_unit: 'year',441 period_unit: 'year',442 height: 24,443 millies_possible_in_period: 9573418080 // 6 * 52.1428 * 51 * 3600000444 });445 }446 }447 }448 };449 return function (column) {450 // summary:451 // Updates a column definition with special rendering methods that452 // generate a gantt style chart.453 // column: Object454 // A column definition with the following special keys:455 // - start: Date|number456 // The start date of the gantt chart's viewport, either as a457 // Date object or in milliseconds since the Unix epoch.458 // - end: Date|number459 // The end date of the gantt chart's viewport, either as a Date460 // object or in milliseconds since the Unix epoch.461 // - scale: number462 // The number of milliseconds that one pixel represents.463 /**464 * Renders the today line under to the given parent465 * 466 * @param {object} parent467 * @param {number} start468 * @param {number} scale469 */470 var render_today = function (parent, start, scale) {471 var today = moment(new Date());472 var start_date = moment(start).startOf('day');473 var today_element = jQuery(jQuery.parseHTML('<div></div>'));474 today_element.addClass('today').css({475 left: Math.floor((today - start_date) / scale)476 });477 jQuery(parent).append(today_element);478 };479 /**480 * Calculates the number of div element going to be rendered for one481 * row when the start and end dates and zoom level is set to given482 * parameters. So one can use it to calculate how much is it going to483 * take.484 * 485 * @param start486 * @param end487 * @param zoom_level488 * @returns {number}489 */490 column.guess_element_count = function(start, end, zoom_level) {491 var table_width = zoom_levels[zoom_level].table_width(start, end);492 var element_width = zoom_levels[zoom_level].chart.element_width;493 return Math.floor(table_width / element_width);494 };495 /**496 * Converts the given start and end pixel values to start and end dates497 * in millies498 * 499 * @param start500 * @param end501 */502 column.convert_pixel_to_millies = function (start, end) {503 var scale = zoom_levels[column.scale].scale;504 var start_date = moment(column.start).startOf('day');505 return {506 start: start * scale + start_date,507 end: end * scale + start_date508 };509 };510 /**511 * Returns the best zoom level for the given start and end range512 * @param start513 * @param end514 */515 column.guess_zoom_level = function(start, end) {516 // get the zoom level with the desired scale so the range will have517 // around 100 boxes518 var range = end - start;519 var desired_element_count = 100;520 var min_ratio = 1e10;521 var current_ratio;522 var current_element_count;523 var desired_level = null;524 for (var level in zoom_levels) {525 if (level !== null) {526 current_element_count = this.guess_element_count(start, end, level);527 current_ratio = desired_element_count / current_element_count + current_element_count / desired_element_count - 2;528 if (current_ratio < min_ratio) {529 min_ratio = current_ratio;530 desired_level = level;531 }532 }533 }534 return desired_level;535 };536 /**537 * summary:538 * Renders a task.539 * object: Object540 * An object representing data with the following functions:541 * - data_in_between(start, end)542 * - data_labels()543 * - data_scale()544 *545 * @param data546 * Data547 * @param value548 * unused549 * @param {Object} td550 * DomNode551 */552 column.renderCell = function (data, value, td) {553 // wrap the data with the grid.wrapper554 var wrapped_data = new this.grid.data_wrapper(data);555 // render cells556 zoom_levels[column.scale].chart.draw(td, wrapped_data, column.start, column.end);557 // render today558 render_today(td, column.start, zoom_levels[column.scale].scale);559 560 // draw popover561 jQuery(td).find('[data-rel=popover]').popover({562 html:true,563 container: 'body'564 }).on('show.bs.popover', function () {565 // remove all the other popovers566 var self = this;567 jQuery('[data-rel=popover]').each(function(){568 if (this !== self) {569 jQuery(this).popover('hide');570 } else {571 jQuery(this).popover({572 trigger: 'hover'573 })574 }575 });576 });577 578 };579 column.refresh = function (options) {580 // summary:581 // Refreshes the header cell582 // remove the header contents583 // set some defaults584 options = lang.mixin(585 { // default values586 'start': column.start,587 'end': column.end,588 'scale': column.scale589 },590 options591 );592 domConstruct.empty(column.headerNode);593 column.renderHeaderCell(column.headerNode);594 column.start = options.start;595 column.end = options.end;596 column.scale = options.scale;597 // let it adjust the scroll bars598 column.grid.resize();599 };600 column.reload = function () {601 // summary:602 // reloads the grid data603 column.grid.refresh();604 };605 column.scrollToDate = function (date) {606 // scrolls to the given date607 var date_as_millis, date_x, scroller, scroller_width;608 date_as_millis = +date;609 var start_date = moment(column.start).startOf('day');610 date_x = (date_as_millis - start_date) / zoom_levels[column.scale].scale;611 scroller = jQuery('.dgrid-column-set-scroller-1');612 scroller_width = scroller.width();613 scroller.scrollLeft(date_x - scroller_width * 0.5);614 };615 column.centerOnToday = function () {616 // scrolls to today617 column.scrollToDate(new Date());618 };619 /**620 * Creates a header cell that contains the dates corresponding to the621 * time lines that are being rendered in the main content622 * 623 * @param {Object} th624 * DomNode625 */626 column.renderHeaderCell = function (th) {627 column.fetch_date_values();628 // fix scrolling629 var table_width = zoom_levels[column.scale].table_width(column.start, column.end);630 column.grid.addCssRule(".dgrid-column-chart", "width: " + table_width + "px");631 jQuery(th).css({632 width: table_width633 });634 // get element width635 // render headers636 var i;637 var header_count = zoom_levels[column.scale].headers.length;638 var parent_div;639 for (i = 0; i < header_count; i += 1) {640 parent_div = zoom_levels[column.scale].headers[i].draw(th, column.start, column.end);641 parent_div.css({642 top: i * 27643 });644 }645 // extend the height of the table header646 jQuery(th).css({647 height: header_count * 27 // 27 px each648 });649 // render today650 render_today(th, column.start, zoom_levels[column.scale].scale);651 };652 column.fetch_date_values = function() {653 if (column.scale === null || column.scale === undefined) {654 // get data from grid655 column.scale = column.grid.scale;656 }657 if (column.start === null || column.start === undefined) {658 // get data from grid659 column.start = column.grid.start;660 661 if (typeof(column.start) === 'function') {662 column.start = +column.start();663 } else {664 column.start = +column.start;665 }666 }667 if (column.end === null || column.end === undefined) {668 // get data from grid669 column.end = column.grid.end;670 671 if (typeof(column.end) === 'function') {672 column.end = +column.end();673 } else {674 column.end = +column.end;675 }676 }677 };678 return column;679 };...
photo-effects.js
Source:photo-effects.js
1const EFFECTS = {2 chrome: {3 FILTER: 'grayscale',4 OPTIONS: {5 range: {6 min: 0,7 max: 1,8 },9 start: 1,10 step: 0.1,11 },12 STEP_UNIT: ''13 },14 sepia: {15 FILTER: 'sepia',16 OPTIONS: {17 range: {18 min: 0,19 max: 1,20 },21 start: 1,22 step: 0.1,23 },24 STEP_UNIT: ''25 },26 marvin: {27 FILTER: 'invert',28 OPTIONS: {29 range: {30 min: 0,31 max: 100,32 },33 start: 100,34 step: 1,35 },36 STEP_UNIT: '%'37 },38 phobos: {39 FILTER: 'blur',40 OPTIONS: {41 range: {42 min: 0,43 max: 3,44 },45 start: 3,46 step: 0.1,47 },48 STEP_UNIT: 'px'49 },50 heat: {51 FILTER: 'brightness',52 OPTIONS: {53 range: {54 min: 1,55 max: 3,56 },57 start: 3,58 step: 0.1,59 },60 STEP_UNIT: ''61 },62};63const imgUploadFormElement = document.querySelector('.img-upload__form');64const effectsListElement = imgUploadFormElement.querySelector('.effects__list');65const imgUploadEffectLevelElement = imgUploadFormElement.querySelector('.img-upload__effect-level');66const effectLevelSliderElement = imgUploadFormElement.querySelector('.effect-level__slider');67const effectLevelValueElement = imgUploadFormElement.querySelector('.effect-level__value');68const imgUploadPreviewElement = imgUploadFormElement.querySelector('.img-upload__preview').querySelector('img');69// ÐнÑенÑивноÑÑÑ ÑÑÑекÑа ÑегÑлиÑÑеÑÑÑ Ð¿ÐµÑемеÑением ползÑнка в ÑлайдеÑе.70// Ð¡Ð»Ð°Ð¹Ð´ÐµÑ ÑеализÑеÑÑÑ ÑÑоÑонней библиоÑекой Ð´Ð»Ñ ÑеализаÑии ÑлайдеÑов noUiSlider.71noUiSlider.create(effectLevelSliderElement, {72 range: {73 min: 0,74 max: 1,75 },76 start: 1,77 step: 0.01,78 connect: 'lower'79});80// ÐÑи Ñмене ÑÑÑекÑа, вÑбоÑом одного из знаÑений ÑÑеди Ñадиокнопок .effects__radio,81// добавиÑÑ ÐºÐ°ÑÑинке внÑÑÑи .img-upload__preview CSS-клаÑÑ, ÑооÑвеÑÑÑвÑÑÑий ÑÑÑекÑÑ82const onEffectsListClick = (evt) => {83 // ФÑнкÑÐ¸Ñ Ð´Ð»Ñ ÑкалиÑÐ¾Ð²Ð°Ð½Ð¸Ñ ÑилÑÑÑов84 const applyFilterEffect = (effect) => {85 const effectStepUnit = EFFECTS[effect].STEP_UNIT;86 const effectStyle = EFFECTS[effect].FILTER;87 effectLevelSliderElement.noUiSlider.on('update', () => {88 // УÑÐ¾Ð²ÐµÐ½Ñ ÑÑÑекÑа запиÑÑваеÑÑÑ Ð² поле .effect-level__value89 effectLevelValueElement.value = effectLevelSliderElement.noUiSlider.get();90 imgUploadPreviewElement.style.filter = `${effectStyle}(${effectLevelValueElement.value}${effectStepUnit})`;91 });92 imgUploadEffectLevelElement.classList.remove('hidden');93 imgUploadPreviewElement.removeAttribute('class');94 imgUploadPreviewElement.classList.add(`effects__preview--${effect}`);95 // ÐÑи пеÑеклÑÑении ÑÑÑекÑов, ÑÑÐ¾Ð²ÐµÐ½Ñ Ð½Ð°ÑÑÑенноÑÑи ÑбÑаÑÑваеÑÑÑ Ð´Ð¾ наÑалÑного знаÑÐµÐ½Ð¸Ñ (100%):96 imgUploadPreviewElement.style.filter = `${effectStyle}(${EFFECTS[effect].OPTIONS.start}${effectStepUnit})`;97 // ÑлайдеÑ, CSS-ÑÑÐ¸Ð»Ñ Ð¸Ð·Ð¾Ð±ÑÐ°Ð¶ÐµÐ½Ð¸Ñ Ð¸ знаÑение Ð¿Ð¾Ð»Ñ Ð´Ð¾Ð»Ð¶Ð½Ñ Ð¾Ð±Ð½Ð¾Ð²Ð»ÑÑÑÑÑ.98 effectLevelSliderElement.noUiSlider.updateOptions(EFFECTS[effect].OPTIONS);99 };100 // ÐÐ»Ñ Ð¾ÑигиналÑного изобÑажениÑ101 imgUploadPreviewElement.removeAttribute('class');102 if (evt.target.id === 'effect-none') {103 // ÐÑи вÑбоÑе ÑÑÑекÑа «ÐÑигинал» ÑÐ»Ð°Ð¹Ð´ÐµÑ ÑкÑÑваеÑÑÑ.104 imgUploadEffectLevelElement.classList.add('hidden');105 // ÐÐ»Ñ ÑÑÑекÑа «ÐÑигинал» CSS-ÑÑили filter ÑдалÑÑÑÑÑ.106 imgUploadPreviewElement.style.filter = 'none';107 // ÐÐ»Ñ Ð¿ÑимененнÑÑ
ÑилÑÑÑов108 } else {109 const effectName = evt.target.value;110 applyFilterEffect(effectName);111 }112};113const accessEffects = () => {114 imgUploadEffectLevelElement.classList.add('hidden');115 effectsListElement.addEventListener('change', onEffectsListClick);116};117const finishEffects = () => {118 effectsListElement.removeEventListener('change', onEffectsListClick);119 imgUploadEffectLevelElement.classList.add('hidden');120 imgUploadPreviewElement.removeAttribute('class');121};...
fetchData.utils.js
Source:fetchData.utils.js
1const { DateTime, Interval } = require("luxon");2import { json } from "d3";3const apiBaseUrl = "https://wlm.inmagik.com";4const dataCacheMode = "force-cache"//"default";5const geoCacheMode = "force-cache";6const fetchData = ({ selectedRegion, selectedProvince, selectedMunicipality, typology, dateFrom, dateTo }, setDataValue, setParentDataValue, setIsFetching, setTimeStep) => {7 setIsFetching(true);8 // console.log("fetching data...");9 let dataUrl = apiBaseUrl;10 let parentDataUrl = apiBaseUrl;11 if (selectedMunicipality) {12 // in municipality13 dataUrl += `/api/municipality/${selectedMunicipality.code}/wlm/`;14 parentDataUrl += `/api/municipality/${selectedMunicipality.code}/wlm/`;15 } else if (selectedProvince) {16 // municipalities in province17 dataUrl += `/api/province/${selectedProvince.code}/wlm-areas/`;18 parentDataUrl += `/api/province/${selectedProvince.code}/wlm/`;19 } else if (selectedRegion) {20 // provinces in region21 dataUrl += `/api/region/${selectedRegion.code}/wlm-areas/`;22 parentDataUrl += `/api/region/${selectedRegion.code}/wlm/`;23 } else {24 // no area selected, do all italian regions25 dataUrl += `/api/region/wlm-regions/`;26 parentDataUrl += `/api/region/wlm-aggregate`;27 }28 if (dataUrl) {29 const _df = DateTime.fromISO(dateFrom);30 const _dt = DateTime.fromISO(dateTo);31 const i = Interval.fromDateTimes(_df, _dt);32 let max_steps = 15,33 step_size,34 step_unit;35 if (Math.ceil(i.length("days") / 1) <= 31) {36 step_unit = "days";37 step_size = 1;38 } else if (Math.ceil(i.length("days") / 5) <= max_steps) {39 step_unit = "days";40 step_size = 5;41 } else if (Math.ceil(i.length("days") / 10) <= max_steps) {42 step_unit = "days";43 step_size = 10;44 } else if (Math.ceil(i.length("months") / 1) <= max_steps) {45 step_unit = "months";46 step_size = 1;47 } else if (Math.ceil(i.length("months") / 3) <= max_steps) {48 step_unit = "months";49 step_size = 3;50 } else if (Math.ceil(i.length("months") / 4) <= max_steps) {51 step_unit = "months";52 step_size = 4;53 } else if (Math.ceil(i.length("months") / 6) <= max_steps) {54 step_unit = "months";55 step_size = 6;56 } else {57 step_unit = "years";58 step_size = 1;59 }60 const timeStepMessage = ["Showing ", Math.ceil(i.length(step_unit) / step_size), " history points (every ", step_size, " ", step_unit, ")", ].join("")61 setTimeStep(timeStepMessage)62 const parameters = { step_size, step_unit };63 parameters.date_from = dateFrom;64 parameters.date_to = dateTo;65 if (typology) parameters.theme = typology.id;66 parameters.format = "json";67 const searchParams = new URLSearchParams(parameters).toString();68 dataUrl += "?" + searchParams;69 parentDataUrl += "?" + searchParams;70 Promise.all([71 json(dataUrl, {72 cache: dataCacheMode,73 }),74 json(parentDataUrl, {75 cache: dataCacheMode,76 }),77 ]).then(([data, parentData]) => {78 // console.log(data, parentData)79 // filter data if later than date_to80 // data.data.forEach((area) => {81 // const newHistory = area.history.filter((h) => {82 // const date = h.date;83 // return DateTime.fromISO(date) <= _dt;84 // });85 // area.history = newHistory;86 // });87 // parentData.data.forEach((area) => {88 // const newHistory = area.history.filter((h) => {89 // const date = h.date;90 // return DateTime.fromISO(date) <= _dt;91 // });92 // area.history = newHistory;93 // });94 setDataValue(data);95 setParentDataValue(parentData);96 setIsFetching(false);97 });98 }99};...
Using AI Code Generation
1var wpt = require('wpt');2wpt.step_unit('test');3var wpt = require('wpt');4wpt.step_unit('test', 'Test Step Unit');5var wpt = require('wpt');6wpt.step_unit('test', 'Test Step Unit', 'test');7var wpt = require('wpt');8wpt.step_unit('test', 'Test Step Unit', 'test', 'test');9var wpt = require('wpt');10wpt.step_unit('test', 'Test Step Unit', 'test', 'test', 'test');11var wpt = require('wpt');12wpt.step_unit('test', 'Test Step Unit', 'test', 'test', 'test', 'test');13var wpt = require('wpt');14wpt.step_unit('test', 'Test Step Unit', 'test', 'test', 'test', 'test', 'test');15var wpt = require('wpt');16wpt.step_unit('test', 'Test Step Unit', 'test', 'test', 'test', 'test', 'test', 'test');17var wpt = require('wpt');18wpt.step_unit('test', 'Test Step Unit', 'test', 'test', 'test', 'test', 'test', 'test', 'test');19var wpt = require('wpt');20wpt.step_unit('test', 'Test Step Unit', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test');
Using AI Code Generation
1var wpt = require('webpagetest');2var test = wpt('API_KEY');3 if (err) return console.log(err);4 test.step_unit(data.data.testId, 1, function(err, data) {5 if (err) return console.log(err);6 console.log(data);7 });8});9{ data:10 { testId: '150314_8X_1',11 repeatView: [Object] },12 statusText: 'Ok' }13{ data:14 { testId: '150314_8X_1',15 repeatView: [Object] },16 statusText: 'Ok' }17{ data:18 { testId: '150314_8X_1',19 repeatView: [Object] },20 statusText: 'Ok' }21{ data:22 { testId: '150314_8X_1',23 repeatView: [Object] },24 statusText: 'Ok' }25{ data:26 { testId: '150314_8X_1',27 repeatView: [Object] },28 statusText: 'Ok' }29{ data:30 { testId: '150314_8X_1',31 repeatView: [Object] },32 statusText: 'Ok' }33{ data:34 { testId: '
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new wpt('API_KEY');3wpt.step_unit(url, function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});
Using AI Code Generation
1step_unit("test", "test description", "ok");2step_unit("test", "test description", "ok");3step_unit("test", "test description", "ok");4step_unit("test", "test description", "ok");5step_unit("test", "test description", "ok");6step_unit("test", "test description", "ok");7step_unit("test", "test description", "ok");8step_unit("test", "test description", "ok");9step_unit("test", "test description", "ok");10step_unit("test", "test description", "ok");11step_unit("test", "test description", "ok");12step_unit("test", "test description", "ok");13step_unit("test", "test description", "ok");14step_unit("test", "test description", "ok");15step_unit("test", "test description", "ok");16step_unit("test", "test description", "ok");17step_unit("test", "test description", "ok");18step_unit("test", "test description", "ok");19step_unit("test", "test description", "ok");20step_unit("test", "test description", "ok");21step_unit("test", "test description", "ok");22step_unit("test", "test description", "ok");
Using AI Code Generation
1var wpt = require('webpagetest');2var test = new wpt('a8a0a8f8b2d2a2f0c0f0f0f0f0f0f0f0');3var location = 'Dulles:Chrome';4var options = { 'video': true, 'location': location };5test.runTest(url, options, function(err, data) {6 if (err)7 console.log(err);8 console.log(data);9});10var wpt = require('webpagetest');11var test = new wpt('a8a0a8f8b2d2a2f0c0f0f0f0f0f0f0f0');12var location = 'Dulles:Chrome';13var options = { 'video': true, 'location': location };14test.runTest(url, options, function(err, data) {15 if (err)16 console.log(err);17 console.log(data);18});19var wpt = require('webpagetest');20var test = new wpt('a8a0a8f8b2d2a2f0c0f0f0f0f0f0f0f0');21var location = 'Dulles:Chrome';22var options = { 'video': true, 'location': location };23test.runTest(url, options, function(err, data) {24 if (err)25 console.log(err);26 console.log(data);27});28var wpt = require('webpagetest');29var test = new wpt('a8a0a8f8b2d2a2f0c0f0f0f0f0f0f0f0');30var location = 'Dulles:Chrome';31var options = { 'video': true, 'location': location };32test.runTest(url, options, function(err, data) {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!