How to use timeParams method in Best

Best JavaScript code snippet using best

thredds_layer.js

Source:thredds_layer.js Github

copy

Full Screen

1 /**2 Class: OpenLayers.Layer.WMSTimeOffset3 Extends the WMS base class to handle WMS layers that can take a time parameter. This is meant to be a base class as the time4 parameter can vary from WMS layer types.5 */6 OpenLayers.Layer.WMSTimeOffset = OpenLayers.Class(OpenLayers.Layer.WMS, {7 currentDateTime : undefined, //Current Date object.8 currentTime : undefined, //Current Time object.9 initialize: function(name, url, params, options) {10 OpenLayers.Layer.WMS.prototype.initialize.apply(this,arguments);11 },12 /**13 * Method: setTimeOffset14 * The WMSEx object should be extended for layers that have a time offset parameter that can be passed in the WMS query. THis function15 * should be overloaded in the child object and the appropriate POST/GET parameter applied.16 * Parameters:17 timeObj a Date object with the desired time.18 * Returns:19 */20 setTimeOffset : function(dateObj, timeObj, updateLayer)21 {22 this.currentDate = dateObj;23 this.currentTime = timeObj;24 if(updateLayer)25 {26 this.redraw();27 }28 },29 getCurrentDateTime : function()30 {31 return(currentDateTime);32 },33 setTimeOffset : function(dateObj, updateLayerFlag)34 {35 if(dateObj)36 {37 this.currentDateTime = dateObj;38 }39 if(updateLayerFlag)40 {41 this.redraw();42 }43 }44 });45 /**46 Class: OpenLayers.Layer.WMSThredds47 Extends the WMS base class to handle some new options. Thredds layers can have a forecast/hindcast data, this layer adds the time48 parameter into the WMS query. WE inherit from the WMSEx class as it implements a setTimeOffset() function that will be used to set the49 desired time.50 */51 OpenLayers.Layer.WMSThredds = OpenLayers.Class(OpenLayers.Layer.WMSTimeOffset, {52 curLayerDateTime : undefined, //The current layer date time offset in the Thredds format. This date/time is in GMT.53 /**54 * Constructor: OpenLayers.Layer.WMS55 * Create a new WMS layer object56 *57 * Example:58 * (code)59 * var wms = new OpenLayers.Layer.WMSEx```("NASA Global Mosaic",60 * "http://wms.jpl.nasa.gov/wms.cgi",61 * {layers: "modis,global_mosaic"});62 * (end)63 *64 * Parameters:65 * name - {String} A name for the layer66 * url - {String} Base url for the WMS67 * (e.g. http://wms.jpl.nasa.gov/wms.cgi)68 * params - {Object} An object with key/value pairs representing the69 * GetMap query string parameters and parameter values.70 * options - {Ojbect} Hashtable of extra options to tag onto the layer71 */72 initialize: function(name, url, params, options) {73 OpenLayers.Layer.WMS.prototype.initialize.apply(this,arguments);74 },75 /*76 getCurrentDateTime : function()77 {78 //Take the current Thredds datetime string, convert it into a Date object.79 //this.currentDateTime = Date.parseDate(this.curLayerDateTime, "Y-m-d\\TH:i:s.000\\Z");80 if(this.currentDateTime === undefined)81 {82 this.currentDateTime = new Date();83 var updateInterval;84 //WE can either have a calculated update interval where the user provides how many times an hour the data updates, or the85 //specific update times for the hour are provided.86 if(this.extendedOptions.timeParams.hourlyUpdateInterval)87 {88 if(this.extendedOptions.timeParams.currentTimeOffset)89 {90 //Adjust time by currentTimeOffset.91 var utcTime = this.currentDateTime.getTime();92 this.currentDate.UTC(utcTime + (currentTimeOffset * 60 * 60 * 1000))93 }94 this.currentDateTime = getClosestDateToHourInterval(this.currentDateTime, this.extendedOptions.timeParams.hourlyUpdateInterval);95 }96 else if(this.extendedOptions.timeParams.updateTimes)97 {98 if(this.extendedOptions.timeParams.currentTimeOffset)99 {100 //Adjust time by currentTimeOffset.101 var utcTime = this.currentDateTime.getTime();102 this.currentDate.UTC(utcTime + (currentTimeOffset * 60 * 60 * 1000))103 }104 this.currentDateTime = getClosestDateToUpdateTimes(this.currentDateTime, this.extendedOptions.timeParams.updateTimes);105 }106 }107 return(this.currentDateTime);108 },109 */110 getFullRequestString : function(newParams, altUrl)111 {112 // Do we have a current layer time? If not let's get one based on the current time.113 if(this.curLayerDateTime === undefined)114 {115 this.setTimeOffset(undefined, false);116 }117 newParams['TIME'] = this.curLayerDateTime;118 return OpenLayers.Layer.WMSTimeOffset.prototype.getFullRequestString.apply(this, arguments);119 },120 /**121 * Method: setTimeOffset122 * Thredds servers use a TIME parameter in the POST query. This function properly populates the desired time and adds the parameter to the query.123 * Parameters:124 dateObj a Date object with the desired date/time.125 updateLayer if true, the layer will request a redraw.126 * Returns:127 */128 setTimeOffset : function(dateObj, updateLayer)129 {130 var layerTimeReq;131 if(dateObj === undefined)132 {133 dateObj = new Date();134 //If we need to use a time offset for the initial time, we make the adjustment.135 if(this.extendedOptions.timeParams.currentTimeOffset)136 {137 //Adjust time by currentTimeOffset.138 var utcTime = dateObj.getTime();139 dateObj.setTime(utcTime - (this.extendedOptions.timeParams.currentTimeOffset * 60 * 60 * 1000))140 }141 //dateObj = dateObj.format("Y-m-d H:i:00");142 dateObj = convertToGMT(dateObj)143 /*144 if(this.extendedOptions.timeParams.hourlyUpdateInterval)145 {146 dateObj = getClosestDateToHourInterval(dateObj, this.extendedOptions.timeParams.hourlyUpdateInterval);147 }148 else if(this.extendedOptions.timeParams.updateTimes)149 {150 dateObj = getClosestDateToUpdateTimes(dateObj, this.extendedOptions.timeParams.updateTimes);151 }152 */153 }154 this.currentDateTime = dateObj;155 layerTimeReq = dateObj.format("Y-m-d\\TH:i:00.000\\Z");156 this.curLayerDateTime = layerTimeReq;157 if(updateLayer)158 {159 this.redraw();160 }161 }162 });163/*164 Class: WMSGraphGetFeatureInfo165 Overrides the WMSGetFeatureInfo and sends the returned XML to a data store to be used for graphing.166*/167rcoosmapping.WMSThreddsXMLGetFeatureInfo = OpenLayers.Class(OpenLayers.Control.WMSGetFeatureInfo,168{169 gfiUrl : undefined,170 srsProj : undefined,171 queryLayers : undefined,172 timeParams : undefined,173 obsType : '',174 uomType : '',175 initialize: function(options)176 {177 this.eventListeners = {getfeatureinfo : this.gfiCallback};178 if(options.vendorParams.obsType)179 {180 this.obsType = options.vendorParams.obsType;181 delete options.vendorParams['obsType'];182 }183 if(options.vendorParams.uomType)184 {185 this.uomType = options.vendorParams.uomType;186 delete options.vendorParams['uomType'];187 }188 if(options.vendorParams)189 {190 if(options.vendorParams.gfiUrl)191 {192 this.gfiUrl = options.vendorParams.gfiUrl;193 delete options.vendorParams['gfiUrl'];194 }195 if(options.vendorParams.srs)196 {197 this.srsProj = options.vendorParams.srs;198 delete options.vendorParams['srs'];199 }200 if(options.vendorParams.query_layers)201 {202 this.queryLayers = options.vendorParams.query_layers;203 delete options.vendorParams['query_layers'];204 }205 if(options.vendorParams.timeParams)206 {207 this.timeParams = {};208 if(options.vendorParams.timeParams.forecastHours)209 {210 this.timeParams.forecastHours = options.vendorParams.timeParams.forecastHours;211 }212 else213 {214 this.timeParams.forecastHours = 24;215 }216 if(options.vendorParams.timeParams.hindcastHours)217 {218 this.timeParams.hindcastHours = options.vendorParams.timeParams.hindcastHours;219 }220 else221 {222 this.timeParams.hindcastHours = 24;223 }224 if(options.vendorParams.timeParams.updateRate)225 {226 this.timeParams.updateRate = options.vendorParams.timeParams.updateRate;227 }228 else229 {230 this.timeParams.updateRate = 3;231 }232 this.timeParams.hindcastHours *= -1;233 delete options.vendorParams['timeParams'];234 }235 }236 OpenLayers.Control.WMSGetFeatureInfo.prototype.initialize.apply(this, arguments);237 },238 gfiCallback : function(event)239 {240 var xmlDoc = new DOMParser().parseFromString(event.request.responseText,"text/xml");241 var threadsXML = new Ext.data.Store({242 reader : new rcoosmapping.data.threadsWMSXMLReader({243 record: 'FeatureInfo',244 fields: [245 {name : 'time' , mapping: 'time'},246 {name : 'value', mapping: 'value'}247 ],248 headerFields: [249 {name : 'obsType' , defaultValue: this.obsType},250 {name : 'uomType' , defaultValue: this.uomType},251 {name : 'latitude' , mapping: 'latitude'},252 {name : 'longitude', mapping: 'longitude'},253 {name : 'type', defaultValue: "MultiPoint"},254 {name : 'geometryType', defaultValue: "MultiPoint"},255 ]256 })257 });258 threadsXML.loadData(xmlDoc);259 var i = 0;260 },261 getClosestDateToHourInterval : function(curDate, updateInterval)262 {263 var hour = parseInt(curDate.format('H'),10);264 var offset = hour % updateInterval;265 var closestDate = curDate;266 if(offset !== 0)267 {268 var offstAdjust = 0;269 var epoch = curDate.format('U');270 var x = Math.round(updateInterval / 2);271 if(offset >= x)272 {273 offstAdjust = updateInterval - offset;274 }275 else276 {277 offstAdjust = offset * -1;278 }279 epoch += (offstAdjust * 60 * 60);280 closestDate = new Date(epoch * 1000);281 }282 return(closestDate);283 },284 buildWMSOptions: function(url, layers, clickPosition, format)285 {286 if(this.gfiUrl)287 {288 url = this.gfiUrl;289 }290 var layerNames = [], styleNames = [];291 for (var i = 0, len = layers.length; i < len; i++) {292 layerNames = layerNames.concat(layers[i].params.LAYERS);293 styleNames = styleNames.concat(this.getStyleNames(layers[i]));294 }295 var firstLayer = layers[0];296 // use the firstLayer's projection if it matches the map projection -297 // this assumes that all layers will be available in this projection298 var projection = this.map.getProjection();299 var layerProj = firstLayer.projection;300 if(this.srsProj)301 {302 //extent.transform(new OpenLayers.Projection(mapConfig.displayProjection),303 // new OpenLayers.Projection(mapConfig.projection));304 layerProj = new OpenLayers.Projection(this.srsProj);305 }306 var bbox = this.map.getExtent().transform(this.map.getProjectionObject(), layerProj).toBBOX(null,307 firstLayer.reverseAxisOrder());308 if (layerProj && layerProj.equals(this.map.getProjectionObject())) {309 projection = layerProj.getCode();310 }311 if(this.timeParams)312 {313 var ct = new Date();314 var fromTime = ct.add(Date.HOUR, this.timeParams.hindcastHours);315 var toTime = ct.add(Date.HOUR, this.timeParams.forecastHours);316 if(this.timeParams.updateRate)317 {318 //var startDate = this.getClosestDateToHourInterval(ct, this.timeParams.updateRate);319 fromTime = this.getClosestDateToHourInterval(fromTime, this.timeParams.updateRate);320 toTime = this.getClosestDateToHourInterval(toTime, this.timeParams.updateRate);321 }322 var timeParam = fromTime.format("Y-m-d\\TH:00:00.000\\Z") + '/' + toTime.format("Y-m-d\\TH:00:00.000\\Z");323 this.vendorParams.TIME = timeParam;324 }325 var params = OpenLayers.Util.extend({326 service: "WMS",327 version: firstLayer.params.VERSION,328 request: "GetFeatureInfo",329 layers: (this.queryLayers ? this.queryLayers : layerNames),330 query_layers: (this.queryLayers ? this.queryLayers : layerNames),331 styles: styleNames,332 bbox: bbox,333 feature_count: this.maxFeatures,334 height: this.map.getSize().h,335 width: this.map.getSize().w,336 format: format,337 info_format: firstLayer.params.INFO_FORMAT || this.infoFormat338 }, (parseFloat(firstLayer.params.VERSION) >= 1.3) ?339 {340 crs: (this.srsProj ? this.srsProj : projection),341 i: parseInt(clickPosition.x),342 j: parseInt(clickPosition.y)343 } :344 {345 srs: (this.srsProj ? this.srsProj : projection),346 x: parseInt(clickPosition.x),347 y: parseInt(clickPosition.y)348 }349 );350 OpenLayers.Util.applyDefaults(params, this.vendorParams);351 return {352 url: url,353 params: OpenLayers.Util.upperCaseObject(params),354 callback: function(request) {355 this.handleResponse(clickPosition, request, url);356 },357 scope: this358 };359 }...

Full Screen

Full Screen

IconShadow.js

Source:IconShadow.js Github

copy

Full Screen

1'use strict';2const3 INITIAL_SHADOW_LENGTH = 2000,4 TARGET_ANGLE = Math.PI / 4;5class IconShadow {6 /**7 * @param iconPath path of the icon used to construct the shadow8 * @param iconBase of the icon used to cut the shadow9 */10 constructor(iconPath, iconBase) {11 this.iconBase = iconBase;12 this.iconPath = iconPath;13 this.iconShadowPaths = [];14 let outlineIconPaths = this.getAndCopyPaths(iconPath);15 for (let outlineIdx = 0; outlineIdx < outlineIconPaths.length; ++outlineIdx) {16 let path = outlineIconPaths[outlineIdx];17 let subPaths = [];18 let tangent = this.findNextTangent(path);19 // cut path along tangents into sub paths20 path.split(tangent.curveIdx, tangent.timeParams[0]);21 while (path && (tangent = this.findNextTangent(path))) {22 let newPath = path.split(tangent.curveIdx, tangent.timeParams[0]);23 subPaths.push(path);24 path = newPath;25 }26 if (path) subPaths.push(path);27 // create shadow sub shapes28 let xyTranslation = Math.sqrt(INITIAL_SHADOW_LENGTH * INITIAL_SHADOW_LENGTH / 2);29 let translation = new paper.Point(xyTranslation, xyTranslation);30 for (let i = 0; i < subPaths.length; ++i) {31 let subPath = subPaths[i];32 // offset + insert all segments to create closed form33 for (let j = subPath.segments.length - 1; j >= 0; --j) {34 let segment = subPath.segments[j];35 // make shade edges 'sharp'36 if (j === subPath.segments.length -1) {37 segment.handleOut.x = 0;38 segment.handleOut.y = 0;39 }40 if (j === 0) {41 segment.handleIn.x = 0;42 segment.handleIn.y = 0;43 }44 subPath.add(new paper.Segment(segment.point.add(translation), segment.handleOut, segment.handleIn));45 }46 subPath.closed = true;47 this.iconShadowPaths.push(subPath.clone());48 }49 }50 // find bottom right edge of shadow (for changing length)51 this.iconShadowBottomRightSegments = [];52 this.iconShadowPaths.forEach(function(path) {53 this.iconShadowBottomRightSegments = this.iconShadowBottomRightSegments.concat(this.findBottomRightSegments(path));54 }.bind(this));55 this.length = INITIAL_SHADOW_LENGTH;56 // store shadow template and cut with base57 this.applyShadow();58 }59 findNextTangent(path) {60 // go over each curve and try finding tangent with target angle61 outer: for (let i = 0; i < path.curves.length; ++i) {62 let curve = path.curves[i];63 // search for tangent within curve64 let timeParams = this.findNextTangentFromCurve(curve);65 if (timeParams.length > 0) {66 // don't split curve right at the beginning (otherwise it might never stop splitting there ...)67 while (i === 0 && timeParams[0] < 1E-10) {68 timeParams.splice(0, 1);69 if (timeParams.length === 0) continue outer;70 }71 return {72 curveIdx: i,73 timeParams: timeParams74 };75 }76 // check for hard edges between this and the next curve77 let nextCurve = path.curves[(i + 1) % path.curves.length];78 let hardEdge = (curve.handle2.x === 0 && curve.handle2.y === 0) || (nextCurve.handle1.x === 0 || nextCurve.handle1.y === 0);79 hardEdge = hardEdge || (Math.abs(curve.getTangentAt(1, true).angle - nextCurve.getTangentAt(0, true).angle) > 1E-10);80 if (!hardEdge) continue;81 // (possible) TODO82 // Currently path will be split along every hard edge. This might not be super efficient for very large paths.83 return {84 curveIdx: i,85 timeParams: [1]86 };87 }88 return undefined;89 }90 findNextTangentFromCurve(curve) {91 // in case of missing handles return92 if (curve.handle1.x === 0 && curve.handle1.y === 0 && curve.handle2.x === 0 && curve.handle2.y === 0) {93 return [];94 }95 // find tangent with target angle (45 degrees)96 let points = [97 curve.point1,98 curve.point1.add(curve.handle1),99 curve.point2.add(curve.handle2),100 curve.point2101 ];102 let a = {};103 let b = {};104 let c = {};105 a.x = 3 * points[3].x - 9 * points[2].x + 9 * points[1].x - 3 * points[0].x;106 a.y = 3 * points[3].y - 9 * points[2].y + 9 * points[1].y - 3 * points[0].y;107 b.x = 6 * points[2].x - 12 * points[1].x + 6 * points[0].x;108 b.y = 6 * points[2].y - 12 * points[1].y + 6 * points[0].y;109 c.x = 3 * points[1].x - 3 * points[0].x;110 c.y = 3 * points[1].y - 3 * points[0].y;111 let t = {112 x: Math.cos(TARGET_ANGLE),113 y: Math.sin(TARGET_ANGLE)114 };115 let timeParams = [];116 let den = 2 * a.x * t.y - 2 * a.y * t.x;117 if (Math.abs(den) < 1E-10) {118 let num = a.x * c.y - a.y * c.x;119 den = a.x * b.y - a.y * b.x;120 if (den != 0) {121 let time = -num / den;122 if (time >= 0 && time <= 1) timeParams.push(time);123 }124 } else {125 let delta = (b.x * b.x - 4 * a.x * c.x) * t.y * t.y + (-2 * b.x * b.y + 4 * a.y * c.x + 4 * a.x * c.y) * t.x * t.y + (b.y * b.y - 4 * a.y * c.y) * t.x * t.x;126 let k = b.x * t.y - b.y * t.x;127 timeParams = [];128 if (delta >= 0 && den != 0) {129 let d = Math.sqrt(delta);130 let t0 = -(k + d) / den;131 let t1 = (-k + d) / den;132 if (Math.abs(t0 - 1) < 1E-5) t0 = 1;133 if (Math.abs(t1 - 1) < 1E-5) t1 = 1;134 if (t0 >= 0 && t0 <= 1) timeParams.push(t0);135 if (t1 >= 0 && t1 <= 1) timeParams.push(t1);136 }137 }138 if (timeParams.length === 0) return timeParams;139 // clean values140 for (let i = 0; i < timeParams.length; ++i) {141 let time = timeParams[i];142 // if very close to 0, set value to 0143 if (time < 1E-5) {144 timeParams[i] = 0;145 continue;146 }147 // if very close to 1, set value to 1148 time = Math.abs(1 - time);149 if (time < 1E-5) {150 timeParams[i] = 1;151 continue;152 }153 }154 timeParams.sort(function(a, b) { return a - b; });155 return timeParams;156 }157 findBottomRightSegments(path) {158 let segments = [];159 if (path instanceof paper.CompoundPath) {160 for (let i = 0; i < path.children.length; ++i) {161 segments = segments.concat(this.findBottomRightSegments(path.children[i]));162 }163 } else {164 for (let i = 0; i < path.segments.length; ++i) {165 let segment = path.segments[i];166 if (segment.point.getDistance(this.iconPath.bounds.topLeft) >= INITIAL_SHADOW_LENGTH * 0.95) {167 segments.push(segment);168 }169 }170 }171 return segments;172 }173 /**174 * @param scale factor to scale this shadow by.175 */176 scale(scale) {177 this.iconShadowPaths.forEach(function(path) {178 path.scale(scale, this.iconPath.position);179 }.bind(this));180 this.unitedIconShadowPath.scale(scale, this.iconPath.position);181 this.length = this.length * scale;182 this.applyShadow();183 }184 /**185 * @param {paper.Point} delta - how much this icon + shadow should be moved.186 */187 move(delta) {188 this.iconShadowPaths.forEach(function(path) {189 path.position = path.position.add(delta);190 });191 this.unitedIconShadowPath.position = this.unitedIconShadowPath.position.add(delta);192 this.applyShadow();193 }194 /**195 * Remove this shadow form the canvas.196 */197 remove() {198 this.iconShadowPaths.forEach(function(path) {199 path.remove();200 });201 if (this.unitedIconShadowPath) this.unitedIconShadowPath.remove();202 if (this.appliedIconShadowPath) this.appliedIconShadowPath.remove();203 }204 /**205 * Cut the shadow path template(s) to base size. This creates the206 * final shadow path.207 */208 applyShadow() {209 // join sub shadows to from one path210 if (!this.unitedIconShadowPath) this.createUnitedIconShadowPath();211 // cut shadow to base212 let basePath = this.iconBase.getPathWithoutShadows();213 let newAppliedIconShadowPath = this.unitedIconShadowPath.intersect(basePath);214 // save shadow215 if (this.appliedIconShadowPath) {216 this.appliedIconShadowPath.replaceWith(newAppliedIconShadowPath);217 newAppliedIconShadowPath.fillColor = this.appliedIconShadowPath.fillColor;218 } else {219 // create default gradient220 newAppliedIconShadowPath.fillColor = {221 gradient: {222 stops: [223 [new paper.Color(0, 0, 0, 1), 0],224 [new paper.Color(0, 0, 0, 0), 1]225 ]226 }227 }228 }229 this.appliedIconShadowPath = newAppliedIconShadowPath;230 this.updateAppliedIconShadowPathGradientBounds();231 // move shadow below icon232 this.appliedIconShadowPath.moveBelow(this.iconPath);233 }234 /**235 * Unites all shadow parts to one shadow shape (doesn't intersect with base though,236 * hence can be used as a 'template').237 * Don't call this too often though, uniting shapes is CPU intensive.238 */239 createUnitedIconShadowPath() {240 if (this.unitedIconShadowPath) this.unitedIconShadowPath.remove();241 this.unitedIconShadowPath = this.iconShadowPaths[0].clone();242 for (let i = 1; i < this.iconShadowPaths.length; ++i) {243 let subPathCopy = this.iconShadowPaths[i].clone();244 let newShadowPath = this.unitedIconShadowPath.unite(subPathCopy);245 subPathCopy.remove();246 this.unitedIconShadowPath.remove();247 this.unitedIconShadowPath = newShadowPath;248 }249 }250 /**251 * Sets the length of this shadow (diagonal)252 * @param {Number} length253 */254 setLength(length) {255 let deltaLength = length - this.length;256 let translation = Math.sqrt(deltaLength * deltaLength / 2);257 if (deltaLength < 0) translation = translation * -1;258 for (let i = 0; i < this.iconShadowBottomRightSegments.length; ++i) {259 let segment = this.iconShadowBottomRightSegments[i];260 segment.point = segment.point.add(translation);261 }262 this.length = length;263 this.createUnitedIconShadowPath();264 this.applyShadow();265 }266 /**267 * Sets the start intensity of this shadow.268 * @param {Number} intensity - between 0 and 1.269 */270 setIntensity(intensity) {271 this.appliedIconShadowPath.fillColor.gradient.stops[0].color.alpha = intensity;272 // hack: just changing alpha does not trigger a redraw, 'change' this as well273 this.appliedIconShadowPath.fillColor.destination = this.appliedIconShadowPath.fillColor.destination;274 }275 /**276 * Sets where the shadow should begin fading.277 * @param {Number} fading - between 0 and 1. 1 Start fading right away, 0 never fade.278 */279 setFading(fading) {280 this.appliedIconShadowPath.fillColor.gradient.stops[0].rampPoint = 1 - fading;281 // hack: just changing alpha does not trigger a redraw, 'change' this as well282 this.appliedIconShadowPath.fillColor.destination = this.appliedIconShadowPath.fillColor.destination;283 }284 updateAppliedIconShadowPathGradientBounds() {285 let bounds = this.unitedIconShadowPath.bounds;286 this.appliedIconShadowPath.fillColor.origin = bounds.topLeft;287 this.appliedIconShadowPath.fillColor.destination = bounds.bottomRight;288 }289 /**290 * Copies and returns all paths from a given Path / CompoundPath object.291 */292 getAndCopyPaths(pathItem) {293 if (pathItem instanceof paper.Path) {294 const result = [ new paper.Path(pathItem.pathData) ];295 result[0].position = pathItem.position.clone();296 return result;297 }298 // copy children299 const children = [];300 for (let i = 0; i < pathItem.children.length; ++i) {301 children.push(new paper.Path(pathItem.children[i].pathData));302 }303 return children;304 }305}...

Full Screen

Full Screen

order.js

Source:order.js Github

copy

Full Screen

1import { handleDate } from '@/utils/date-filter'2export default {3 methods: {4 searchTimeChange (timeParams) {5 let result =6 timeParams.createdTime ||7 timeParams.takeTime ||8 timeParams.returnTime ||9 timeParams.settleTime ||10 timeParams.finishTime ||11 timeParams.expectTakeTime12 if (result) {13 for (let key in timeParams) {14 if (15 timeParams[key].length > 0 &&16 typeof timeParams[key] === 'object'17 ) {18 timeParams.dateMin = handleDate(timeParams[key][0], 'day')19 timeParams.dateMax = handleDate(timeParams[key][1], 'day')20 timeParams.dateKey = key21 delete timeParams[key]22 }23 }24 return timeParams25 } else {26 return timeParams27 }28 },29 searchUserChange (type) {30 let resoult =31 type.userPhone || type.carNumber || type.userName || type.orderSn32 if (resoult) {33 for (let key in type) {34 if (type[key] === resoult) {35 type.key = key36 type.value = type[key]37 delete type[key]38 }39 }40 return type41 } else {42 return type43 }44 },45 pictureChange (list) {46 let resoult = {47 images: [],48 imagesImgDescription: []49 }50 // const m = new Map()51 list.forEach(ele => {52 switch (ele.key) {53 case 'left_front':54 // m.set(ele.key, { key: '左前45°', url: ele.url })55 ele.key = '左前45°'56 break57 case 'right_front':58 // m.set(ele.key, { key: '右前45°', url: ele.url })59 ele.key = '右前45°'60 break61 case 'front_row':62 // m.set(ele.key, { key: '前排', url: ele.url })63 ele.key = '前排'64 break65 case 'back_row':66 // m.set(ele.key, { key: '后排', url: ele.url })67 ele.key = '后排'68 break69 case 'center_back':70 // m.set(ele.key, { key: '正后方', url: ele.url })71 ele.key = '正后方'72 break73 case 'other':74 // m.set(ele.key, { key: '其他位置或特写', url: ele.url })75 ele.key = '其他位置或特写'76 break77 }78 if (ele && ele.url) {79 resoult.images.push(ele.url)80 resoult.imagesImgDescription.push(ele.key)81 }82 })83 // let mapList = [84 // m.get('left_front'),85 // m.get('right_front'),86 // m.get('front_row'),87 // m.get('back_row'),88 // m.get('center_back'),89 // m.get('other')90 // ]91 // mapList.forEach(ele => {92 // if (ele && ele.url) {93 // resoult.images.push(ele.url)94 // resoult.imagesImgDescription.push(ele.key)95 // }96 // })97 return resoult98 }99 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const BestTimeToBuyAndSellStock = require('./BestTimeToBuyAndSellStock');2const prices = [7,1,5,3,6,4];3const bestTimeToBuyAndSellStock = new BestTimeToBuyAndSellStock();4const maxProfit = bestTimeToBuyAndSellStock.timeParams(prices);5console.log(maxProfit);6class BestTimeToBuyAndSellStock{7 timeParams(prices){8 let maxProfit = 0;9 for(let i=0; i<prices.length; i++){10 for(let j=i+1; j<prices.length; j++){11 if(prices[j] - prices[i] > maxProfit){12 maxProfit = prices[j] - prices[i];13 }14 }15 }16 return maxProfit;17 }18}19module.exports = BestTimeToBuyAndSellStock;

Full Screen

Using AI Code Generation

copy

Full Screen

1const BestTimeToBuyAndSellStock = require('./BestTimeToBuyAndSellStock.js');2const bestTimeToBuyAndSellStock = new BestTimeToBuyAndSellStock();3var prices = [7,1,5,3,6,4];4var result = bestTimeToBuyAndSellStock.timeParams(prices);5console.log(result);6class BestTimeToBuyAndSellStock {7 timeParams(prices) {8 if(prices.length == 1) {9 return 0;10 }11 var maxProfit = 0;12 for(var i=0; i<prices.length; i++) {13 for(var j=i+1; j<prices.length; j++) {14 if(prices[j] - prices[i] > maxProfit) {15 maxProfit = prices[j] - prices[i];16 }17 }18 }19 return maxProfit;20 }21}22module.exports = BestTimeToBuyAndSellStock;

Full Screen

Using AI Code Generation

copy

Full Screen

1const BestTimeToBuyAndSellStock = require("./BestTimeToBuyAndSellStock");2let maxProfit = new BestTimeToBuyAndSellStock();3let prices = [7, 1, 5, 3, 6, 4];4console.log(maxProfit.timeParams(prices));5const BestTimeToBuyAndSellStock = require("./BestTimeToBuyAndSellStock");6let maxProfit = new BestTimeToBuyAndSellStock();7let prices = [7, 6, 4, 3, 1];8console.log(maxProfit.timeParams(prices));

Full Screen

Using AI Code Generation

copy

Full Screen

1let timeParams = new BestTimeToBuyAndSellStock();2let prices = [7,1,5,3,6,4];3console.log(timeParams.maxProfit(prices));4let timeParams = new BestTimeToBuyAndSellStock();5let prices = [7,6,4,3,1];6console.log(timeParams.maxProfit(prices));7let timeParams = new BestTimeToBuyAndSellStock();8let prices = [2,4,1];9console.log(timeParams.maxProfit(prices));10let timeParams = new BestTimeToBuyAndSellStock();11let prices = [1,2];12console.log(timeParams.maxProfit(prices));13let timeParams = new BestTimeToBuyAndSellStock();14let prices = [2,1,2,1,0,1,2];15console.log(timeParams.maxProfit(prices));

Full Screen

Using AI Code Generation

copy

Full Screen

1const bestTime = require('./bestTime.js');2const timeParams = bestTime.timeParams;3const bestTimeToBuyAndSell = bestTime.bestTimeToBuyAndSell;4let prices = [7, 1, 5, 3, 6, 4];5console.log(timeParams(prices));6console.log(bestTimeToBuyAndSell(prices));7prices = [7, 6, 4, 3, 1];8console.log(timeParams(prices));9console.log(bestTimeToBuyAndSell(prices));10**Time complexity** : O(n) 11**Space complexity** : O(1)

Full Screen

Using AI Code Generation

copy

Full Screen

1const BestTime = require('./bestTime.js');2const bestTime = new BestTime();3const timeParams = bestTime.timeParams;4let time = timeParams(12, 30, 'AM');5console.log(time);6const BestTime = require('./bestTime.js');7const bestTime = new BestTime();8const timeParams = bestTime.timeParams;9let time = timeParams(12, 30, 'PM');10console.log(time);11const BestTime = require('./bestTime.js');12const bestTime = new BestTime();13const timeParams = bestTime.timeParams;14let time = timeParams(12, 30, 'AM');15console.log(time);16const BestTime = require('./bestTime.js');17const bestTime = new BestTime();18const timeParams = bestTime.timeParams;19let time = timeParams(12, 30, 'AM');20console.log(time);21const BestTime = require('./bestTime.js');22const bestTime = new BestTime();23const timeParams = bestTime.timeParams;24let time = timeParams(12, 30, 'AM');25console.log(time);26const BestTime = require('./bestTime.js');27const bestTime = new BestTime();28const timeParams = bestTime.timeParams;29let time = timeParams(12, 30, 'AM');30console.log(time);

Full Screen

Using AI Code Generation

copy

Full Screen

1console.log(timeParams);2class BestTime {3 timeParams(hours, minutes, seconds) {4 let time = hours * 3600 + minutes * 60 + seconds;5 return time;6 }7}8module.exports = BestTime;

Full Screen

Using AI Code Generation

copy

Full Screen

1const bestTime = require("./bestTime");2const time = new bestTime();3const timeParams = {4};5const result = time.bestTime(timeParams);6console.log(result);7MIT © [Oluwaseun Ogunlade](

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Best automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful