12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240 |
- (function ($) {
-
- var MINPANWIDTH = 110;
- var SLIDEHEIGHT = 30;
- var PANMAG = 5;
- var PANHEAD = 10;
- var INDICTWIDTH = 12;
- var PERMSEC = 10000;
- var PERSEC = 10000000;
- var PERMINUTE = (PERSEC * 60);
- var PERHOUR = (PERMINUTE * 60);
- var PERDAY = (PERHOUR * 24);
- var SPANPAD = 6;
- var SPANLINEHEIGHT = 16;
- var BOTTOMBUTTONLEFT = 80;
- var SHOWTHUMBSHEIGHT = 32;
- var SLIDHLIMIT = 160;
- var SHOWTHUMBSHLIMT = 200;
- var SHOWTOOLBARHLIMIT = 232;
- var SHOWLISTHLIMT = 250;
- var TOOLBARHEIGHT = 32;
- var TIMELABELHEIGHT = 32;
- var MINLISTHEIGHT = 80;
- var HSPLITHEIGHT = 10;
- var ButtonImage = $(new Image()).attr('src', 'htm/rtchart/chartbuttons.png');
- var penColors = ['#00A8F0', '#5DB75D', '#FFFF00', '#FFA62F', '#E41B17', '#000066', '#A0D2FF', '#FF96FF',
- '#E0FFFF', '#388E8E', '#00EE00', '#CD3700', '#EEAD0E', '#6600CC', '#ADFF2F', '#663300'
- ];
- var COLOR_NAMES = {
- aqua: [0, 255, 255],
- azure: [240, 255, 255],
- beige: [245, 245, 220],
- black: [0, 0, 0],
- blue: [0, 0, 255],
- brown: [165, 42, 42],
- cyan: [0, 255, 255],
- darkblue: [0, 0, 139],
- darkcyan: [0, 139, 139],
- darkgrey: [169, 169, 169],
- darkgreen: [0, 100, 0],
- darkkhaki: [189, 183, 107],
- darkmagenta: [139, 0, 139],
- darkolivegreen: [85, 107, 47],
- darkorange: [255, 140, 0],
- darkorchid: [153, 50, 204],
- darkred: [139, 0, 0],
- darksalmon: [233, 150, 122],
- darkviolet: [148, 0, 211],
- fuchsia: [255, 0, 255],
- gold: [255, 215, 0],
- green: [0, 128, 0],
- indigo: [75, 0, 130],
- khaki: [240, 230, 140],
- lightblue: [173, 216, 230],
- lightcyan: [224, 255, 255],
- lightgreen: [144, 238, 144],
- lightgrey: [211, 211, 211],
- lightpink: [255, 182, 193],
- lightyellow: [255, 255, 224],
- lime: [0, 255, 0],
- magenta: [255, 0, 255],
- maroon: [128, 0, 0],
- navy: [0, 0, 128],
- olive: [128, 128, 0],
- orange: [255, 165, 0],
- pink: [255, 192, 203],
- purple: [128, 0, 128],
- violet: [128, 0, 128],
- red: [255, 0, 0],
- silver: [192, 192, 192],
- white: [255, 255, 255],
- yellow: [255, 255, 0]
- };
- dhtmlXCalendarObject.prototype.langData["cn"] = {
- dateformat: '%Y-%m-%d %H:%i:%s',
- monthesFNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
- monthesSNames: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
- daysFNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
- daysSNames: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
- weekstart: 1,
- weekname: "d"
- };
- var WebLink = function (weburl) {
- this.weburl = weburl;
- };
- var TrendPen = function (rtchart, options) {
- this.rtChart = rtchart;
- this.options = $.extend({
- URI: null,
- Num: 2,
- penColor: rtchart.getNextPenColor(),
- penWidth: 2,
- linkReTryTime: 1000,
- hisReTryTime: 20000,
- lockRange: false,
- expandAll: false,
- stepLine: null,
- drawTag: false,
- drawLine: true,
- webURL: GoldenRtWeb.getWebURL()
- }, options || {});
- this.hisRequestSeed = 1;
- if (this.options.rageMax != null)
- this.rageMax = this.options.rageMax;
- if (this.options.rageMin != null)
- this.rageMin = this.options.rageMin;
- var r = Math.abs(this.rageMax - this.rageMin);
- if (r < 1) {
- if (r > 0.1) {
- if (this.options.Num < 3)
- this.options.Num = 3;
- } else if (r > 0.01) {
- if (this.options.Num < 4)
- this.options.Num = 4;
- } else if (r > 0.001) {
- if (this.options.Num < 5)
- this.options.Num = 5;
- } else if (this.options.Num < 6)
- this.options.Num = 6;
- }
- };
- var TrendColor = function (r, g, b, a) {
- this.rgba = ['r', 'g', 'b', 'a'];
- var x = 4;
- while (-1 < --x) {
- this[this.rgba[x]] = arguments[x] || ((x == 3) ? 1.0 : 0);
- }
- this.normalize();
- }
- TrendColor.parse = function (color) {
- if (color instanceof TrendColor) return color;
- var result;
-
- if ((result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color)))
- return new TrendColor(parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16));
-
- if ((result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color)))
- return new TrendColor(parseInt(result[1], 10), parseInt(result[2], 10), parseInt(result[3], 10));
-
- if ((result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color)))
- return new TrendColor(parseInt(result[1] + result[1], 16), parseInt(result[2] + result[2], 16), parseInt(result[3] + result[3], 16));
-
- if ((result = /rgba\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(color)))
- return new TrendColor(parseInt(result[1], 10), parseInt(result[2], 10), parseInt(result[3], 10), parseFloat(result[4]));
-
- if ((result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color)))
- return new TrendColor(parseFloat(result[1]) * 2.55, parseFloat(result[2]) * 2.55, parseFloat(result[3]) * 2.55);
-
- if ((result = /rgba\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\s*\)/.exec(color)))
- return new TrendColor(parseFloat(result[1]) * 2.55, parseFloat(result[2]) * 2.55, parseFloat(result[3]) * 2.55, parseFloat(result[4]));
-
- var name = (color + '').replace(/^\s*([\S\s]*?)\s*$/, '$1').toLowerCase();
- if (name == 'transparent') {
- return new TrendColor(255, 255, 255, 0);
- }
- return (result = COLOR_NAMES[name]) ? new TrendColor(result[0], result[1], result[2]) : new TrendColor(0, 0, 0, 0);
- };
- TrendColor.processColor = function (color, options) {
- var opacity = options.opacity;
- if (!color) return 'rgba(0, 0, 0, 0)';
- if (color instanceof TrendColor) return color.alpha(opacity).toString();
- if (_.isString(color)) return TrendColor.parse(color).alpha(opacity).toString();
- var grad = color.colors ? color : {
- colors: color
- };
- if (!options.ctx) {
- if (!_.isArray(grad.colors)) return 'rgba(0, 0, 0, 0)';
- return TrendColor.parse(_.isArray(grad.colors[0]) ? grad.colors[0][1] : grad.colors[0]).alpha(opacity).toString();
- }
- grad = _.extend({
- start: 'top',
- end: 'bottom'
- }, grad);
- if (/top/i.test(grad.start)) options.x1 = 0;
- if (/left/i.test(grad.start)) options.y1 = 0;
- if (/bottom/i.test(grad.end)) options.x2 = 0;
- if (/right/i.test(grad.end)) options.y2 = 0;
- var i, c, stop, gradient = options.ctx.createLinearGradient(options.x1, options.y1, options.x2, options.y2);
- for (i = 0; i < grad.colors.length; i++) {
- c = grad.colors[i];
- if (_.isArray(c)) {
- stop = c[0];
- c = c[1];
- } else stop = i / (grad.colors.length - 1);
- gradient.addColorStop(stop, TrendColor.parse(c).alpha(opacity));
- }
- return gradient;
- };
- $.widget("rtinfo.trendChart", {
- options: {
- rtRefresh: true,
- showAxis: true,
- showGrid: true,
- showThumbs: true,
- showList: true,
- panShow: true,
- listExpand: true,
- reservePrevData: 10,
- spanSec: 10 * 60,
- pointGroupName: null,
- freeRange: true,
- panWidth: MINPANWIDTH + 50,
- listHeight: MINLISTHEIGHT + 50,
- activeShadowSize: 4,
- tooltipDelay: 1000,
- gridColor: 'rgba(91,91,91,1.0)',
- borderColor: 'rgba(120,120,120,1.0)',
- timeLabelColor: 'rgba(214,214,214,1.0)',
- indicatorColor: 'rgba(210,210,210,0.5)',
- bkColor: 'rgba(0,0,0,1.0)',
- buttonImage: ButtonImage,
- resolution: 1
- },
- btipShow: false,
- tipShowPen: null,
- vIndicator: null,
- hIndicator: null,
- chartWidth: 0,
- chartHeight: 0,
- ftBeginTime: 0,
- ftTimeLabelBeg: null,
- ctx: null,
- canvas: null,
- buttonsDrawed: false,
- trendPens: null,
- webLinks: null,
- _create: function () {
- console.log('_create');
-
- var configs = localStorage.getItem("goldenTrendConfig");
- if (configs) {
- try {
- configs = JSON.parse(configs);
- } catch (ex) {
- localStorage.removeItem("goldenTrendConfig");
- configs = null;
- }
- var config = configs[groupName];
- if (config != null && typeof (config) != "undefined") {
-
-
- this.options.bDeafult = config.bDeafult;
- this.options.bkColor = config.bkColor;
- this.options.borderColor = config.borderColor;
- this.options.gridColor = config.gridColor;
- this.options.indicatorColor = config.indicatorColor;
- this.options.listExpand = config.listExpand;
- this.options.listHeight = config.listHeight;
- this.options.panShow = config.panShow;
- this.options.panWidth = config.panWidth;
- this.options.rtRefresh = config.rtRefresh;
- this.options.showAxis = config.showAxis;
- this.options.showGrid = config.showGrid;
- this.options.showList = config.showList;
- this.options.showThumbs = config.showThumbs;
- this.options.spanSec = config.spanSec;
- this.options.timeLabelColor = config.timeLabelColor;
- this.options.tooltipDelay = config.tooltipDelay;
- this.options.freeRange = config.freeRange;
- }
- }
- this.options.spanSec = this.options.spanSec || 1;
- if (!this.options.spanSec || this.options.spanSec < 1)
- this.options.spanSec = 1;
- var date = new Date();
- date.setMilliseconds(0);
- date = this.DateToFileTime(date);
- date += PERSEC;
- date -= this.options.spanSec * PERSEC;
- this.setBeginTime(date);
- this._buildChart();
- this.element.uniqueId();
- $(window).resize(this, function (e) {
- e.data._onResize();
- });
- this.yScroll = 0;
- var rtchart = this;
- var X, Y;
- $(document).bind('mousemove.rtChart_' + this.element.attr('id'), function (e) {
- if (X === e.clientX && Y === e.clientY)
- return;
- X = e.clientX;
- Y = e.clientY;
- if (rtchart.mouseTimer) {
- window.clearTimeout(rtchart.mouseTimer);
- rtchart.mouseTimer = null;
- }
- if (rtchart.tooltipTimer && e.target != rtchart.vIndicator[0] && e.target != rtchart.hIndicator[0]) {
- window.clearTimeout(rtchart.tooltipTimer);
- rtchart.tooltipTimer = null;
- }
- if (e.target == rtchart.canvas[0]) {
- rtchart.mouseTimer = window.setTimeout(function () {
- window.clearTimeout(rtchart.mouseTimer);
- rtchart.mouseTimer = null;
- rtchart._onMouseMove(e);
- }, 200);
- }
- });
- $(window).bind('keydown.rtChart_' + this.element.attr('id'), function (e) {
- rtchart._onKeyDown(e);
- });
- var url = location.href;
- var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
- var paraObj = {}
- for (i = 0; j = paraString[i]; i++) {
- paraObj[decodeURIComponent(j.substring(0, j.indexOf("=")))] = decodeURIComponent(j.substring(j.indexOf("=") + 1, j.length));
- }
- if (paraObj.pointGroupName != null)
- this.options.pointGroupName = paraObj.pointGroupName;
- if (this.options.pointGroupName == null) {
- if (paraObj.pointGroupName != null)
- this.options.pointGroupName = paraObj.pointGroupName;
- else if (paraObj.newPointGroup != null) {
- this.isNewPage = true;
- var d = dialog({
- content: "可以在新打开的页中进行点组的设置操作,然后保存点组,<br>从而创建新的点组。",
- quickClose: true
- });
- d.show();
- window.setTimeout(function () {
- d.close().remove();
- d = null;
- }, 2000);
- }
- }
- if (typeof (Flag) != "undefined" && Flag != null || Flag != "") {
- if (Flag == "tagName") {
- if (typeof (tagName) != "undefined" && tagName != null || tagName != "") {
- var that = this;
- (function () {
- tagName = decodeURIComponent(tagName);
- var tagNameArr = tagName.split(',');
- for (var i = 0, len = tagNameArr.length; i < len; i++) {
- tagName = tagNameArr[i];
- var itemDef = new GoldenRtWeb.RtItemDefine(0, 0, 0);
- that.AddPen({
- URI: tagName,
- itemDef: itemDef
- });
- that.requestHisData({
- URI: tagName,
- itemDef: itemDef
- }, 100);
- }
- })();
- }
- } else {
- if (typeof (groupName) != "undefined" && groupName != null || groupName != "") {
- if (Flag == "pointGroupName") {
- var that = this;
- (function () {
- groupName = decodeURIComponent(groupName);
- var pointGroups = JSON.parse(localStorage.getItem("goldenTrendConfig"));
-
- for (var key in pointGroups) {
- if (groupName == key) {
- for (var i = 0; i < pointGroups[key].trendPens.length; i++) {
-
- that.AddPen(pointGroups[key].trendPens[i]);
- }
- }
- }
- })();
- }
- }
- }
- }
-
-
- },
- _loadPointGroup: function () {
- var groupName = "";
- if (this.options.pointGroupName != null)
- groupName = this.options.pointGroupName;
- var rtchart = this;
- var configs = localStorage.getItem("goldenTrendConfig");
- if (configs == null)
- return;
- if (configs) {
- try {
- configs = JSON.parse(configs);
- } catch (ex) {
- localStorage.removeItem("goldenTrendConfig");
- configs = null;
- }
- }
- var config = configs[groupName];
- if (config == null) {
- groupName = Object.keys(configs)[0];
- config = configs[groupName];
- }
- this.loadConfig(groupName, config);
- },
- _init: function () {
- console.log('_init');
- },
- _destroy: function () {
- console.log('_destroy');
- $(document).unbind('mousemove.rtChart_' + this.element.attr('id'));
- $(document).unbind('keydown.rtChart_' + this.element.attr('id'));
- this._clear();
- if (this.webLinks) {
- for (i in this.webLinks) {
- var link = this.webLinks[i];
- link.destroy();
- delete link;
- }
- delete this.webLinks;
- }
- if (this.trendPens) {
- for (i in this.trendPens) {
- var pen = this.trendPens[i];
- pen.destroy();
- delete pen;
- }
- delete this.trendPens;
- }
- },
- _isTouch: function () {
- return document.ontouchstart !== undefined;
- },
- _buildChart: function () {
- this._clear();
- this._bulidCanvas();
- console.log('chartBuided');
- },
- _clear: function () {
- this.btipShow = false;
- if (this.artTooltip)
- this.artTooltip.close().remove();
- if (this.tooltipTimer) {
- window.clearTimeout(this.tooltipTimer);
- this.tooltipTimer = null;
- }
- if (this.updateDataTimer) {
- window.clearTimeout(this.updateDataTimer);
- this.updateDataTimer = null;
- }
- if (this.updatePanTimer) {
- window.clearTimeout(this.updatePanTimer);
- this.updatePanTimer = null;
- }
- if (this.prepareTimer) {
- window.clearTimeout(this.prepareTimer);
- this.prepareTimer = null;
- }
- if (this.mouseTimer) {
- window.clearTimeout(this.mouseTimer);
- this.mouseTimer = null;
- }
- if (this.options.buttonImage)
- this.options.buttonImage.unbind();
- if (this.tipShowPen) {
- this.tipShowPen.onTooltipHided();
- this.tipShowPen = null;
- }
- if (this.activePen) {
- this.activePen.setActive(false);
- this.activePen = null;
- if (this.toolBar)
- this.toolBar.disableItem("deletePoint");
- }
- if (this.colorPicker) {
- $('.colorpicker-ind', this.colorPicker).colorpicker('destroy');
- this.colorPicker.draggable("destroy");
- this.colorPicker.empty();
- delete this.colorPicker;
- }
- if (this.vSplite) {
- if (this.vSplite.data('drag') === true)
- this.vSplite.draggable("destroy");
- this.vSplite.unbind();
- this.vSplite = null;
- }
- if (this.hSplite) {
- if (this.hSplite.data('drag') === true)
- this.hSplite.draggable("destroy");
- this.hSplite.unbind();
- this.hSplite = null;
- }
- if (this.vIndicator) {
- this.vIndicator.unbind();
- this.vIndicator.draggable("destroy");
- this.vIndicator = null;
- }
- if (this.hIndicator) {
- this.hIndicator.unbind();
- this.hIndicator.draggable("destroy");
- this.hIndicator = null;
- }
- if (this.ctx)
- delete this.ctx;
- if (this.canvas) {
- this.canvas.unbind();
- delete this.canvas;
- }
- if (this.toolCalendar) {
- this.toolCalendar.unload();
- delete this.toolCalendar;
- }
- if (this.toolBar) {
- this.toolBar.unload();
- this.toolBar = null;
- }
- if (this.toolBarContainer) {
- this.toolBarContainer.remove();
- this.toolBarContainer = null;
- }
- if (this.artTooltip) {
- this.artTooltip.remove();
- delete this.artTooltip;
- }
- if (this.positionDiv) {
- this.positionDiv.unbind();
- this.positionDiv.draggable("destroy");
- this.positionDiv.remove();
- this.positionDiv = null;
- }
- if (this.thumbBegDiv) {
- this.thumbBegDiv.unbind();
- this.thumbBegDiv.draggable("destroy");
- this.thumbBegDiv.remove();
- this.thumbBegDiv = null;
- }
- if (this.thumbEndDiv) {
- this.thumbEndDiv.unbind();
- this.thumbEndDiv.draggable("destroy");
- this.thumbEndDiv.remove();
- this.thumbEndDiv = null;
- }
- this.buttonsDrawed = false;
- if (this.listGrid) {
- this.listGrid.clearAll(true);
- this.listGrid.destructor();
- delete this.listGrid;
- }
- if (this.listContainer) {
- this.listContainer.remove();
- this.listContainer = null;
- }
- this.element.empty();
- },
- _bulidCanvas: function () {
- this.chartWidth = this.element.width();
- this.chartHeight = this.element.height();
- if (!this.chartWidth || !this.chartHeight)
- throw 'container not visable\'t exist';
- var gw = this.getGridWidth();
- var gh = this.getGridHeight();
- var gt = this.toolBarCanShow() ? TOOLBARHEIGHT : 0;
- var cavansHight = gh;
- if (this.slidCanShow())
- cavansHight += SLIDEHEIGHT;
- if (this.thumbsCanshow())
- cavansHight += SHOWTHUMBSHEIGHT;
- if (this.listCanshow())
- if (this.chartWidth < 100 + this.options.panWidth || this.options.panWidth < MINPANWIDTH)
- this.options.panShow = false;
- var rtchart = this;
- if (!this.canvas) {
- this.canvas = $(document.createElement('canvas'));
- this.element.append(this.canvas);
- this.canvas.bind('click', function (e) {
- rtchart._onClick(e);
- });
- this.canvas.bind('dblclick', function (e) {
- rtchart._ondbClick(e);
- });
- this.canvas.bind('mousedown', function (e) {
- rtchart._onMouseDown(e);
- });
- this.canvas.bind('mousewheel', function (e) {
- e.preventDefault();
- rtchart._onMouseWheel(e);
- });
- this.canvas.bind('mousemove', function (e) {
- rtchart._onRtchartMouseMove(e);
- });
- if (this._isTouch()) {
- this.canvas.bind('touchstart', function (e) {
- rtchart._onTouchStart(e);
- });
- }
- }
- this.canvas.css("position", "absolute")
- .css("left", 0)
- .css("top", gt)
- .css("right", 0)
- .css("height", cavansHight);
- if (this.options.bkColor != null)
- this.canvas.css('background-color', this.options.bkColor);
- this.canvas.attr("width", this.chartWidth * this.options.resolution);
- this.canvas.attr("height", cavansHight * this.options.resolution);
- var node = this.canvas.get(0);
- if (window.G_vmlCanvasManager)
- window.G_vmlCanvasManager.initElement(node);
- this.ctx = node.getContext('2d');
- if (!window.G_vmlCanvasManager)
- this.ctx.scale(this.options.resolution, this.options.resolution);
- if (this.positionDiv) {
- this.positionDiv.draggable("destroy");
- this.positionDiv.unbind();
- this.positionDiv.remove();
- this.positionDiv = null;
- }
- if (this.thumbBegDiv) {
- this.thumbBegDiv.draggable("destroy");
- this.thumbBegDiv.unbind();
- this.thumbBegDiv.remove();
- this.thumbBegDiv = null;
- }
- if (this.thumbEndDiv) {
- this.thumbEndDiv.draggable("destroy");
- this.thumbEndDiv.unbind();
- this.thumbEndDiv.remove();
- this.thumbEndDiv = null;
- }
- if (this.toolBarContainer == null) {
- this.toolBarContainer = $(document.createElement('div'));
- this.element.append(this.toolBarContainer);
- }
- this.toolBarContainer.css("position", "absolute")
- .css("left", 0)
- .css("top", -2)
- .css("right", 0)
- .css("height", TOOLBARHEIGHT)
- .addClass('unselectable');
- this.calendarShowed = false;
- this.timerFocus = false;
- if (this.toolBar == null) {
- this.toolBar = new dhtmlXToolbarObject(this.toolBarContainer.get(0), "dhx_web");
- this.toolBar.setIconsPath("htm/codebase/dhtmlxToolbar/codebase/icon/");
- this.toolBar.addButton("addPoint", 0, null, "plus.png", "plus_dis.png");
- this.toolBar.setItemToolTip("addPoint", "添加新点");
- this.toolBar.addButton("deletePoint", 1, null, "deletepen.png", "deletepen_dis.png");
- this.toolBar.setItemToolTip("deletePoint", "移除当前选定点");
- this.toolBar.disableItem("deletePoint");
- if (this.options.showAxis) {
- this.toolBar.addButtonTwoState("showAxis", 2, null, "axis.png", "axis_dis.png");
- this.toolBar.setItemState("showAxis", true);
- this.toolBar.setItemToolTip("showAxis", "当前为值轴显示模式,单击转变为数据板显示模式");
- } else {
- this.toolBar.addButtonTwoState("showAxis", 2, null, "datapan.png", "datapan_dis.png");
- this.toolBar.setItemState("showAxis", false);
- this.toolBar.setItemToolTip("showAxis", "当前为数据板显示模式,单击转变为值轴显示模式");
- }
- if (this.options.freeRange) {
- this.toolBar.addButtonTwoState("toggleRange", 3, null, "view_type_free.png", "view_type_free.png");
- this.toolBar.setItemState("toggleRange", true);
- this.toolBar.setItemToolTip("toggleRange", "当前量程为自由量程,点击切换到固定量程");
- } else {
- this.toolBar.addButtonTwoState("toggleRange", 3, null, "view_type.png", "view_type.png");
- this.toolBar.setItemState("toggleRange", false);
- this.toolBar.setItemToolTip("toggleRange", "当前量程为固定量程,点击切换到自由量程");
- }
- this.toolBar.addButton("colorPicker", 4, null, "colorpicker.png", "colorpicker_dis.png");
- this.toolBar.setItemToolTip("colorPicker", "设置颜色");
- this.toolBar.addButton("saveConfig", 4, null, "save.png", "save.png");
- this.toolBar.setItemToolTip("saveConfig", "保存设置(如改变点组名称,可另存新建点组)");
- var opts =
- [
- ['newPiointGroup', 'obj', '新建点组', 'window_new.png'],
- ['editorPointGroup', 'obj', '编辑点组...', 'tag_blue_edit.png'],
- ['refreshPointGroup', 'obj', '刷新点组列表', 'reload.png'],
- ['idsep', 'sep']
- ];
- this.toolBar.addButtonSelect("pointGroup", 5, "点组", opts, "tag.png");
- this.toolBar.addSeparator("rtSep", 6);
-
-
-
- this.toolBar.addButton("zoomToool", 8, null, "zoom.png", "zoom_dis.png");
- this.toolBar.setItemToolTip("zoomToool", "趋势缩放");
- this.toolBar.addButton("zoomResume", 9, null, "zoom_resume.png", "zoom_resume_dis.png");
- this.toolBar.setItemToolTip("zoomResume", "恢复缩放");
- this.toolBar.disableItem("zoomResume");
- this.toolBar.addSeparator("rtSep4", 10);
- if (this.options.rtRefresh) {
- this.toolBar.addButtonTwoState("reRefresh", 11, null, "refresh.png", "refresh_dis.png");
- this.toolBar.setItemState("reRefresh", true);
- this.toolBar.setItemToolTip("reRefresh", "当前为实时刷新模式,单击转变为静态查询模式");
- } else {
- this.toolBar.addButtonTwoState("reRefresh", 11, null, "query.png", "query_dis.png");
- this.toolBar.setItemState("reRefresh", false);
- this.toolBar.setItemToolTip("reRefresh", "当前为静态查询模式,单击转变为实时刷新模式");
- }
- this.toolBar.addSeparator("rtSep1", 12);
- this.toolBar.addButton("timePrev", 13, null, "previous.png", "previous_dis.png");
- this.toolBar.setItemToolTip("timePrev", "前翻半个时间跨度");
- var spanopts = [
- ['b1m', 'obj', '当前时间 10分钟前', "left.png"],
- ['b3m', 'obj', '当前时间 30分钟前', "left.png"],
- ['b1h', 'obj', '当前时间 1小时前', "left.png"],
- ['b2h', 'obj', '当前时间 2小时前', "left.png"],
- ['b8h', 'obj', '当前时间 8小时前', "left.png"],
- ['b12h', 'obj', '当前时间 12小时前', "left.png"],
- ['spansep', 'sep'],
- ['b1d', 'obj', '当前时间 1天 前', "left.png"],
- ['b2d', 'obj', '当前时间 2天 前', "left.png"],
- ['b7d', 'obj', '当前时间 7天 前', "left.png"],
-
-
-
-
-
-
-
-
- ];
- this.toolBar.addButtonSelect("timeSpan", 14, this.getTimeSpanString(), spanopts, null);
- this.toolBar.addButton("timeNext", 15, null, "next.png", "next_dis.png");
- this.toolBar.setItemToolTip("timeNext", "后翻半个时间跨度");
- this.toolBar.addSeparator("rtSep2", 16);
- this.toolBar.addInput("date_from", 17, "", 128);
- this.toolBar.addInput("date_to", 18, "", 128);
- this._updateTimeDisplay();
- this.toolBar.addButton("goDate", 19, null, "find.png", "find_dis.png");
- this.toolBar.setItemToolTip("goDate", "点击执行查询");
- var from = this.toolBar.getInput("date_from");
- var to = this.toolBar.getInput("date_to");
- $(from).focusin(function () {
- rtchart.timerFocus = true;
- });
- $(to).focusin(function () {
- rtchart.timerFocus = true;
- });
- $(from).focusout(function () {
- rtchart.timerFocus = false;
- });
- $(to).focusout(function () {
- rtchart.timerFocus = false;
- });
- this.toolCalendar = new dhtmlXCalendarObject([from, to]);
- this.toolCalendar.setDateFormat("%Y-%m-%d %H:%i:%s");
- this.toolCalendar.setMinutesInterval(1);
- this.toolCalendar.loadUserLanguage("cn");
- this._updateTimeDisplay();
- this.toolCalendar.attachEvent("onShow", function () {
- rtchart.calendarShowed = true;
- });
- this.toolCalendar.attachEvent("onHide", function () {
- rtchart.calendarShowed = false;
- });
- this.toolCalendar.attachEvent("onClick", function (date) {
- if (document.activeElement == $(from)[0]) {
- var button = document.activeElement.parentElement.nextElementSibling.nextElementSibling;
- var d = dialog({
- content: "点击按钮进行查询操作或进行其他查询设置,\n点击工具条空白处取消文本框编辑状态。",
- quickClose: true
- });
- d.show(button);
- window.setTimeout(function () {
- d.close().remove();
- d = null;
- }, 2000);
- } else if (document.activeElement == $(to)[0]) {
- var button = document.activeElement.parentElement.nextElementSibling;
- var d = dialog({
- content: "点击按钮进行查询操作或进行其他查询设置,\n点击工具条空白处取消文本框编辑状态。",
- quickClose: true
- });
- d.show(button);
- window.setTimeout(function () {
- d.close().remove();
- d = null;
- }, 2000);
- }
- });
- var excelopts = [
- ['exportToExcelInterpo', 'obj', '导出统一时间坐标的内插值', null],
- ['exportExcel', 'obj', '导出时间坐标不同的归档值', null]
-
- ];
- this.toolBar.addButtonSelect("exportExceltool", 20, null, excelopts, "excel.png", "excel_dis.png");
- this.toolBar.setItemToolTip("exportExceltool", "导出");
-
-
-
-
-
-
- this.toolBar.addButton("exportPng", 21, null, "mime_png.png", "mime_png.png");
- this.toolBar.setItemToolTip("exportPng", "导出打印位图");
- this.toolBar.addSeparator("rtSep3", 22);
-
- this.toolBar.attachEvent("onClick", function (id) {
- rtchart.timerFocus = false;
- rtchart.calendarShowed = false;
- $(from).blur();
- $(to).blur();
- switch (id) {
- case "addPoint":
- rtchart._onAddPoint();
- break;
- case "addGroup":
- if (rtchart.listGrid.getRowsNum()) {
- var pens = rtchart.listGrid.getRowsNum();
- for (var i = 1; i <= pens; i++) {
- var rowid = i;
- var pen = rtchart.getPenByRowId(rowid);
- if (pen)
- rtchart.removePen(pen);
- }
- }
- if (rtchart.artTooltip)
- rtchart.artTooltip.close().remove();
- break;
- case "saveGroup":
- rtchart._onSaveGroup();
- break;
- case "deletePoint":
- if (rtchart.listGrid.getSelectedRowId()) {
- var pens = rtchart.listGrid.getSelectedRowId();
- pens = pens.split(',');
- if (pens) {
- for (var i = 0; i < pens.length; i++) {
- var rowid = pens[i];
- var pen = rtchart.getPenByRowId(rowid);
- if (pen)
- rtchart.removePen(pen);
- }
- }
- }
- break;
- case "editorPointGroup":
- rtchart._onEditorPointGroup();
- break;
- case "colorPicker":
- rtchart._onSetColors();
- break;
- case "saveConfig":
- rtchart._onSaveConfig();
- break;
- case "exportExcel":
- rtchart._onExportExcel();
- break;
- case "exportToExcelInterpo":
- rtchart._onExportToExcelInterpo();
- break;
- case "exportPng":
- rtchart._onExportPng();
- break;
- case "mpass":
- rtchart._onModifyPassWord();
- break;
- case "accmag":
- rtchart._onUserMagement();
- break;
- case "login":
- rtchart.requestLogin("_login", true);
- break;
- case "logout":
- rtchart.logout();
- break;
- case "goDate":
- rtchart._queryHisData($(from), $(to));
- break;
- case "refreshPointGroup":
- rtchart._loadPointGroupNames();
- break;
- case "newPiointGroup":
- var url = location.href;
- if (url.indexOf("?") > 0)
- url = url.substr(0, url.indexOf("?"));
- url += "?webServiceIP=" + webServiceIP + "&webServicePort=" + webServicePort + "";
- url += "&newPointGroup=1";
- window.open(url, "_blank");
- break;
- case "zoomToool":
- rtchart._toggleZoom();
- break;
- case "zoomResume":
- rtchart._onReZoom();
- break;
- case "timePrev":
- rtchart.updateBeginTime(rtchart.getBegTime() - 0.5 * rtchart.options.spanSec * PERSEC);
- break;
- case "timeNext":
- rtchart.updateBeginTime(rtchart.getBegTime() + 0.5 * rtchart.options.spanSec * PERSEC);
- break;
- case 'b1m':
- var date = new Date();
- date.setMilliseconds(0);
- date = rtchart.DateToFileTime(date);
- date += PERSEC;
- date -= 600 * PERSEC;
- rtchart.setBegTimeAndSpan(date, 600);
- break;
- case 'b3m':
- var date = new Date();
- date.setMilliseconds(0);
- date = rtchart.DateToFileTime(date);
- date += PERSEC;
- date -= 1800 * PERSEC;
- rtchart.setBegTimeAndSpan(date, 1800);
- break;
- case 'b1h':
- var date = new Date();
- date.setMilliseconds(0);
- date = rtchart.DateToFileTime(date);
- date += PERSEC;
- date -= 3600 * PERSEC;
- rtchart.setBegTimeAndSpan(date, 3600);
- break;
- case 'b2h':
- var date = new Date();
- date.setMilliseconds(0);
- date = rtchart.DateToFileTime(date);
- date += PERSEC;
- date -= 2 * 3600 * PERSEC;
- rtchart.setBegTimeAndSpan(date, 2 * 3600);
- break;
- case 'b8h':
- var date = new Date();
- date.setMilliseconds(0);
- date = rtchart.DateToFileTime(date);
- date += PERSEC;
- date -= 8 * 3600 * PERSEC;
- rtchart.setBegTimeAndSpan(date, 8 * 3600);
- break;
- case 'b12h':
- var date = new Date();
- date.setMilliseconds(0);
- date = rtchart.DateToFileTime(date);
- date += PERSEC;
- date -= 12 * 3600 * PERSEC;
- rtchart.setBegTimeAndSpan(date, 12 * 3600);
- break;
- case 'b1d':
- var date = new Date();
- date.setMilliseconds(0);
- date = rtchart.DateToFileTime(date);
- date += PERSEC;
- date -= 24 * 3600 * PERSEC;
- rtchart.setBegTimeAndSpan(date, 24 * 3600);
- break;
- case 'b2d':
- var date = new Date();
- date.setMilliseconds(0);
- date = rtchart.DateToFileTime(date);
- date += PERSEC;
- date -= 2 * 24 * 3600 * PERSEC;
- rtchart.setBegTimeAndSpan(date, 2 * 24 * 3600);
- break;
- case 'b7d':
- var date = new Date();
- date.setMilliseconds(0);
- date = rtchart.DateToFileTime(date);
- date += PERSEC;
- date -= 7 * 24 * 3600 * PERSEC;
- rtchart.setBegTimeAndSpan(date, 7 * 24 * 3600);
- break;
- case 'a1m':
- rtchart.setTimeSpan(600, false);
- break;
- case 'a1h':
- rtchart.setTimeSpan(3600, false);
- break;
- case 'a2h':
- rtchart.setTimeSpan(2 * 3600, false);
- break;
- case 'a8h':
- rtchart.setTimeSpan(8 * 3600, false);
- break;
- case 'a1d':
- rtchart.setTimeSpan(24 * 3600, false);
- break;
- case 'a2d':
- rtchart.setTimeSpan(2 * 24 * 3600, false);
- break;
- case 'a7d':
- rtchart.setTimeSpan(7 * 24 * 3600, false);
- break;
- default:
- if (rtchart.pointGroups) {
- for (var n in rtchart.pointGroups) {
- var config = rtchart.pointGroups[n];
- if (id == config.Id) {
- var gName = n;
- if (gName && gName.length) {
- var url = location.href;
- if (url.indexOf("?") > 0)
- url = url.substr(0, url.indexOf("?"));
- url += "?webServiceIP=" + webServiceIP + "&webServicePort=" + webServicePort + "";
- url += "&pointGroupName=" + encodeURI(gName);
- if (rtchart.isFullScreen() === true)
- window.location.href = url;
- else
- window.open(url, "_blank");
- }
- break;
- }
- }
- break;
- }
- }
- });
- this.toolBar.attachEvent("onStateChange", function (id) {
- switch (id) {
- case "reRefresh":
- if (rtchart.toolBar.getItemState("reRefresh"))
- rtchart.setRtrefresh(true);
- else
- rtchart.setRtrefresh(false);
- break;
- case "showAxis":
- if (rtchart.toolBar.getItemState("showAxis"))
- rtchart.setShowAxis(true);
- else
- rtchart.setShowAxis(false);
- break;
- case "fullScreen":
- rtchart.onFullScreenSet();
- break;
- case "toggleRange":
- rtchart.toggleRangeMode();
- break;
- }
- });
- this._loadPointGroupNames();
- var elem = document.documentElement;
- if (elem.requestFullscreen) {
- this.requestFullScreen = function () {
- var docElm = document.documentElement;
- docElm.requestFullscreen();
- }
- this.isFullScreen = function () {
- return document.fullscreen;
- }
- } else if (elem.mozRequestFullScreen) {
- this.requestFullScreen = function () {
- var docElm = document.documentElement;
- docElm.mozRequestFullScreen();
- }
- this.isFullScreen = function () {
- return document.mozFullScreen;
- }
- } else if (elem.webkitRequestFullScreen) {
- this.requestFullScreen = function () {
- var docElm = document.documentElement;
- docElm.webkitRequestFullScreen();
- }
- this.isFullScreen = function () {
- return document.webkitIsFullScreen;
- }
- } else if (elem.msRequestFullscreen) {
- this.requestFullScreen = function () {
- var docElm = document.documentElement;
- docElm.msRequestFullscreen();
- }
- this.isFullScreen = function () {
- return document.msFullscreenElement;
- }
- }
- if (document.exitFullscreen) {
- this.cancelFullScreen = function () {
- document.exitFullscreen();
- }
- } else if (document.mozCancelFullScreen) {
- this.cancelFullScreen = function () {
- document.mozCancelFullScreen();
- }
- } else if (document.webkitCancelFullScreen) {
- this.cancelFullScreen = function () {
- document.webkitCancelFullScreen();
- }
- } else if (document.msExitFullscreen) {
- this.cancelFullScreen = function () {
- document.msExitFullscreen();
- }
- }
- }
- this.positionDiv = $(document.createElement('div'));
- this.element.append(this.positionDiv);
- this.positionDiv.css("position", "absolute")
- .css("left", 0)
- .css("top", gt)
- .css("width", 6)
- .css("height", 6)
- .css(" z-index", 200)
- .addClass('unselectable')
- .draggable({
- disabled: true,
- scroll: false,
- containment: [
- this.canvas.offset().left - 2,
- this.canvas.offset().top + gt,
- this.canvas.offset().left + this.canvas.width() - 5,
- this.canvas.offset().top + gt + this.canvas.height()
- ]
- });
- if (this.thumbsCanshow()) {
- gt += gh + TIMELABELHEIGHT;
- var h = SHOWTHUMBSHEIGHT + 3;
- this.thumbBegDiv = $(document.createElement('div'));
- this.element.append(this.thumbBegDiv);
- this.thumbBegDiv.css("position", "absolute")
- .css("left", -3)
- .css("top", gt)
- .css("width", 7)
- .css("height", h)
- .css("cursor", "e-resize")
- .css(" z-index", 200)
- .addClass('unselectable')
- .addClass('hspelit')
- .draggable({
- containment: [this.canvas.offset().left - 3, 0, this.canvas.offset().left + this.chartWidth - 18, gh],
- axis: "x",
- scroll: false,
- drag: function (event, ui) {
- rtchart._onThumbsChanged();
- }
- });
- this.thumbEndDiv = $(document.createElement('div'));
- this.element.append(this.thumbEndDiv);
- this.thumbEndDiv.css("position", "absolute")
- .css("left", this.chartWidth - 3)
- .css("top", gt)
- .css("width", 7)
- .css("height", h)
- .css("cursor", "e-resize")
- .css(" z-index", 200)
- .addClass('unselectable')
- .addClass('hspelit')
- .draggable({
- containment: [this.canvas.offset().left + 18, 0, this.canvas.offset().left + this.chartWidth - 3, gh],
- axis: "x",
- scroll: false,
- drag: function (event, ui) {
- rtchart._onThumbsChanged();
- }
- });
- gt += h;
- }
- if (this.listContainer) {
- this.listContainer.remove();
- this.listContainer = null;
- }
- if (this.listCanshow() && this.options.listExpand) {
- gt += 4;
- this.listContainer = $(document.createElement('div'));
- this.element.append(this.listContainer);
- this.listContainer.css("position", "absolute")
- .css("left", 0)
- .css("right", 0)
- .css("top", gt)
- .css("bottom", 0)
- .css("border", "1px solid rgb(60,60,60)")
- .addClass('unselectable');
- this.listGrid = new dhtmlXGridObject(this.listContainer.get(0));
- this.listGrid.setImagePath("htm/codebase/dhtmlxGrid/codebase/imgs/");
- this.listGrid.setHeader("点名称,线宽,描述,显示,数据时间,数据值,量程下限,量程上限,量程锁定,阶跃,标记,实时值,最大值,最小值,平均值");
- this.listGrid.setColAlign("left,center,left,center,right,right,right,right,center,center,right,right,center,right,right");
- this.listGrid.setInitWidths("160,50,180,45,140,120,100,100,65,45,45,110,110,110,110");
- this.listGrid.setColTypes("clrlabel,combo,ro,ch,ro,ro,edn,edn,ch,ch,ch,vqtcell,vqtcellclick,vqtcellclick,unitval");
- this.listGrid.setColSorting("str,str,str,na,na,na,na,na,na,na,na,na,na,na,na");
- this.listGrid.enableColumnMove(true);
- this.listGrid.enableDragAndDrop(true);
- this.listGrid.setSkin("dhx_web");
- this.listGrid.enableColumnAutoSize(true);
- this.listGrid.enableMultiselect(true);
- this.listGrid.init();
- var combo = this.listGrid.getColumnCombo(1);
- combo.addOption("1", "1");
- combo.addOption("2", "2");
- combo.addOption("3", "3");
- combo.addOption("4", "4");
- combo.addOption("5", "5");
- combo.addOption("6", "6");
- combo.addOption("7", "7");
- combo.addOption("8", "8");
- this.listGrid.onSetLabelColor = function (e, rowid) {
- (e || event).cancelBubble = true;
- var pen = rtchart.getPenByRowId(rowid);
- if (pen) {
- rtchart.setPenColor(pen, e);
- }
- };
- this.listGrid.onPosVQT = function (e, rowid, tip) {
- (e || event).cancelBubble = true;
- var pen = rtchart.getPenByRowId(rowid);
- if (pen) {
- pen.posVQT(tip);
- }
- };
- this.listGrid.attachEvent("onSelectStateChanged", function (rowid) {
- if (rowid && rowid != "") {
- var pens = rowid.split(",");
- if (pens && pens.length) {
- var pen = rtchart.getPenByRowId(pens[0]);
- if (pen != rtchart.activePen)
- rtchart.requestActive(pen);
- } else
- rtchart.requestActive(null);
- } else
- rtchart.requestActive(null);
- });
- this.listGrid.attachEvent("onAfterSorting", function (index, type, direction) {
- rtchart._onListSorted();
- });
- this.listGrid.attachEvent("onCheck", function (rowid, cInd, state) {
- var pen = rtchart.getPenByRowId(rowid);
- if (pen != null) {
- var col = rtchart.listGrid.getColumnLabel(cInd);
- switch (col) {
- case "显示":
- pen.setDisplay(state, false);
- break;
- case "阶跃":
- pen.setStepLine(state, false);
- break;
- case "标记":
- pen.setDrawTag(state, false);
- break;
- case "插值":
- pen.setInterpolate(state, false);
- break;
- case "量程锁定":
- pen.setRangeLock(state, false);
- break;
- }
- }
- });
- this.listGrid.attachEvent("onDrop", function (sId, tId, dId, sObj, tObj, sCol, tCol) {
- rtchart._onListSorted();
- });
- this.listGrid.attachEvent("onCellChanged", function (rId, cInd, nValue) {
- var pen = rtchart.getPenByRowId(rId);
- if (pen != null) {
- var col = rtchart.listGrid.getColumnLabel(cInd);
- switch (col) {
- case "量程下限":
- pen.onSetMinRange(nValue);
- break;
- case "量程上限":
- pen.onSetMaxRange(nValue);
- break;
- case "线宽":
- pen.onSetLineWidth(nValue, true);
- break;
- }
- }
- });
- this._synList();
- }
- this._reDrawAll();
- },
- onFullScreenSet: function () {
- if (this.isFullScreen()) {
- this.cancelFullScreen();
- this.toolBar.setItemState("fullScreen", false);
- this.toolBar.setItemToolTip("fullScreen", "单击进入全屏显示模式(F11)");
- this.toolBar.setItemImage("fullScreen", "fullscreen.png");
- } else {
- this.requestFullScreen();
- this.toolBar.setItemState("fullScreen", true);
-
- this.toolBar.setItemImage("fullScreen", "leave_fullscreen.png");
- }
- },
- logout: function () {
- var xhr = $.ajax({
- url: GoldenRtWeb.getWebURL() + '/Logout',
- type: "GET",
- processData: false,
- complete: function (xhr, ts) {
- var url = window.location.href;
- var index = url.lastIndexOf('?');
- if (index > 0)
- url = url.substr(0, index);
- window.location = url;
- }
- });
- },
- _onExportPng: function () {
-
-
-
-
-
-
-
- this. _downloadFile('趋势图.png', this.canvas[0].toDataURL("image/png"));
- },
- _downloadFile: function (fileName, content) {
- var aLink = document.createElement('a');
- var blob =this._base64Img2Blob(content);
- var evt = document.createEvent("HTMLEvents");
- evt.initEvent("click", false, false);
- aLink.download = fileName;
- aLink.href = URL.createObjectURL(blob);
- aLink.dispatchEvent(evt);
- aLink.click();
- },
- _base64Img2Blob: function (code) {
- var parts = code.split(';base64,');
- var contentType = parts[0].split(':')[1];
- var raw = window.atob(parts[1]);
- var rawLength = raw.length;
- var uInt8Array = new Uint8Array(rawLength);
- for (var i = 0; i < rawLength; ++i) {
- uInt8Array[i] = raw.charCodeAt(i);
- }
- return new Blob([uInt8Array], { type: contentType });
- },
- _onExportToExcelInterpo: function () {
- if (!this.trendPens || !this.trendPens.length) {
- var d = dialog({
- content: "目前尚未加载点信息,因此无法进行导出操作。",
- quickClose: true
- });
- d.show();
- window.setTimeout(function () {
- d.close();
- d.remove();
- d = null;
- }, 2000);
- return;
- }
- var pens = [];
- for (var i = 0; i < this.trendPens.length; i++) {
- var pen = this.trendPens[i];
- pens.push(pen.getURI());
- }
- pens = pens.join(';');
- var uri = "beginTime=" + this.getBegTime();
- uri += "&endTime=" + this.getEndTime();
- uri += "&point=" + pens;
- var link = document.createElement("a");
- link.download = "exportExcel";
- link.href = this.getWebURL() + "ExportToExcelInterpo?" + encodeURI(uri);
- link.click();
- },
- _onExportExcel: function () {
- if (!this.trendPens || !this.trendPens.length) {
- var d = dialog({
- content: "目前尚未加载点信息,因此无法进行导出操作。",
- quickClose: true
- });
- d.show();
- window.setTimeout(function () {
- d.close();
- d.remove();
- d = null;
- }, 2000);
- return;
- }
- var pens = [];
- for (var i = 0; i < this.trendPens.length; i++) {
- var pen = this.trendPens[i];
- pens.push(pen.getURI());
- }
- pens = pens.join(';');
- var uri = "beginTime=" + this.getBegTime();
- uri += "&endTime=" + this.getEndTime();
- uri += "&point=" + pens;
- var link = document.createElement("a");
- link.download = "exportExcel";
- link.href = this.getWebURL() + "ExportToExcel?" + encodeURI(uri);
- link.click();
- },
- _queryHisData: function (from, to) {
- var beg = from.val();
- beg = this.parseDate(beg);
- if (beg == null) {
- from.focus();
- var d = dialog({
- content: "查询起始时间设置有误,请重新设置。",
- quickClose: true
- });
- window.setTimeout(function () {
- d.close().remove();
- d = null;
- from.focus();
- }, 2000);
- d.show(from[0]);
- return;
- }
- beg = this.DateToFileTime(beg);
- var end = to.val();
- end = this.parseDate(end);
- if (end == null) {
- to.focus();
- var d = dialog({
- content: "查询截止时间设置有误,请重新设置。",
- quickClose: true
- });
- window.setTimeout(function () {
- d.close().remove();
- d = null;
- to.focus();
- }, 2000);
- d.show(to[0]);
- return;
- }
- end = this.DateToFileTime(end);
- if (end <= beg) {
- to.focus();
- var d = dialog({
- content: "查询截止时间不能小于等于查询起始时间,请重新设置。",
- quickClose: true
- });
- window.setTimeout(function () {
- d.close().remove();
- d = null;
- to.focus();
- }, 2000);
- d.show(to[0]);
- return;
- }
- this.setBegTimeAndSpan(beg, (end - beg) / PERSEC);
- },
- getPenByRowId: function (rowId) {
- if (this.trendPens) {
- for (var k in this.trendPens) {
- var pen = this.trendPens[k];
- if (pen.rowId == rowId)
- return pen;
- }
- }
- return null;
- },
- _bindPenList: function (pen) {
- if (this.listGrid) {
- var rowId = this.listRowSeed++;
- this.listGrid.addRow(rowId, "");
- pen._setListRowId(rowId);
- }
- },
- _synList: function () {
- this.listGrid.clearAll();
- this.listRowSeed = 1;
- if (this.trendPens && this.trendPens.length) {
- for (i in this.trendPens)
- this._bindPenList(this.trendPens[i]);
- }
- },
- _updateList: function (rowId, colName, val) {
- if (this.listGrid && rowId && colName) {
- var num = this.listGrid.getColumnsNum();
- for (var i = 0; i < num; i++) {
- if (this.listGrid.getColumnLabel(i) == colName) {
- var cell = this.listGrid.cells(rowId, i);
- if (cell)
- cell.setValue(val);
- break;
- }
- }
- }
- },
- getWebURL: function () {
- return GoldenRtWeb.getWebURL();
- },
- _reDrawAll: function () {
- var node = this.canvas.get(0);
- this.ctx.clearRect(0, 0, node.width, node.height);
- this.buttonsDrawed = false;
- this.updateDataArea();
- this.UpdatePan(true);
- this._drawIndicator();
- this._drawButtons();
- },
- _onResize: function () {
- if (this.artTooltip)
- this.artTooltip.close().reset().remove();
- if (this.element.width() != this.chartWidth ||
- this.element.height() != this.chartHeight)
- this._bulidCanvas();
- },
- _onListSorted: function () {
- var ids = this.listGrid.getAllRowIds();
- var arry = ids.split(",");
- if (arry && arry.length) {
- var newPens = [];
- for (var i = 0; i < arry.length; i++) {
- var pen = this.getPenByRowId(arry[i]);
- if (pen)
- newPens.push(pen);
- }
- if (newPens.length) {
- this.trendPens = newPens;
- this.updateDataArea();
- this.UpdatePan();
- }
- }
- },
- _drawIndicator: function () {
- var gw = this.getGridWidth();
- var gh = this.getGridHeight();
- var gt = this.toolBarCanShow() ? TOOLBARHEIGHT : 0;
- var rtchart = this;
- var hw;
- if (this.options.showAxis)
- hw = this.chartWidth;
- else
- hw = gw + 12;
- if (!this.hIndicator) {
- this.hIndicator = $(document.createElement('canvas'));
- this.element.append(this.hIndicator);
- bNew = true;
- }
- this.hIndicator.css("position", "absolute")
- .css("left", 0)
- .css("top", 25)
- .css("width", hw)
- .css("height", INDICTWIDTH)
- .css("cursor", "n-resize");
- this.hIndicator.attr("width", (hw) * this.options.resolution);
- this.hIndicator.attr("height", INDICTWIDTH * this.options.resolution);
- var node = this.hIndicator.get(0);
- if (window.G_vmlCanvasManager)
- window.G_vmlCanvasManager.initElement(node);
- var hctx = node.getContext('2d');
- if (!window.G_vmlCanvasManager)
- hctx.scale(this.options.resolution, this.options.resolution);
- hctx.save();
- hctx.translate(0.5, 0.5);
- hctx.clearRect(0, 0, (hw), INDICTWIDTH);
- hctx.lineWidth = 3.0;
- hctx.strokeStyle = this.options.indicatorColor;
- hctx.beginPath();
- hctx.moveTo(1, 5);
- hctx.lineTo(hw, 5);
- hctx.stroke();
- hctx.restore();
- if (bNew)
- this.hIndicator.draggable({
- containment: [0, this.canvas.offset().top - 5, hw, this.canvas.offset().top + gh - 5],
- scroll: false,
- axis: "y",
- drag: function (event, ui) {
- rtchart._onhIndicatorMove(event);
- },
- stop: function (event, ui) {
- rtchart._onhIndicatorMoveEnd(event);
- }
- });
- else
- this.hIndicator.draggable('option', 'containment', [0, this.canvas.offset().top - 5, gw, this.canvas.offset().top + gh - 5]);
- this.hIndicator.hover(
- function (e) {
- rtchart.hIndicator.focus();
- rtchart._onhIndicatorHover(e);
- });
- if (this.vSplite) {
- if (this.vSplite.data('drag') === true)
- this.vSplite.draggable("destroy");
- this.vSplite.unbind();
- this.vSplite.remove();
- this.vSplite = null;
- }
- if (this.hSplite) {
- if (this.hSplite.data('drag') === true)
- this.hSplite.draggable("destroy");
- this.hSplite.unbind();
- this.hSplite.remove();
- this.hSplite = null;
- }
- bNew = false;
- if (!this.vIndicator) {
- this.vIndicator = $(document.createElement('canvas'));
- this.element.append(this.vIndicator);
- bNew = true;
- }
- this.vIndicator.css("position", "absolute")
- .css("left", 20)
- .css("top", gt)
- .css("width", INDICTWIDTH)
- .css("height", (gh + 16))
- .css("pointer-events", 'none');
-
- this.vIndicator.attr("width", INDICTWIDTH * this.options.resolution);
- this.vIndicator.attr("height", (gh + 16) * this.options.resolution);
- node = this.vIndicator.get(0);
- if (window.G_vmlCanvasManager)
- window.G_vmlCanvasManager.initElement(node);
- var vctx = node.getContext('2d');
- if (!window.G_vmlCanvasManager)
- vctx.scale(this.options.resolution, this.options.resolution);
- vctx.save();
- vctx.translate(0.5, 0.5);
- vctx.clearRect(0, 0, INDICTWIDTH, node.height);
- vctx.lineWidth = 1.0;
- vctx.setLineDash([3, 6]);
- vctx.strokeStyle = this.options.indicatorColor;
- vctx.beginPath();
- vctx.moveTo(5, 1);
- vctx.lineTo(5, gh + 10);
- vctx.stroke();
- vctx.restore();
- if (bNew)
- this.vIndicator.draggable({
- containment: [this.canvas.offset().left - 5, 0, this.canvas.offset().left + gw - 5, gh],
- axis: "x",
- scroll: false,
- drag: function (event, ui) {
- rtchart._onvIndicatorMove(event);
- },
- stop: function (event, ui) {
- rtchart._onvIndicatorMoveEnd(event);
- }
- });
- else
- this.vIndicator.draggable('option', 'containment', [this.canvas.offset().left - 5, 0, this.canvas.offset().left + gw - 5, gh]);
- this.vIndicator.hover(
- function (e) {
- rtchart.vIndicator.focus();
- rtchart._onvIndicatorHover(e);
- });
- if (this.options.panShow) {
- this.vSplite = $(document.createElement('canvas'));
- this.hIndicator.before(this.vSplite);
- this.vSplite.css("position", "absolute")
- .css("left", gw)
- .css("top", gt)
- .css("width", PANMAG * 2)
- .css("height", (gh + 1))
- .css("cursor", "e-resize")
- .addClass('unselectable');
- this.vSplite.attr("width", PANMAG * 2 * this.options.resolution);
- this.vSplite.attr("height", (gh + 1) * this.options.resolution);
- node = this.vSplite.get(0);
- if (window.G_vmlCanvasManager)
- window.G_vmlCanvasManager.initElement(node);
- var spctx = node.getContext('2d');
- if (!window.G_vmlCanvasManager)
- spctx.scale(this.options.resolution, this.options.resolution);
- spctx.clearRect(0, 0, node.width, node.height);
- this.vSplite.draggable({
- containment: [this.canvas.offset().left + 200, 0, this.chartWidth - 5, gh],
- axis: "x",
- scroll: false,
- start: function (event, ui) {
- var ctx = this.getContext('2d');
- ctx.clearRect(0, 0, this.width, this.height);
- var gradient = ctx.createLinearGradient(0, 0, this.width, 0);
- gradient.addColorStop("0", "rgba(120,120,120,0.5)");
- gradient.addColorStop(".50", "rgba(180,180,180,0.7)");
- gradient.addColorStop("1.0", "rgba(120,120,120,0.5)");
- ctx.fillStyle = gradient;
- ctx.fillRect(0, 0, this.width, this.height);
- ctx.beginPath();
- ctx.lineWidth = "1";
- ctx.strokeStyle = "rgb(30,30,30)";
- ctx.rect(.5, .5, this.width - 1, this.height - 1);
- ctx.stroke();
- },
- stop: function (event, ui) {
- var ctx = this.getContext('2d');
- ctx.clearRect(0, 0, this.width, this.height);
- var l = $(this).position().left;
- rtchart.setPanWidth(rtchart.chartWidth - l);
- }
- });
- this.vSplite.data('drag', true);
- this.vSplite.hover(
- function (e) {
- var o = $(this).offset();
- var x = e.pageX - o.left;
- var y = e.pageY - o.top;
- if (y > this.height / 2 - 18 && y < this.height / 2 - 18 + 35) {
- $(this).attr('title', '收回数据板');
- $(this).css('cursor', 'pointer');
- } else {
- $(this).attr('title', null);
- $(this).css('cursor', "e-resize");
- }
- },
- function (e) {
- $(this).css("cursor", "e-resize");
- });
- this.vSplite.click(function (e) {
- var o = $(this).offset();
- var x = e.pageX - o.left;
- var y = e.pageY - o.top;
- if (y > this.height / 2 - 18 && y < this.height / 2 - 18 + 35)
- rtchart.setPanShow(false);
- });
- } else if (this.panCanShow()) {
- this.vSplite = $(document.createElement('canvas'));
- this.hIndicator.before(this.vSplite);
- this.vSplite.css("position", "absolute")
- .css("left", this.chartWidth - 5)
- .css("top", gh / 2 + 15)
- .css("width", 5)
- .css("height", 35)
- .css("cursor", "pointer")
- .attr("title", "展开数据板");
- this.vSplite.attr("width", 5 * this.options.resolution);
- this.vSplite.attr("height", 35 * this.options.resolution);
- node = this.vSplite.get(0);
- if (window.G_vmlCanvasManager)
- window.G_vmlCanvasManager.initElement(node);
- var spctx = node.getContext('2d');
- if (!window.G_vmlCanvasManager)
- spctx.scale(this.options.resolution, this.options.resolution);
- spctx.clearRect(0, 0, node.width, node.height);
- this.vSplite.click(function (e) {
- rtchart.setPanShow(true);
- });
- }
- if (this.listCanshow()) {
- this.hSplite = $(document.createElement('canvas'));
- this.element.append(this.hSplite);
- var t;
- if (this.listCanshow() && this.options.listExpand)
- t = this.chartHeight - this.options.listHeight;
- else
- t = this.chartHeight - 11;
- this.hSplite.css("position", "absolute")
- .css("left", 0)
- .css("top", t)
- .css("right", 0)
- .css("height", 10)
- .css("cursor", "n-resize")
- .css("z-index", 1000)
- .addClass('unselectable');
- this.hSplite.attr("width", this.chartWidth * this.options.resolution);
- this.hSplite.attr("height", 10 * this.options.resolution);
- node = this.hSplite.get(0);
- if (window.G_vmlCanvasManager)
- window.G_vmlCanvasManager.initElement(node);
- var hpctx = node.getContext('2d');
- if (!window.G_vmlCanvasManager)
- hpctx.scale(this.options.resolution, this.options.resolution);
- hpctx.clearRect(0, 0, node.width, node.height);
- this.hSplite.draggable({
- containment: [0, this.element.offset().top + 210, 0, this.element.offset().top + this.element.height() - 30],
- axis: "y",
- scroll: false,
- start: function (event, ui) {
- var ctx = this.getContext('2d');
- ctx.clearRect(0, 0, this.width, this.height);
- var gradient = ctx.createLinearGradient(0, 0, 0, this.height);
- gradient.addColorStop("0", "rgba(120,120,120,0.5)");
- gradient.addColorStop(".50", "rgba(200,200,200,0.7)");
- gradient.addColorStop("1.0", "rgba(120,120,120,0.5)");
- ctx.fillStyle = gradient;
- ctx.fillRect(0, 0, this.width - 3, this.height);
- ctx.beginPath();
- ctx.lineWidth = "1";
- ctx.strokeStyle = "rgb(30,30,30)";
- ctx.rect(.5, .5, this.width - 3, this.height - 1);
- ctx.stroke();
- },
- stop: function (event, ui) {
- var ctx = this.getContext('2d');
- ctx.clearRect(0, 0, this.width, this.height);
- var t = rtchart.chartHeight - $(this).offset().top + rtchart.element.offset().top;
- rtchart.setListHeight(t);
- }
- });
- this.hSplite.data('drag', true);
- this.hSplite.hover(
- function (e) {
- var o = $(this).offset();
- var x = e.pageX - o.left;
- var y = e.pageY - o.top;
- if (x > this.width / 2 - 18 && x < this.width / 2 + 18) {
- if (rtchart.options.listExpand)
- $(this).attr('title', '收回数据列表');
- else
- $(this).attr('title', '展开数据列表');
- $(this).css('cursor', 'pointer');
- } else {
- $(this).attr('title', null);
- $(this).css('cursor', "n-resize");
- }
- },
- function (e) {
- $(this).css("cursor", "n-resize");
- }
- );
- this.hSplite.click(function (e) {
- var o = $(this).offset();
- var x = e.pageX - o.left;
- var y = e.pageY - o.top;
- if (x > this.width / 2 - 18 && x < this.width / 2 + 18) {
- if (rtchart.options.listExpand)
- rtchart.setListExpand(false);
- else
- rtchart.setListExpand(true);
- }
- });
- }
- },
- _drawButtons: function () {
- if (this.buttonsDrawed === true || !this.options.buttonImage)
- return;
- if (this.options.buttonImage.get(0).complete === true) {
- var img = this.options.buttonImage.get(0);
- var gw = this.getGridWidth();
- var gh = this.getGridHeight();
- this.buttonsDrawed = true;
- var canvas = this.vIndicator.get(0);
- var ctx = canvas.getContext("2d");
- ctx.drawImage(img, 0, 0, 11, 11, 0, gh - 3, 11, 11);
- canvas = this.hIndicator.get(0);
- ctx = canvas.getContext("2d");
- ctx.drawImage(img, 11, 0, 11, 11, gw - 3, 0, 11, 11);
- if (this.vSplite) {
- canvas = this.vSplite.get(0);
- ctx = canvas.getContext("2d");
- if (this.options.panShow)
- ctx.drawImage(img, 0, 11, 5, 35, 0, canvas.height / 2 - 18, 5, 35);
- else
- ctx.drawImage(img, 5, 11, 5, 35, 0, 0, 5, 35);
- }
- if (this.hSplite) {
- canvas = this.hSplite.get(0);
- ctx = canvas.getContext("2d");
- if (this.options.listExpand)
- ctx.drawImage(img, 10, 11, 35, 5, canvas.width / 2 - 18, 0, 35, 5);
- else
- ctx.drawImage(img, 10, 15, 35, 5, canvas.width / 2 - 18, 0, 35, 5);
- }
- } else {
- var me = this;
- this.options.buttonImage.load(function () {
- if (me) {
- me._drawButtons();
- me.UpdateDataPan(true);
- me = null;
- }
- });
- }
- },
- updateDataArea: function () {
- if (this.updateDataAreaTimer == null) {
- var self = this;
- this.updateDataAreaTimer = window.setTimeout(function () {
- window.clearTimeout(self.updateDataAreaTimer)
- self.updateDataAreaTimer = null;
- self._drawDataArea();
- self = null;
- }, 20);
- }
- },
- _drawDataArea: function () {
- if (this.thumbsCanshow())
- this._drawThumbs();
- this._drawTimeLabel();
- this._drawTrendLines();
- },
- _drawTrendLines: function () {
- var gw = this.getGridWidth();
- var gh = this.getGridHeight();
- var ctx = this.ctx;
- ctx.save();
- ctx.clearRect(0, 0, gw, gh);
- ctx.translate(0.5, 0.5);
- var begTime = this.getDrawBegTime();
- var endTime = this.getDrawEndTime();
- var timeScale = gw / (endTime - begTime);
- if (this.options.showGrid) {
- var y = gh / 20.0;
- ctx.beginPath();
- ctx.lineWidth = 1;
- ctx.strokeStyle = this.options.gridColor;
- for (var i = 0; i < 19; i++) {
- var iy = Math.floor(y);
- ctx.moveTo(0, iy);
- ctx.lineTo(gw, iy);
- y += gh / 20.0;
- }
- var t = this.ftTimeLabelBeg;
- var x = (t - begTime) * timeScale;
- for (var i = 0; i < 4; i++) {
- var ix = Math.floor(x);
- ctx.moveTo(ix, 0);
- ctx.lineTo(ix, gh);
- t += (endTime - begTime) / 4;
- x = (t - begTime) * timeScale;
- }
- ctx.stroke();
- }
- if (this.trendPens && this.trendPens.length) {
- ctx.rect(1, 1, gw - 1, gh - 1);
- ctx.clip();
- ctx.lineWidth = 1;
- for (k in this.trendPens) {
- var pen = this.trendPens[k];
- if (pen != this.activePen)
- pen.drawTrendLine(ctx, begTime, endTime, gw, gh, timeScale);
- }
- if (this.activePen) {
- var shadowSize = this.options.activeShadowSize;
- var lineWidth = 2;
- ctx.lineWidth = shadowSize / 2;
- var offset = lineWidth / 2 + ctx.lineWidth / 2;
- ctx.strokeStyle = "rgba(0,0,0,0.4)";
- this.activePen.drawTrendLine(ctx, begTime, endTime, gw, gh, timeScale, offset + shadowSize / 2);
- ctx.strokeStyle = "rgba(0,0,0,0.5)";
- this.activePen.drawTrendLine(ctx, begTime, endTime, gw, gh, timeScale, offset);
- ctx.lineWidth = lineWidth;
- this.activePen.drawTrendLine(ctx, begTime, endTime, gw, gh, timeScale);
- }
- }
- if (this.zoomRect) {
- ctx.lineWidth = 1;
- ctx.strokeStyle = "rgb(180,180,180)";
- ctx.fillStyle = "rgba(10,10,10,0.2)";
- ctx.beginPath();
- ctx.rect(this.zoomRect.x, this.zoomRect.y, this.zoomRect.w, this.zoomRect.h);
- ctx.fill();
- ctx.stroke();
- }
- ctx.restore();
- if (this.options.borderColor != null) {
- ctx.lineWidth = 1;
- ctx.beginPath();
- ctx.strokeStyle = this.options.borderColor;
- ctx.rect(0.5, 0.5, gw, gh);
- ctx.stroke();
- }
- },
- _onThumbsChanged: function () {
- this.thumbBegDiv.draggable("option", "containment", [this.canvas.offset().left - 3, 0, this.canvas.offset().left + this.thumbEndDiv.position().left - 20, 0]);
- this.thumbEndDiv.draggable("option", "containment", [this.canvas.offset().left + this.thumbBegDiv.position().left + 20, 0, this.canvas.offset().left + this.chartWidth - 3, 0]);
- this._drawThumbs();
- this._drawTimeLabel();
- this._drawTrendLines();
- },
- _resetTumbs: function () {
- if (this.thumbBegDiv) {
- this.thumbBegDiv
- .css("left", -3)
- .draggable("option", "containment", [this.canvas.offset().left - 3, 0, this.canvas.offset().left + this.chartWidth - 18, 0]);
- }
- if (this.thumbEndDiv) {
- this.thumbEndDiv
- .css("left", this.chartWidth - 3)
- .draggable("option", "containment", [this.canvas.offset().left + 18, 0, this.canvas.offset().left + this.chartWidth - 18, 0]);
- }
- },
- _drawThumbs: function () {
- var thw = this.chartWidth;
- var gh = this.getGridHeight();
- var gt = gh + TIMELABELHEIGHT;
- var h = SHOWTHUMBSHEIGHT - 3;
- var ctx = this.ctx;
- ctx.save();
- ctx.clearRect(0, gt, thw, h);
- ctx.translate(0.5, 0.5);
- if (this.trendPens && this.trendPens.length) {
- var begTime = this.getBegTime();
- var endTime = this.getEndTime();
- var timeScale = thw / this.options.spanSec / PERSEC;
- ctx.rect(1, gt, thw - 1, h - 1);
- ctx.clip();
- ctx.lineWidth = 1;
- for (k in this.trendPens) {
- var pen = this.trendPens[k];
- pen.drawThumbsTrendLine(ctx, begTime, endTime, gh, gt, h, timeScale);
- }
- }
- ctx.fillStyle = "rgba(100,100,100,0.7)";
- var ix = this.thumbBegDiv.position().left + 6;
- ctx.fillRect(0, gt, ix, h);
- ix = this.thumbEndDiv.position().left;
- ctx.fillRect(ix, gt, thw - ix, h);
- ctx.restore();
- if (this.options.borderColor != null) {
- ctx.lineWidth = 1;
- ctx.beginPath();
- ctx.strokeStyle = this.options.borderColor;
- ctx.rect(0.5, 0.5 + gt, thw - 1, h);
- ctx.stroke();
- }
- },
- _drawTimeLabel: function () {
- if (!this.ctx || !this.slidCanShow())
- return;
- var begTime = this.getDrawBegTime();
- var endTime = this.getDrawEndTime();
- var timeSpan = (endTime - begTime);
- var span = timeSpan / 4;
- var changed = false;
- if (this.ftTimeLabelBeg == null ||
- Math.abs(this.ftTimeLabelBeg - this.ftBeginTime) > this.options.spanSec * PERSEC) {
- if (span >= PERDAY) {
- var ft = begTime + PERDAY;
- ft = this.FileTimeToDate(ft);
- ft.setHours(0);
- ft.setMinutes(0);
- ft.setSeconds(0);
- ft.setMilliseconds(0);
- this.ftTimeLabelBeg = this.DateToFileTime(ft);
- } else if (span > PERHOUR) {
- var ft = begTime + PERHOUR;
- ft = this.FileTimeToDate(ft);
- ft.setMinutes(0);
- ft.setSeconds(0);
- ft.setMilliseconds(0);
- this.ftTimeLabelBeg = this.DateToFileTime(ft);
- } else if (span > PERMINUTE) {
- var ft = begTime + PERMINUTE;
- ft = this.FileTimeToDate(ft);
- ft.setSeconds(0);
- ft.setMilliseconds(0);
- this.ftTimeLabelBeg = this.DateToFileTime(ft);
- } else if (span > PERSEC) {
- var ft = begTime + PERSEC;
- ft = this.FileTimeToDate(ft);
- ft.setMilliseconds(0);
- this.ftTimeLabelBeg = this.DateToFileTime(ft);
- } else
- this.ftTimeLabelBeg = begTime + span;
- changed = true;
- }
- while (begTime < this.ftTimeLabelBeg + span) {
- this.ftTimeLabelBeg -= span;
- changed = true;
- }
- while (begTime > this.ftTimeLabelBeg) {
- this.ftTimeLabelBeg += span;
- changed = true;
- }
- if (changed)
- this._updatevIndicatorTooltip();
- var ctx = this.ctx;
- ctx.save();
- ctx.translate(0.5, 0.5);
- ctx.fillStyle = this.options.timeLabelColor;
- ctx.textBaseline = "top";
- ctx.textAlign = "left";
- ctx.font = "12px sans-serif";
- var gw = this.getGridWidth();
- var gh = this.getGridHeight();
- ctx.clearRect(0, gh + 0.5, gw, 13);
- var len = 60;
- var str;
- if (timeSpan / PERSEC > 10)
- str = this.FileTimeToTimeString(begTime, false);
- else {
- str = this.FileTimeToTimeString(begTime, true);
- len = 80;
- }
- ctx.fillText(str, 0, gh);
- str = this.FileTimeToDateString(begTime);
- ctx.clearRect(0, gh + 14, 70, 16);
- ctx.fillText(str, 0, gh + 16);
- var time = this.ftTimeLabelBeg;
- var x = (time - begTime) * gw / timeSpan;
- var px = 0;
- for (var i = 1; i < 5; i++) {
- var ix = Math.floor(x);
- if ((ix > px + len) && (ix + len < gw - len)) {
- if (this.options.spanSec > 10)
- str = this.FileTimeToTimeString(time, false);
- else
- str = this.FileTimeToTimeString(time, true);
- ctx.fillText(str, ix, gh);
- px = x;
- }
- time += timeSpan / 4;
- x += gw / 4;
- }
- if (timeSpan / PERSEC > 10)
- str = this.FileTimeToTimeString(endTime, false);
- else
- str = this.FileTimeToTimeString(endTime, true);
- ctx.textAlign = "right";
- ctx.fillText(str, gw, gh);
- str = this.FileTimeToDateString(endTime);
- ctx.clearRect(gw - 70, gh + 14, 72, 16);
- ctx.fillText(str, gw, gh + 16);
- ctx.restore();
- },
- UpdatePan: function (bReDraw) {
- if (bReDraw)
- this.panReDraw = bReDraw;
- if (this.updatePanTimer == null) {
- var self = this;
- this.updatePanTimer = window.setTimeout(function () {
- window.clearTimeout(self.updatePanTimer)
- self.updatePanTimer = null;
- self._drawPan();
- self = null;
- }, 100);
- }
- },
- UpdateDataPan: function (bReDraw) {
- if (this.options.showAxis || !this.options.panShow)
- return;
- this.UpdatePan(bReDraw);
- },
- UpdateAxisPan: function (bReDraw) {
- if (!this.options.showAxis || !this.options.panShow)
- return;
- this.UpdatePan(bReDraw);
- },
- _drawPan: function (bReDraw) {
- this.options
- if (this.options.panShow) {
- var l = this.getGridWidth() + PANMAG;
- var w = this.options.panWidth - PANMAG;
- if (this.options.showAxis) {
- var h = this.getGridHeight() + TIMELABELHEIGHT;
- var ctx = this.ctx;
- ctx.save();
- ctx.font = "12px sans-serif";
- ctx.textBaseline = "top";
- ctx.lineWidth = 1.0;
- ctx.lineJoin = 'miter';
- ctx.clearRect(l, 0, w + 1, h);
- ctx.rect(l, 0, w + 1, h - 2);
- ctx.clip();
- ctx.translate(0.5, 0.5);
- if (this.trendPens) {
- for (var i = 0; i < this.trendPens.length; i++)
- this.trendPens[i].resetAxisDrawed();
- var pl = this.getGridWidth() + PANMAG;
- var ph = this.getGridHeight();
- var pw = this.options.panWidth - PANMAG;
- var begX = pl + 1;
- for (var i = 0; i < this.trendPens.length; i++) {
- ctx.strokeStyle = this.options.borderColor;
- ctx.fillStyle = this.options.timeLabelColor;
- var drawPen = this.trendPens[i];
- var x = drawPen.drawAxis(begX, ph, ctx);
- if (isNaN(x))
- x = 0;
- begX += x + 2;
- if (begX >= this.chartWidth)
- break;
- }
- }
- ctx.restore();
- } else {
- var h = this.getGridHeight();
- if (this.yScroll == null || this.yScroll < 0)
- this.yScroll = 0;
- else if (!this.trendPens || h > PANHEAD + this._getPanTotalHeight())
- this.yScroll = 0;
- else if (this.yScroll + (h - PANHEAD) > this._getPanTotalHeight())
- this.yScroll = this._getPanTotalHeight() - h + PANHEAD;
- var ctx = this.ctx;
- ctx.save();
- ctx.font = "14px sans-serif";
- ctx.textBaseline = "top";
- bReDraw = this.panReDraw || bReDraw;
- this.panReDraw = false;
- if (bReDraw)
- ctx.clearRect(l + 0.5, 0.5, w, h + TIMELABELHEIGHT);
- ctx.rect(l, 0, w + 1, h - 2);
- ctx.clip();
- if (this.trendPens) {
- var t = PANHEAD - this.yScroll;
- var pl = this.getGridWidth() + PANMAG;
- var ph = this.getGridHeight();
- var pw = this.options.panWidth - PANMAG;
- for (var i = 0; i < this.trendPens.length; i++) {
- ctx.save();
- ctx.translate(pl, t);
- if (this.newPenPos == i) {
- ctx.lineWidth = 4.0;
- ctx.lineJoin = 'round';
- ctx.strokeStyle = "rgb(0,210,210)";
- ctx.beginPath();
- ctx.moveTo(0, 0);
- ctx.lineTo(pw, 0);
- ctx.stroke();
- }
- var drawPen = this.trendPens[i];
- drawPen.drawPan(bReDraw, ctx, t, pw);
- ctx.restore();
- t += drawPen.getPanHeight();
- if (t > ph)
- break;
- }
- }
- if (this._showAxisToggle === true) {
- this._showAxisToggle = false;
- ctx.clearRect(l + 0.5, h, w, TIMELABELHEIGHT);
- }
- ctx.restore();
- ctx.beginPath();
- ctx.lineWidth = 1;
- ctx.strokeStyle = this.options.borderColor;
- ctx.rect(l + 0.5, 0.5, w, h);
- ctx.stroke();
- }
- }
- },
- _setOption: function (key, value) {
- switch (key) {
- case "rtRefresh":
- this.setRtrefresh(value);
- break;
- }
- this._super(key, value);
- },
- toggleRtRefresh: function () {
- this.setRtrefresh(!this.options.rtRefresh);
- },
- setRtrefresh: function (brtRefresh) {
- if (this.options.rtRefresh == brtRefresh)
- return;
- this.options.rtRefresh = brtRefresh;
- if (this.options.rtRefresh) {
- this.toolBar.setItemImage("reRefresh", "refresh.png");
- this.toolBar.setItemState("reRefresh", true);
- this.toolBar.setItemToolTip("reRefresh", "当前为实时刷新模式,单击转变为静态查询模式");
- } else {
- this.toolBar.setItemImage("reRefresh", "query.png");
- this.toolBar.setItemState("reRefresh", false);
- this.toolBar.setItemToolTip("reRefresh", "当前为静态查询模式,单击转变为实时刷新模式");
- }
- if (this.options.rtRefresh) {
- if (Math.abs(this.DateToFileTime(new Date()) - this.getEndTime()) > this.options.spanSec * PERSEC) {
- var begTime = new Date();
- begTime.setMilliseconds(0);
- begTime = this.DateToFileTime(begTime);
- begTime += PERSEC;
- begTime -= this.options.spanSec * PERSEC;
- this.ftTimeLabelBeg = null;
- if (this.ftBeginTime == begTime)
- this.ftBeginTime = 0;
- this.setBeginTime(begTime);
- } else if (this.webLinks) {
- for (var i in this.webLinks)
- this.webLinks[i].requestHisData();
- }
- }
- },
- toggleShowAxis: function () {
- this.setShowAxis(!this.options.showAxis);
- },
- setShowAxis: function (bShowAxis) {
- if (this.options.showAxis == bShowAxis)
- return;
- this.options.showAxis = bShowAxis;
- if (this.options.showAxis) {
- this.toolBar.setItemImage("showAxis", "axis.png");
- this.toolBar.setItemState("showAxis", true);
- this.toolBar.setItemToolTip("showAxis", "当前为值轴显示模式,单击转变为数据板显示模式");
- } else {
- this.toolBar.setItemImage("showAxis", "datapan.png");
- this.toolBar.setItemState("showAxis", false);
- this.toolBar.setItemToolTip("showAxis", "当前为数据板显示模式,单击转变为值轴显示模式");
- }
- this._showAxisToggle = true;
- var gw = this.getGridWidth();
- var hw;
- if (this.options.showAxis)
- hw = this.chartWidth;
- else
- hw = gw + 12;
- this.hIndicator.css("width", hw);
- this.hIndicator.attr("width", (hw) * this.options.resolution);
- var node = this.hIndicator.get(0);
- if (window.G_vmlCanvasManager)
- window.G_vmlCanvasManager.initElement(node);
- var hctx = node.getContext('2d');
- if (!window.G_vmlCanvasManager)
- hctx.scale(this.options.resolution, this.options.resolution);
- hctx.save();
- hctx.translate(0.5, 0.5);
- hctx.clearRect(0, 0, (hw), INDICTWIDTH);
- hctx.lineWidth = 3.0;
- hctx.strokeStyle = this.options.indicatorColor;
- hctx.beginPath();
- hctx.moveTo(1, 5);
- hctx.lineTo(hw, 5);
- hctx.stroke();
- if (this.options.buttonImage && this.options.buttonImage.get(0).complete === true) {
- var img = this.options.buttonImage.get(0);
- hctx.drawImage(img, 11, 0, 11, 11, gw - 3, -0.5, 11, 11);
- }
- hctx.restore();
- this.UpdatePan(true);
- },
- toggleRangeMode: function () {
- this.setRangeMode(!this.options.freeRange);
- },
- setRangeMode: function (rangeMode) {
- if (this.options.freeRange === rangeMode) return;
- this.options.freeRange = rangeMode;
- if (this.options.freeRange) {
- this.toolBar.setItemImage("toggleRange", "view_type_free.png");
- this.toolBar.setItemState("toggleRange", true);
- this.toolBar.setItemToolTip("toggleRange", "当前量程为自由量程,点击切换到固定量程");
- } else {
- this.toolBar.setItemImage("toggleRange", "view_type.png");
- this.toolBar.setItemState("toggleRange", false);
- this.toolBar.setItemToolTip("toggleRange", "当前量程为固定量程,点击切换到自由量程");
- }
-
- var pen
- if (!rangeMode) {
- for (var i = 0, len = this.trendPens.length; i < len; i++) {
- pen = this.trendPens[i];
- pen.setRange(0, 1000, null);
- }
- }
- },
- setCursor: function (cursor) {
- this.canvas.css("cursor", cursor);
- },
- showTooltip: function (opt, pen) {
- if (this.artTooltip)
- this.artTooltip.close().remove();
- if (this.tipShowPen)
- this.tipShowPen.onTooltipHided();
- if (this.tooltipTimer) {
- window.clearTimeout(this.tooltipTimer);
- this.tooltipTimer = null;
- }
- var rtChart = this;
- this.tooltipTimer = window.setTimeout(
- function () {
- var o = rtChart.getOffset();
- if (opt.x == null || opt.x < 0)
- opt.x = 0;
- else if (opt.x + rtChart.positionDiv.width() + 2 > o.left + rtChart.chartWidth)
- opt.x = o.left + rtChart.chartWidth - rtChart.positionDiv.width() - 2;
- if (opt.y == null || opt.y < 0)
- opt.y = 0;
- else if (opt.y + rtChart.positionDiv.height() + 2 > o.top + rtChart.chartHeight)
- opt.y = o.top + rtChart.chartHeight - rtChart.positionDiv.height() - 2;
- rtChart.positionDiv.offset({
- left: opt.x,
- top: opt.y
- });
- $.extend(opt, {
- padding: 10,
- onremove: function () {
- rtChart._onTootipHided();
- rtChart = null;
- }
- });
- rtChart.artTooltip = dialog(opt);
- rtChart.artTooltip.show(rtChart.positionDiv.get(0));
- rtChart.btipShow = true;
- rtChart.tipShowPen = pen;
- if (rtChart.tipShowPen)
- rtChart.tipShowPen.onTooltipShowed();
- }, this.options.tooltipDelay || 200);
- },
- UpdateTooltip: function (content) {
- if (this.artTooltip)
- this.artTooltip.content(content)
- },
- _onTootipHided: function () {
- this.btipShow = false;
- if (this.tipShowPen) {
- this.tipShowPen.onTooltipHided();
- this.tipShowPen = null;
- }
- this.tootipAt = null;
- if (this.artTooltip)
- delete this.artTooltip;
- this.positionDiv.offset({
- left: this.canvas.offset().left,
- top: this.canvas.offset().top
- });
- },
- getTooltipPen: function () {
- return this.tipShowPen;
- },
- _onhIndicatorHover: function (e) {
- if (this.loginning === true)
- return;
- if (this.artTooltip && this.tootipAt == "HI" && this.artTooltip.__popup)
- return;
- if (this.artTooltip)
- this.artTooltip.close().remove();
- if (this.tooltipTimer) {
- window.clearTimeout(this.tooltipTimer);
- this.tooltipTimer = null;
- }
- var rtChart = this;
- this.tooltipTimer = window.setTimeout(
- function () {
- if (rtChart.tooltipTimer) {
- window.clearTimeout(rtChart.tooltipTimer);
- rtChart.tooltipTimer = null;
- }
- var gh = rtChart.getGridHeight();
- var o = rtChart.canvas.offset();
- var y = e.pageY - o.top;
- var ta = (y > gh / 2) ? 'bottom' : 'top';
- var opt = {
- title: "值线",
- content: rtChart._gethIndicatorTooltipContent(),
- align: ta,
- padding: 10,
- width: 300,
- skin: 'tooltipTans'
- };
- rtChart.artTooltip = dialog(opt);
- rtChart.artTooltip.show(rtChart.hIndicator.get(0));
- rtChart.btipShow = true;
- rtChart.tootipAt = "HI";
- rtChart = null;
- }, this.options.tooltipDelay || 1000);
- },
- _onhIndicatorMove: function (event) {
- if (this.artTooltip && this.tootipAt == "HI" && this.artTooltip.__popup)
- this.artTooltip.content(this._gethIndicatorTooltipContent());
- },
- _onhIndicatorMoveEnd: function (event) {
- if (this.artTooltip && this.tootipAt == "HI" && this.artTooltip.__popup)
- this.artTooltip.content(this._gethIndicatorTooltipContent());
- },
- _gethIndicatorTooltipContent: function () {
- var gh = this.getGridHeight();
- var iy = this.hIndicator.offset().top - this.canvas.offset().top + 5;
- var content = null;
- if (this.trendPens) {
- var arr = [];
- for (var i in this.trendPens)
- arr.push(this.trendPens[i].getValueLine(iy));
- if (arr.length)
- content = arr.join("");
- }
- return content;
- },
- _onvIndicatorHover: function (e) {
- if (this.loginning === true)
- return;
- if (this.artTooltip && this.tootipAt == "VI" && this.artTooltip.__popup)
- return;
- if (this.tooltipTimer) {
- window.clearTimeout(this.tooltipTimer);
- this.tooltipTimer = null;
- }
- var rtChart = this;
- var gw = rtChart.getGridWidth();
- var o = rtChart.canvas.offset();
- var x = e.pageX - o.left;
- var ta = (x > gw / 2) ? 'left top' : 'left top';
- var currentTime = {};
- var opt = {
- title: rtChart._getvIndicatorTooltipTitle(currentTime),
- content: rtChart._getvIndicatorTooltipContent(currentTime),
- align: ta,
- padding: 10,
- width: 320,
- skin: 'tooltipTans'
- };
- if (opt.content != null) {
- rtChart.artTooltip = dialog(opt);
- rtChart.artTooltip.show(rtChart.vIndicator.get(0));
- rtChart.btipShow = true;
- rtChart.tootipAt = "VI";
- }
- rtChart = null;
- },
- _onvIndicatorMove: function (e) {
- if (this.artTooltip && this.tootipAt == "VI" && this.artTooltip.__popup) {
- this.artTooltip.reset();
- this._updatevIndicatorTooltip();
- }
- },
- _onvIndicatorMoveEnd: function (e) {
- this._updatevIndicatorTooltip();
- },
- _updatevIndicatorTooltip: function () {
- if (this.artTooltip && this.tootipAt == "VI" && this.artTooltip.__popup) {
- if (this.vTooltipTimer == null) {
- var rtChart = this;
- this.vTooltipTimer = window.setTimeout(function () {
- window.clearTimeout(rtChart.vTooltipTimer);
- rtChart.vTooltipTimer = null;
- var currTime = {};
- rtChart.artTooltip.title(rtChart._getvIndicatorTooltipTitle(currTime));
- rtChart.artTooltip.content(rtChart._getvIndicatorTooltipContent(currTime));
- rtChart = null;
- }, 100);
- }
- }
- if (this.trendPens) {
- for (var i in this.trendPens)
- this.trendPens[i].updateDataReader();
- }
- },
- _getvIndicatorTooltipTitle: function (currTime) {
- var gw = this.getGridWidth();
- var ix = this.vIndicator.position().left + 5;
- var begTime = this.getDrawBegTime();
- var endTime = this.getDrawEndTime();
- var span = endTime - begTime;
- var timeScale = span / gw;
- var ft = begTime + ix * timeScale;
- var title = "";
- var date = this.FileTimeToDate(ft);
- if (span > 28 * PERDAY)
- title += date.getFullYear() + "年";
- if (span > PERDAY)
- title += (date.getMonth() + 1) + "月";
- if (span > PERHOUR)
- title += date.getDate() + "日";
- title += this.FileTimeToTimeString(ft, true);
- title += " 附近的值";
- currTime.ft = ft;
- return title;
- },
- _getvIndicatorTooltipContent: function (currentTime) {
- var ft = currentTime.ft;
- if (this.trendPens) {
- var content = [];
- for (var i in this.trendPens)
- content.push(this.trendPens[i].getValueTooltipAtTime(ft));
- if (content.length)
- return content.join("");
- else
- return null;
- } else
- return null;
- },
- posvIndicator: function (ft) {
- if (ft >= this.getBegTime() && ft <= this.getEndTime()) {
- if (this.options.rtRefresh)
- this.setRtrefresh(false);
- if (ft <= this.getDrawBegTime() || ft >= this.getDrawEndTime()) {
- this._resetTumbs();
- this.updateDataArea();
- }
- var begTime = this.getDrawBegTime();
- var endTime = this.getDrawEndTime();
- var gw = this.getGridWidth();
- var span = endTime - begTime;
- var timeScale = span / gw;
- var posX = Math.floor((ft - this.getDrawBegTime()) / timeScale) - 6;
- while (1) {
- this.vIndicator.css("left", posX - 5);
- var ix = this.vIndicator.position().left + 5;
- if (begTime + ix * timeScale >= ft)
- break;
- posX++;
- }
- }
- },
- getReaderTimer: function () {
- var gw = this.getGridWidth();
- var ix = this.vIndicator.position().left + 5;
- var begTime = this.getDrawBegTime();
- var endTime = this.getDrawEndTime();
- var span = endTime - begTime;
- var timeScale = span / gw;
- var ft = begTime + ix * timeScale;
- return ft;
- },
- getHisRefreshing: function () {
- return this.options.rtRefresh;
- },
- panCanShow: function () {
- if (!this.options.panWidth || this.options.panWidth < MINPANWIDTH)
- this.options.panWidth = MINPANWIDTH;
- if (this.chartWidth < 100 + this.options.panWidth)
- return false;
- else
- return true;
- },
- thumbsCanshow: function () {
- if (this.options.showThumbs && this.chartHeight > SHOWTHUMBSHLIMT)
- return true;
- else
- return false;
- },
- thumbsShow: function () {
- if (this.options.showThumbs && this.chartHeight > SHOWTHUMBSHLIMT) {
- var beg = this.thumbBegDiv.position().left + 3;
- var end = this.thumbEndDiv.position().left + 3;
- if (beg > 0 || end < this.chartWidth)
- return true;
- else
- return false;
- } else
- return false;
- },
- _tumbsCanDrag: function (x) {
- var beg = this.thumbBegDiv.position().left + 3;
- var end = this.thumbEndDiv.position().left + 3;
- if ((x > beg && x < end) && (beg > 0 || end < this.chartWidth))
- return true;
- else
- return false;
- },
- listCanshow: function () {
- if (this.options.showList && (this.chartHeight - this.options.listHeight) > 200)
- return true;
- else
- return false;
- },
- toolBarCanShow: function () {
- if (this.chartHeight > SHOWTOOLBARHLIMIT)
- return true;
- else
- return false;
- },
- slidCanShow: function () {
- if (this.chartHeight > SLIDHLIMIT)
- return true;
- else
- return false;
- },
- setListHeight: function (h) {
- if (this.options.listHeight == h) {
- if (this.hSplite) {
- var canvas = this.hSplite.get(0);
- var ctx = canvas.getContext("2d");
- if (this.options.buttonImage && this.options.buttonImage.get(0).complete === true) {
- var img = this.options.buttonImage.get(0);
- if (this.options.listExpand)
- ctx.drawImage(img, 10, 11, 35, 5, canvas.width / 2 - 18, 0, 35, 5);
- else
- ctx.drawImage(img, 10, 15, 35, 5, canvas.width / 2 - 18, 0, 35, 5);
- }
- }
- return;
- }
- this.options.listHeight = h;
- if (this.options.listHeight < 30)
- this.options.listExpand = false;
- else
- this.options.listExpand = true;
- if (this.artTooltip)
- this.artTooltip.close().reset().remove();
- this._bulidCanvas();
- },
- setListExpand: function (bExpand) {
- if (this.options.listExpand == bExpand)
- return;
- if (bExpand) {
- if (!this.listCanshow())
- return;
- }
- this.options.listExpand = bExpand;
- if (this.artTooltip)
- this.artTooltip.close().reset().remove();
- this._bulidCanvas();
- },
- getPanShow: function () {
- return this.options.panShow;
- },
- setPanShow: function (bShow) {
- if (this.options.panShow == bShow)
- return;
- if (bShow) {
- if (!this.panCanShow())
- return;
- }
- this.options.panShow = bShow;
- this._reDrawAll();
- },
- setPanWidth: function (w) {
- if (this.options.panWidth == w)
- return;
- this.options.panWidth = w;
- if (this.chartWidth < 100 + this.options.panWidth || this.options.panWidth < MINPANWIDTH)
- this.options.panShow = false;
- this._reDrawAll();
- },
- getPanWidth: function () {
- return this.options.panWidth - PANMAG;
- },
- getOffset: function () {
- return this.canvas.offset();
- },
- getGridWidth: function () {
- return this.chartWidth - (this.options.panShow ? this.options.panWidth : 0) - 1;
- },
- getGridHeight: function () {
- var h = this.chartHeight;
- if (this.toolBarCanShow())
- h -= TOOLBARHEIGHT;
- if (this.listCanshow()) {
- if (this.options.listExpand)
- h -= this.options.listHeight;
- else
- h -= HSPLITHEIGHT;
- }
- if (this.slidCanShow())
- h -= SLIDEHEIGHT;
- if (this.thumbsCanshow())
- h -= SHOWTHUMBSHEIGHT;
- h--;
- return h;
- },
- getNextPenColor: function () {
- var i = 0;
- if (this.trendPens) {
- if (this.trendPens.length < penColors.length) {
- i = this.trendPens.length;
- return penColors[i];
- } else {
- i = this.trendPens.length % penColors.length;
- var c = TrendColor.parse(penColors[i]);
- var sign = (this.trendPens.length % 2 == 1 ? -1 : 1);
- var factor = 1 + sign * Math.ceil(this.trendPens.length / 2) * 0.2;
- c.scale(factor, factor, factor);
- return c.toString();
- }
- } else
- return penColors[i];
- },
- getButtonImage: function () {
- if (this.options.buttonImage)
- return this.options.buttonImage.get(0);
- else
- return null;
- },
- _updateTimeDisplay: function () {
- if (!this.toolBar || this.calendarShowed === true || this.timerFocus === true)
- return;
- this.toolBar.setValue("date_from", this.FileTimeToDateString(this.getBegTime()) + " " + this.FileTimeToTimeString(this.getBegTime(), this.options.spanSec < 10));
- this.toolBar.setValue("date_to", this.FileTimeToDateString(this.getEndTime()) + " " + this.FileTimeToTimeString(this.getEndTime(), this.options.spanSec < 10));
- },
- getTimeSpanString: function () {
- var spanStr = "时间跨度:";
- var span = this.options.spanSec * PERSEC;
- if (this.options.spanSec > PERDAY) {
- var d = Math.floor(span / PERDAY);
- span -= d * PERDAY;
- spanStr += d + "天";
- }
- if (this.options.spanSec * PERSEC > PERHOUR) {
- var h = Math.floor(span / PERHOUR);
- span -= h * PERHOUR;
- spanStr += h + "时";
- }
- if (this.options.spanSec * PERSEC > PERMINUTE) {
- var m = Math.floor(span / PERMINUTE);
- span -= m * PERMINUTE;
- spanStr += m + "分";
- }
- var s = Math.floor(span / PERSEC);
- span -= s * PERSEC;
- spanStr += s + "秒";
- if (this.options.spanSec <= 10) {
- var ms = (span / PERMSEC).toFixed(2);
- spanStr += ms + "毫秒";
- }
- return spanStr;
- },
- setBegTimeAndSpan: function (begTime, span) {
- span = span || 1;
- if (this.options.spanSec == span && this.ftBeginTime == begTime)
- return;
- this.ftTimeLabelBeg = null;
- this.options.spanSec = span;
- if (this.ftBeginTime == begTime)
- this.ftBeginTime = 0;
- this.updateBeginTime(begTime);
- if (this.toolBar)
- this.toolBar.setItemText("timeSpan", this.getTimeSpanString());
- this._updateTimeDisplay();
- },
- setTimeSpan: function (span, fixEnd) {
- span = span || 1;
- if (this.options.spanSec == span)
- return;
- var newBeginTime;
- if (fixEnd)
- newBeginTime = this.getEndTime() - span * PERSEC;
- else
- newBeginTime = this.getBegTime();
- this.ftTimeLabelBeg = null;
- this.options.spanSec = span;
- if (this.ftBeginTime == newBeginTime)
- this.ftBeginTime = 0;
- this.updateBeginTime(newBeginTime);
- if (this.toolBar)
- this.toolBar.setItemText("timeSpan", this.getTimeSpanString());
- this._updateTimeDisplay();
- },
- updateBeginTime: function (ft) {
- this.setBeginTime(ft);
- if (this.dataLoadTimer) {
- window.clearTimeout(this.dataLoadTimer);
- this.dataLoadTimer = null;
- }
- var rtchart = this;
- this.dataLoadTimer = window.setTimeout(function () {
- window.clearTimeout(rtchart.dataLoadTimer);
- rtchart.dataLoadTimer = null;
- if (rtchart.trendPens) {
- for (i in rtchart.trendPens) {
- var pen = rtchart.trendPens[i];
- pen.refreshHisData(true);
- }
- }
- rtchart = null;
- }, 500);
- this.updateDataArea();
- this._updatevIndicatorTooltip();
- },
- setBeginTime: function (ft) {
- if (this.ftBeginTime == ft)
- return;
- var old = this.ftBeginTime;
- this.ftBeginTime = ft;
- if (this.getHisRefreshing()) {
- if (ft < old) {
- this.autoRefresh = true;
- this.setRtrefresh(false);
- }
- }
- this._updateTimeDisplay();
- },
- setBegTime: function (begTime, fixEnd) {
- var ft = this.DateToFileTime(begTime);
- if (fixEnd) {
- if (this.getEndTime() > ft) {
- var span = this.getEndTime() - ft;
- span /= PERSEC;
- this.setBegTimeAndSpan(ft, span);
- } else {
- var d = dialog({
- content: '设置的起始时间不能大于截至时间'
- });
- d.show();
- setTimeout(function () {
- d.close().remove();
- d = null;
- }, 2000);
- }
- } else {
- this.ftTimeLabelBeg = null;
- if (this.ftBeginTime == ft)
- this.ftBeginTime = 0;
- this.updateBeginTime(ft);
- }
- },
- setEndTime: function (endTime, fixBeg) {
- var ft = this.DateToFileTime(endTime);
- if (fixBeg) {
- if (ft > this.getBegTime()) {
- var span = ft - this.getBegTime();
- span /= PERSEC;
- ft -= this.options.spanSec * PERSEC;
- this.setBegTimeAndSpan(ft, span);
- } else {
- var d = dialog({
- content: '设置的截至时间不能大于起始时间'
- });
- d.show();
- setTimeout(function () {
- d.close().remove();
- d = null;
- }, 2000);
- }
- } else {
- ft -= this.options.spanSec * PERSEC;
- this.ftTimeLabelBeg = null;
- if (this.ftBeginTime == ft)
- this.ftBeginTime = 0;
- this.updateBeginTime(ft);
- }
- },
- getBegTime: function () {
- return this.ftBeginTime;
- },
- getEndTime: function () {
- return this.ftBeginTime + (this.options.spanSec * PERSEC);
- },
- getTimeSlot: function () {
- var slotTime = this.options.spanSec * PERSEC;
- slotTime /= this.getGridWidth();
- return slotTime;
- },
- getTimeSpan: function () {
- return this.options.spanSec * PERSEC;
- },
- getDrawBegTime: function () {
- var begTime = this.getBegTime();
- if (this.thumbsShow()) {
- var beg = this.thumbBegDiv.position().left + 3;
- if (beg > 0) {
- var w = this.chartWidth - 1;
- begTime += beg * this.options.spanSec * PERSEC / w;
- }
- }
- return begTime;
- },
- getDrawEndTime: function () {
- var endTime = this.getEndTime();
- if (this.thumbsShow()) {
- var end = this.thumbEndDiv.position().left + 3;
- var w = this.chartWidth - 1;
- if (end < w) {
- endTime -= (w - end) * this.options.spanSec * PERSEC / w;
- }
- }
- return endTime;
- },
- _setNewLastTime: function (lastft) {
- if (lastft <= this.getEndTime())
- return;
- var newTimeBegin = lastft - (this.options.spanSec * PERSEC);
- if (!this.newTimeBegin || this.newTimeBegin < newTimeBegin)
- this.newTimeBegin = newTimeBegin;
- },
- _onNewHisData: function () {
- if (!this.prepareTimer) {
- var me = this;
- this.prepareTimer = window.setTimeout(function () {
- window.clearTimeout(me.prepareTimer);
- me.prepareTimer = null;
- me._prepareHisData();
- me = null;
- }, 10);
- }
- },
- _prepareHisData: function () {
- if (!this.trendPens || !this.trendPens.length)
- return;
- var begTime, endTime;
- var baseChanged = false;
- var newTimeBeg = this.newTimeBegin;
- if (newTimeBeg > this.getBegTime()) {
- baseChanged = true;
- begTime = this.newTimeBegin;
- endTime = begTime + (this.options.spanSec * PERSEC);
- this.newTimeBegin = null;
- }
- if (!baseChanged) {
- begTime = this.getBegTime();
- endTime = this.getEndTime();
- }
- for (k in this.trendPens) {
- var pen = this.trendPens[k];
- pen.prepareHisData(begTime, endTime);
- }
- if (baseChanged) {
- this.setBeginTime(begTime);
- if (!this.getHisRefreshing())
- this.setRtrefresh(true);
- this._drawTimeLabel();
- } else if (!this.getHisRefreshing()) {
- if (newTimeBeg >= this.getBegTime() - (this.options.spanSec * PERSEC) * 20 / this.getGridWidth())
- this.setRtrefresh(true);
- }
- this.updateDataArea();
- },
- _getPanTotalHeight: function () {
- if (!this.trendPens || !this.trendPens.length)
- return 0;
- var t = 0;
- for (var i = 0; i < this.trendPens.length; i++) {
- var pen = this.trendPens[i];
- t += pen.getPanHeight();
- }
- return t;
- },
- _findDragThing: function (e) {
- this.dargWho = null;
- var gw = this.getGridWidth();
- var gh = this.getGridHeight();
- var o = this.getOffset();
- var dragEvent = e;
- if (e.originalEvent &&
- e.originalEvent.changedTouches &&
- e.originalEvent.changedTouches[0])
- dragEvent = e.originalEvent.changedTouches[0];
- var x = dragEvent.pageX - o.left;
- var y = dragEvent.pageY - o.top;
- if (this.options.panShow && !this.options.showAxis && x > gw + PANMAG && y < gh)
- {
- var t = PANHEAD;
- x -= (gw + PANMAG);
- if (y < t) { } else if (this.trendPens) {
- y -= t;
- y += this.yScroll;
- t = 0;
- var dargPen = null;
- for (var i = 0; i < this.trendPens.length; i++) {
- var pen = this.trendPens[i];
- if (y >= t && y <= t + pen.getPanHeight() &&
- pen == this.activePen) {
- dargPen = pen;
- break;
- } else
- t += pen.getPanHeight();
- }
- if (dargPen) {
- this.dargWho = "penPan";
- this.origVal = this.getPenIndex(dargPen);
- } else if (t > gh - PANHEAD) {
- this.dargWho = "pan";
- this.origVal = this.yScroll;
- }
- }
- } else if (x > 0) {
- var activeDrag = false;
- if (y >= 0 && y <= gh) {
- if (this.trendPens) {
- var ft = this._getXTime(x);
- for (var i in this.trendPens) {
- var pen = this.trendPens[i];
- if (pen == this.activePen && pen.hasDataAtTime(ft, y)) {
- activeDrag = true;
- break;
- }
- }
- }
- if (this.zooming === true) {
- this.dargWho = "dataArea";
- this.origVal = this.getBegTime();
- } else if (activeDrag) {
- this.origSecVal = dragEvent.pageY;
- this.dargWho = "activePen";
- this.origVal = this.getBegTime();
- } else {
- this.dargWho = "dataArea";
- this.origVal = this.getBegTime();
- }
- } else if (y > gh && y < gh + TIMELABELHEIGHT) {
- this.dargWho = "timeLabel";
- this.origVal = this.getBegTime();
- } else if (y > gh + TIMELABELHEIGHT && this.thumbsCanshow(x)) {
- if (this._tumbsCanDrag(x)) {
- this.dargWho = "tumbsDrag";
- }
- }
- }
- },
- _getPanPenAtMouse: function (e) {
- if (this.options.panShow) {
- if (this.trendPens) {
- var gw = this.getGridWidth();
- var gh = this.getGridHeight();
- var o = this.getOffset();
- var dragEvent = e;
- if (e.originalEvent &&
- e.originalEvent.changedTouches &&
- e.originalEvent.changedTouches[0])
- dragEvent = e.originalEvent.changedTouches[0];
- var x = dragEvent.pageX - o.left;
- var y = dragEvent.pageY - o.top;
- if (this.options.panShow && x > gw + PANMAG && y < gh)
- {
- var t = PANHEAD;
- x -= (gw + PANMAG);
- if (y < t) { } else {
- y -= t;
- y += this.yScroll;
- t = 0;
- for (var i = 0; i < this.trendPens.length; i++) {
- var pen = this.trendPens[i];
- if (y >= t && y <= t + pen.getPanHeight())
- return pen;
- else
- t += pen.getPanHeight();
- }
- }
- }
- }
- }
- return null;
- },
- _getXTime: function (x) {
- return this.getDrawBegTime() + (this.getDrawEndTime() - this.getDrawBegTime()) * x / this.getGridWidth();
- },
- _onMouseWheel: function (e) {
- var gw = this.getGridWidth();
- var gh = this.getGridHeight();
- var o = this.getOffset();
- var x = e.pageX - o.left;
- var y = e.pageY - o.top;
- if (this.options.panShow && x > gw + PANMAG && y < gh)
- {
- if (gh < PANHEAD + this._getPanTotalHeight()) {
- this.yScroll += ((e.deltaY * 10) * -1);
- this.UpdateDataPan(true);
- }
- } else if (x > 0 && x < gw) {
- if (y >= 0 && y <= gh) {
- if (this.trendPens) {
- var ft = this._getXTime(x);
- for (var i in this.trendPens) {
- var pen = this.trendPens[i];
- if (pen == this.activePen) {
- pen.expendY(e.deltaY * -2);
- break;
- }
- }
- }
- }
- }
- },
- _onRtchartMouseMove: function (e) {
- if (this._isTouch())
- return;
- var rtchart = this
- var vSplite = this.vSplite,
- vsLeft = parseInt(vSplite.css('left')) - 10;
- this.vIndicator.offset({
- left: e.pageX > vsLeft ? vsLeft : e.pageX
- });
-
-
- this.__timer__ && clearTimeout(this.__timer__);
- (function (e) {
- if (e.pageX > vsLeft) return;
- this.__timer__ = setTimeout(function () {
- rtchart._onvIndicatorHover(e);
- }, 300)
- })(e);
-
-
- },
- _onMouseDown: function (e) {
- if (this._isTouch())
- return;
- if (this.artTooltip)
- this.artTooltip.close().remove();
- if (this.tooltipTimer) {
- window.clearTimeout(this.tooltipTimer);
- this.tooltipTimer = null;
- }
- var rtchart = this
- this._findDragThing(e);
- if (this.dargWho) {
- this.dragStartEvent = e;
- this.positionDiv.draggable("option", "disabled", false);
- this.positionDiv.bind("drag", function (event, ui) {
- rtchart._dragMove(event);
- });
- this.positionDiv.bind("dragstop", function (event, ui) {
- rtchart._unDarg();
- rtchart = null;
- });
- this.positionDiv.offset({
- left: e.pageX - 2,
- top: e.pageY - 2
- });
- this.positionDiv.trigger(e);
- if (this.dargWho == 'dataArea' && this.zooming)
- this.positionDiv.addClass('zoomcur');
- this.dragTimer = window.setTimeout(function () {
- var dargWho = rtchart.dargWho;
- window.clearTimeout(rtchart.dragTimer);
- rtchart.dragTimer = null;
- rtchart._unDarg();
- if (dargWho == "tumbsDrag")
- rtchart._ondbClick(e);
- else
- rtchart._onClick(e);
- rtchart = null;
- }, 200);
- }
- },
- _dragMove: function (e) {
- if (this.dragTimer) {
- window.clearTimeout(this.dragTimer);
- this.dragTimer = null;
- }
- if (this.dragStartEvent && this.dargWho) {
- var gw = this.getGridWidth();
- var gh = this.getGridHeight();
- var startEvent = this.dragStartEvent;
- var detX = e.clientX - startEvent.clientX;
- var detY = e.clientY - startEvent.clientY;
- switch (this.dargWho) {
- case 'pan':
- this.yScroll = this.origVal - detY;
- this.UpdateDataPan(true);
- break;
- case 'penPan':
- var pen = this._getPanPenAtMouse(e);
- if (pen) {
- var newPos = this.getPenIndex(pen)
- if (newPos != this.origVal && newPos != this.newPenPos) {
- this.newPenPos = newPos;
- this.UpdateDataPan(true);
- } else if (this.trendPens && this.getGridHeight() < PANHEAD + this._getPanTotalHeight()) {
- var gh = this.getGridHeight();
- var o = this.getOffset();
- var y = e.pageY - o.top;
- if (y < 20) {
- if (this.yScroll > 0) {
- this.yScroll -= pen.getPanHeight();
- this.UpdateDataPan(true);
- }
- } else if (y > gh - 10) {
- this.yScroll += pen.getPanHeight();
- this.UpdateDataPan(true);
- }
- }
- }
- break;
- case 'timeLabel':
- this.setBeginTime(this.origVal - detX * (this.getDrawEndTime() - this.getDrawBegTime()) / gw);
- this.updateDataArea();
- break;
- case 'activePen':
- if (this.activePen && this.origSecVal) {
- var dY = e.pageY - this.origSecVal;
- if (Math.abs(detY) > 5) {
- this.activePen.moveY(dY);
- this.origSecVal = e.pageY;
- }
- }
- if (Math.abs(detX) > 30) {
- this.acvtimePenTimeOffset = true;
- this.setBeginTime(this.origVal - detX * (this.getDrawEndTime() - this.getDrawBegTime()) / gw);
- this.updateDataArea();
- }
- break;
- case 'dataArea':
- if (this.zooming) {
- var o = this.canvas.offset();
- var x = startEvent.pageX - o.left;
- var y = startEvent.pageY - o.top;
- var gw = this.getGridWidth();
- var gh = this.getGridHeight();
- if (x > 0 && x < gw &&
- y > 0 && y < gh) {
- this.zoomRect = {
- x: x,
- y: y,
- w: detX,
- h: detY
- };
- var x = this.zoomRect.x;
- if (this.zoomRect.w < 0)
- x += this.zoomRect.w;
- this.zoomRect.begTime = this._getXTime(x);
- this.updateDataArea();
- }
- } else {
- this.setBeginTime(this.origVal - detX * (this.getDrawEndTime() - this.getDrawBegTime()) / gw);
- this.updateDataArea();
- }
- break;
- case 'tumbsDrag':
- if (detX > 0) {
- var end = this.thumbEndDiv.position().left + 3;
- if (end < this.chartWidth - 3) {
- var l = parseInt(this.thumbEndDiv.css('left')) + detX;
- if (l > this.chartWidth - 3)
- l = this.chartWidth - 3;
- this.thumbEndDiv.css('left', l);
- l = parseInt(this.thumbBegDiv.css('left')) + detX;
- this.thumbBegDiv.css('left', l);
- this._onThumbsChanged();
- }
- } else if (detX < 0) {
- var beg = this.thumbBegDiv.position().left + 3;
- if (beg > 0) {
- var l = parseInt(this.thumbBegDiv.css('left')) + detX;
- if (l < -3)
- l = -3;
- this.thumbBegDiv.css('left', l);
- l = parseInt(this.thumbEndDiv.css('left')) + detX;
- this.thumbEndDiv.css('left', l);
- this._onThumbsChanged();
- }
- }
- this.dragStartEvent = e;
- break;
- }
- } else
- this._unDarg();
- },
- _unDarg: function () {
- if (this.dragTimer) {
- window.clearTimeout(this.dragTimer);
- this.dragTimer = null;
- }
- switch (this.dargWho) {
- case 'penPan':
- if (this.newPenPos != null) {
- var pen = this.trendPens[this.newPenPos];
- this.trendPens[this.newPenPos] = this.getPenByIndex(this.origVal);
- this.trendPens[this.origVal] = pen;
- this.newPenPos = null;
- this.UpdateDataPan(true);
- this._synList();
- }
- break;
- case 'timeLabel':
- if (this.trendPens) {
- for (i in this.trendPens) {
- var pen = this.trendPens[i];
- pen.refreshHisData();
- }
- }
- break;
- case 'dataArea':
- if (this.zooming) {
- this._toggleZoom();
- this.positionDiv.removeClass('zoomcur');
- if (this.zoomRect) {
- if (this.zoomRect.w < 0) {
- this.zoomRect.x += this.zoomRect.w;
- this.zoomRect.w *= -1;
- }
- if (this.zoomRect.h < 0) {
- this.zoomRect.y += this.zoomRect.h;
- this.zoomRect.h *= -1;
- }
- if (this.zoomStack == null)
- this.zoomStack = [];
- var zoomItem = {};
- zoomItem.begTime = this.getBegTime();
- zoomItem.spanTime = this.options.spanSec;
- this.zoomStack.push(zoomItem);
- this._updateReZoom();
- var begTime = this.zoomRect.begTime;
- var span = (this.getDrawEndTime() - this.getDrawBegTime()) * this.zoomRect.w / this.getGridWidth();
- if (span < 1)
- span = 1;
- var endTime = begTime + span;
- if (this.trendPens) {
- for (i in this.trendPens) {
- var pen = this.trendPens[i];
- if (pen.hasDataBetweenTime(begTime, endTime)) {
- if (zoomItem.pens == null)
- zoomItem.pens = [];
- zoomItem.pens.pushpen
- }
- }
- }
- this.zoomRect = null;
- this._resetTumbs();
- this.setBegTimeAndSpan(begTime, span / PERSEC);
- }
- } else if (this.trendPens) {
- for (i in this.trendPens) {
- var pen = this.trendPens[i];
- pen.refreshHisData();
- }
- }
- break;
- case 'activePen':
- if (this.acvtimePenTimeOffset && this.trendPens) {
- for (i in this.trendPens) {
- var pen = this.trendPens[i];
- pen.refreshHisData();
- }
- }
- break;
- }
- this.origSecVal = null;
- this.dargWho = null;
- this.origVal = null;
- this.dragStartEvent = null;
- this.positionDiv.draggable("option", "disabled", true);
- this.positionDiv.unbind("drag");
- this.positionDiv.unbind("dragstop");
- this.positionDiv.offset({
- left: this.canvas.offset().left,
- top: this.canvas.offset().top
- });
- },
- _onTouchStart: function (e) {
- if (this.artTooltip)
- this.artTooltip.close().remove();
- if (this.tooltipTimer) {
- window.clearTimeout(this.tooltipTimer);
- this.tooltipTimer = null;
- }
- this._findDragThing(e);
- if (this.dargWho) {
- this.dragStartEvent = e;
- var rtchart = this;
- this.canvas.bind('touchmove', function (e) {
- rtchart._onTouchMove(e);
- });
- this.canvas.bind('touchend', function (e) {
- rtchart._onTouchEnd(e);
- rtchart = null;
- });
- this.dragTimer = window.setTimeout(function () {
- window.clearTimeout(rtchart.dragTimer);
- rtchart.dragTimer = null;
- if (rtchart.tooltipTimer) {
- window.clearTimeout(rtchart.tooltipTimer);
- rtchart.tooltipTimer = null;
- }
- rtchart._onTouchEnd();
- rtchart = null;
- }, 800);
- }
- },
- _onTouchMove: function (e) {
- if (this.dragTimer) {
- window.clearTimeout(this.dragTimer);
- this.dragTimer = null;
- }
- if (this.dragStartEvent && this.dargWho) {
- var startEvent = this.dragStartEvent.originalEvent.changedTouches[0];
- var currEvent = e.originalEvent.changedTouches[0];
- var detX = currEvent.clientX - startEvent.clientX;
- var detY = currEvent.clientY - startEvent.clientY;
- switch (this.dargWho) {
- case 'pan':
- this.yScroll = this.origVal - detY;
- this.UpdateDataPan(true);
- break;
- case 'penPan':
- var pen = this._getPanPenAtMouse(e);
- if (pen) {
- var newPos = this.getPenIndex(pen)
- if (newPos != this.origVal && newPos != this.newPenPos) {
- this.newPenPos = newPos;
- this.UpdateDataPan(true);
- } else if (this.trendPens && this.getGridHeight() < PANHEAD + this._getPanTotalHeight()) {
- var gh = this.getGridHeight();
- var o = this.getOffset();
- var y = currEvent.pageY - o.top;
- if (y < 20) {
- if (this.yScroll > 0) {
- this.yScroll -= pen.getPanHeight();
- this.UpdateDataPan(true);
- }
- } else if (y > gh - 10) {
- this.yScroll += pen.getPanHeight();
- this.UpdateDataPan(true);
- }
- }
- }
- break;
- default:
- this._onTouchEnd();
- return;
- }
- } else
- this._onTouchEnd();
- },
- _onTouchEnd: function (e) {
- if (this.dragTimer) {
- window.clearTimeout(this.dragTimer);
- this.dragTimer = null;
- }
- if (this.newPenPos != null) {
- var pen = this.trendPens[this.newPenPos];
- this.trendPens[this.newPenPos] = this.getPenByIndex(this.origVal);
- this.trendPens[this.origVal] = pen;
- this.newPenPos = null;
- this.UpdateDataPan(true);
- }
- this.canvas.unbind('touchmove');
- this.canvas.unbind('touchend');
- this.dargWho = null;
- this.origVal = null;
- this.dragStartEvent = null;
- },
- _onKeyDown: function (e) {
- switch (e.which) {
- case 39:
- if (this.artTooltip && this.tootipAt == "VI" && this.artTooltip.__popup) {
- if (this.thumbsShow()) {
- var x = this.vIndicator.position().left + 5;
- var endTime = this._getXTime(x + 2);
- var limit = this.getDrawEndTime();
- if (endTime >= limit) {
- var l = parseInt(this.thumbEndDiv.css('left'));
- var s = l + 10;
- if (s > this.chartWidth - 3)
- s = this.chartWidth - 3;
- if (s > l) {
- this.thumbEndDiv.css('left', s);
- s = parseInt(this.thumbBegDiv.css('left')) + s - l;
- if (s > this.chartWidth - 13)
- s = this.chartWidth - 13;
- this.thumbBegDiv.css('left', s);
- this._onThumbsChanged();
- }
- }
- }
- var gw = this.getGridWidth();
- var off = this.vIndicator.offset();
- if (off.left + 1 <= this.canvas.offset().left + gw - 5) {
- this.vIndicator.offset({
- left: off.left + 1,
- top: off.top
- });
- this.artTooltip.reset();
- this._updatevIndicatorTooltip();
- }
- } else {
- var gw = this.getGridWidth();
- var begTime = this.getDrawBegTime();
- var endTime = this.getDrawEndTime();
- var det = (endTime - begTime) / gw;
- this.updateBeginTime(this.getBegTime() - det);
- }
- break;
- case 37:
- if (this.artTooltip && this.tootipAt == "VI" && this.artTooltip.__popup) {
- if (this.thumbsShow()) {
- var x = this.vIndicator.position().left + 5;
- var begTime = this._getXTime(x - 2);
- var limit = this.getDrawBegTime();
- if (begTime <= limit) {
- var l = parseInt(this.thumbBegDiv.css('left'));
- var s = l - 10;
- if (s < -3)
- s = -3;
- if (s < l) {
- this.thumbBegDiv.css('left', s);
- s = parseInt(this.thumbEndDiv.css('left')) - (l - s);
- if (s < 13)
- s = 13;
- this.thumbEndDiv.css('left', s);
- this._onThumbsChanged();
- }
- }
- }
- var gw = this.getGridWidth();
- var off = this.vIndicator.offset();
- if (off.left - 1 >= this.canvas.offset().left - 5) {
- this.vIndicator.offset({
- left: off.left - 1,
- top: off.top
- });
- this.artTooltip.reset();
- this._updatevIndicatorTooltip();
- }
- } else {
- var gw = this.getGridWidth();
- var begTime = this.getDrawBegTime();
- var endTime = this.getDrawEndTime();
- var det = (endTime - begTime) / gw;
- this.updateBeginTime(this.getBegTime() + det);
- }
- break;
- case 38:
- if (this.artTooltip && this.tootipAt == "HI" && this.artTooltip.__popup) {
- var gh = this.getGridHeight();
- var off = this.hIndicator.offset();
- if (off.top - 1 >= this.canvas.offset().top - 5) {
- this.hIndicator.offset({
- left: off.left,
- top: off.top - 1
- });
- this.artTooltip.content(this._gethIndicatorTooltipContent());
- this.artTooltip.reset();
- }
- } else if (this.activePen)
- this.activePen.moveY(-1);
- break;
- case 40:
- if (this.artTooltip && this.tootipAt == "HI" && this.artTooltip.__popup) {
- var gh = this.getGridHeight();
- var off = this.hIndicator.offset();
- if (off.top + 1 <= this.canvas.offset().top + gh - 5) {
- this.hIndicator.offset({
- left: off.left,
- top: off.top + 1
- });
- this.artTooltip.content(this._gethIndicatorTooltipContent());
- this.artTooltip.reset();
- }
- } else if (this.activePen)
- this.activePen.moveY(1);
- break;
- }
- },
- _ondbClick: function (e) {
- var gw = this.getGridWidth();
- var gh = this.getGridHeight();
- var o = this.getOffset();
- var x = e.pageX - o.left;
- var y = e.pageY - o.top;
- if (y > gh + TIMELABELHEIGHT && this.thumbsCanshow()) {
- this._resetTumbs();
- this.updateDataArea();
- }
- },
- _onClick: function (e) {
- this.canvas.attr("title", null);
- this.canvas.css("cursor", "default");
- if (this.btipShow === true &&
- this.tipShowPen &&
- this.tipShowPen.getpreventTooltipUpdate() === true) {
- if (this.artTooltip)
- this.artTooltip.close().remove();
- return;
- }
- if (!this.trendPens || !this.trendPens.length)
- return;
- if (this.zooming)
- this._toggleZoom(e);
- var gw = this.getGridWidth();
- var gh = this.getGridHeight();
- var o = this.getOffset();
- var x = e.pageX - o.left;
- var y = e.pageY - o.top;
- var clientx = x;
- var clienty = y
- if (this.options.panShow && x > gw + PANMAG && y < gh)
- {
- if (!this.options.showAxis) {
- var t = PANHEAD;
- x -= (gw + PANMAG);
- if (y < t) { } else {
- y -= t;
- y += this.yScroll;
- t = 0;
- for (var i = 0; i < this.trendPens.length; i++) {
- var pen = this.trendPens[i];
- if (y >= t && y <= t + pen.getPanHeight()) {
- if (pen.onClick(x, y - t, e) === true) { }
- break;
- } else
- t += pen.getPanHeight();
- }
- }
- } else {
- for (var i = 0; i < this.trendPens.length; i++) {
- var pen = this.trendPens[i];
- var beg = pen.axisBeg;
- var end = pen.axisEnd;
- if (clientx >= beg && clientx <= end) {
- if (this.btipShow) {
- if (this.artTooltip)
- this.artTooltip.close().remove();
- }
- pen.onSetCommAxis(e);
- break;
- }
- }
- }
- } else if (y >= 0 && y < gh) {
- if (this.trendPens) {
- var ft = this._getXTime(x);
- var oldActive = this.activePen;
- var bFind = false;
- var first = null;
- for (var i in this.trendPens) {
- pen = this.trendPens[i];
- if (pen == oldActive) {
- bFind = true;
- this.requestActive(null);
- } else if (pen.hasDataAtTime(ft, y)) {
- if (bFind || oldActive == null) {
- pen.activePen();
- return;
- } else if (first == null)
- first = pen;
- }
- }
- if (first)
- first.activePen();
- }
- } else if (y > gh && y < gh + TIMELABELHEIGHT) {
- if (x < 70)
- this._onSetBegTime(e);
- else if (x > gw - 80 && x < gw)
- this._onSetEndTime(e);
- }
- },
- _onMouseMove: function (e) {
- if (this.colorPicker && this.colorPicker.is(":visible"))
- return;
- if (this.btipShow === true &&
- this.tipShowPen &&
- this.tipShowPen.getpreventTooltipUpdate() === true)
- return;
- if (!this.trendPens || !this.trendPens.length)
- return;
- if (this.tooltipTimer) {
- window.clearTimeout(this.tooltipTimer);
- this.tooltipTimer = null;
- }
- var oldShow = this.btipShow;
- var bClearCursor = true;
- var bClearNativeTooltip = true;
- this.btipShow = false;
- var gw = this.getGridWidth();
- var gh = this.getGridHeight();
- var o = this.getOffset();
- var x = e.pageX - o.left;
- var y = e.pageY - o.top;
- var clientx = x;
- var clienty = y
- if (clientx > 0 && clientx < this.chartWidth &&
- clienty > 0 && clienty < this.chartHeight) {
- if (this.options.panShow && x > gw + PANMAG && y < gh)
- {
- if (this.zooming)
- this.canvas.removeClass('zoomcur');
- if (!this.options.showAxis) {
- var t = PANHEAD;
- x -= (gw + PANMAG);
- if (y < t) { } else {
- y -= t;
- y += this.yScroll;
- t = 0;
- for (var i = 0; i < this.trendPens.length; i++) {
- var pen = this.trendPens[i];
- if (y >= t && y <= t + pen.getPanHeight()) {
- if (pen.onMouseMove(x, y - t, e, clientx, clienty, gh) === true)
- bClearCursor = false;
- break;
- } else
- t += pen.getPanHeight();
- }
- }
- } else {
- for (var i = 0; i < this.trendPens.length; i++) {
- var pen = this.trendPens[i];
- var beg = pen.axisBeg;
- var end = pen.axisEnd;
- if (clientx >= beg && clientx <= end) {
- bClearCursor = false;
- bClearNativeTooltip = false;
- this.canvas.css("cursor", "pointer");
- this.canvas.attr("title", "点击进行 " + pen.getLabel() + " 的共轴设置");
- break;
- }
- }
- }
- } else if (y >= 0 && y < gh) {
- if (this.zooming)
- this.canvas.addClass('zoomcur');
- } else if (y > gh && y < gh + TIMELABELHEIGHT) {
- if (this.zooming)
- this.canvas.removeClass('zoomcur');
- if (x < 70) {
- bClearCursor = false;
- bClearNativeTooltip = false;
- this.canvas.css("cursor", "pointer");
- this.canvas.attr("title", "点击设置查询起始时间");
- } else if (x > gw - 80 && x < gw) {
- bClearCursor = false;
- bClearNativeTooltip = false;
- this.canvas.css("cursor", "pointer");
- this.canvas.attr("title", "点击设置查询截至时间");
- }
- } else if (y > gh + TIMELABELHEIGHT && this.thumbsCanshow()) {
- if (this._tumbsCanDrag(x)) {
- bClearCursor = false;
- this.canvas.css("cursor", "e-resize");
- }
- }
- }
- if (bClearNativeTooltip)
- this.canvas.attr("title", null);
- if (bClearCursor && !this.zooming)
- this.canvas.css("cursor", "default");
- if (oldShow && !this.btipShow) {
- if (this.artTooltip)
- this.artTooltip.close().remove();
- }
- if (!this.btipShow && this.tipShowPen) {
- this.tipShowPen.onTooltipHided();
- this.tipShowPen = null;
- }
- },
- _linkData: function (pen) {
- if (!this.webLinks)
- this.webLinks = [];
- var url = pen.getWebURL().toLowerCase();
- var webLink = this.webLinks[url];
- if (webLink == null) {
- webLink = new WebLink(url);
- this.webLinks[url] = webLink;
- }
- webLink.addPen(pen);
- },
- _buildColorPicker: function () {
- if (this.colorPicker)
- return;
- this.colorPicker = $(document.createElement('div'));
- this.colorPicker.css("position", "absolute")
- .addClass("dropdown-menu")
- .addClass("colorpicker-title");
- this.element.append(this.colorPicker);
- this.colorPicker.append(document.createElement('div'));
- $('div:first', this.colorPicker)
- .attr("data-color", "rgb(255, 255, 255)")
- .addClass("colorpicker-ind")
- .colorpicker({
- align: 'left'
- });
- this.colorPicker.draggable({
- drag: function (event, ui) {
- $('.colorpicker-ind', this).colorpicker('reposition');
- }
- });
- var label = $(document.createElement('span'));
- this.colorPicker.append(label);
- label.addClass("colorpicker-label");
- var prev = $(document.createElement('div'));
- prev.html('<div class="colorpicker-prevbk"></div>')
- this.colorPicker.append(prev);
- prev
- .addClass("colorpicker-prev")
- .attr('title', '点击恢复到上次设置');
- var resume = $(document.createElement('div'));
- resume.html('<div class="colorpicker-resumebk"></div>')
- this.colorPicker.append(resume);
- resume
- .addClass("colorpicker-resume")
- .attr('title', '点击恢复初始设置');
- },
- AddPen: function (options) {
- if (!this.trendPens)
- this.trendPens = [];
- var pen = new TrendPen(this, options);
- for (var i = 0; i < this.trendPens.length; i++) {
- if (this.trendPens[i].options.URI == pen.options.URI) {
- alert(pen.options.URI + "已存在");
- return;
- }
- }
- this.trendPens.push(pen);
- this._bindPenList(pen);
- this._linkData(pen);
- this._drawPan(false);
- },
- removePen: function (pen) {
- if (this.tipShowPen == pen) {
- if (this.artTooltip)
- this.artTooltip.close().remove();
- }
- if (this.activePen) {
- this.activePen.setActive(false);
- this.activePen = null;
- if (this.toolBar)
- this.toolBar.disableItem("deletePoint");
- }
- var bFind = false;
- if (this.trendPens) {
- var len = this.trendPens.length;
- for (var i = 0; i < len; i++) {
- if (this.trendPens[i] == pen) {
- bFind = true;
- this.trendPens.splice(i, 1);
- break;
- }
- }
- }
- if (pen.rowId != null && this.listGrid) {
- this.listGrid.deleteRow(pen.rowId);
- }
- pen.destroy();
- if (bFind) {
- this.UpdatePan(true);
- this.updateDataArea();
- }
- },
- getPenIndex: function (pen) {
- if (this.trendPens) {
- for (var i = 0; i < this.trendPens.length; i++) {
- if (this.trendPens[i] == pen)
- return i;
- }
- }
- return -1;
- },
- getPenByIndex: function (i) {
- if (!this.trendPens)
- return null;
- else
- return this.trendPens[i];
- },
- requestLogin: function (from, notCloseAutoLogClose) {
- if (this.artTooltip)
- this.artTooltip.close().remove();
- if (this.loginning === true)
- return;
- this.loginning = true;
- var rtChart = this;
- },
- getActivePen: function () {
- return this.activePen;
- },
- ensurePenPanVisble: function (pen) {
- if (this.options.panShow && !this.options.showAxis) {
- var t = 0;
- var gh = this.getGridHeight();
- for (var i = 0; i < this.trendPens.length; i++) {
- var findPen = this.trendPens[i];
- if (findPen == pen) {
- if (t < this.yScroll) {
- this.yScroll = t;
- this.UpdateDataPan(true);
- } else if (t - this.yScroll + pen.getPanHeight() + PANHEAD > gh) {
- this.yScroll = t + pen.getPanHeight() + PANHEAD - gh;
- this.UpdateDataPan(true);
- }
- break;
- } else
- t += pen.getPanHeight();
- }
- }
- },
- requestActive: function (pen) {
- if (this.activePen == pen)
- return;
- if (this.activePen)
- this.activePen.setActive(false);
- this.activePen = pen;
- if (this.activePen) {
- this.activePen.setActive(true);
- this.ensurePenPanVisble(this.activePen);
- if (this.activePen.rowId && this.listGrid && this.activePen.rowId != this.listGrid.getSelectedRowId())
- this.listGrid.selectRow(this.listGrid.getRowIndex(this.activePen.rowId), false, false, true);
- if (this.toolBar)
- this.toolBar.enableItem("deletePoint");
- } else {
- if (this.toolBar)
- this.toolBar.disableItem("deletePoint");
- if (this.listGrid && this.listGrid.getSelectedRowId() != null)
- this.listGrid.clearSelection();
- }
- this._drawDataArea();
- },
- setPenColor: function (pen, e) {
- if (this.btipShow) {
- if (this.artTooltip)
- this.artTooltip.close().remove();
- }
- if (!this.colorPicker)
- this._buildColorPicker();
- var colorpicker = this.colorPicker;
- if (colorpicker.prevColor != null) {
- $('.colorpicker-prev', colorpicker).show();
- $('.colorpicker-prevbk', colorpicker).css('background-color', colorpicker.prevColor);
- $('.colorpicker-prev', colorpicker).bind("click", function () {
- if (colorpicker) {
- $('.colorpicker-ind', colorpicker).colorpicker('setValue', colorpicker.prevColor);
- }
- });
- } else
- $('.colorpicker-prev', colorpicker).hide();
- colorpicker.resumeColor = pen.getPenColor();
- $('.colorpicker-resume', colorpicker).bind("click", function () {
- if (colorpicker) {
- $('.colorpicker-ind', colorpicker).colorpicker('setValue', colorpicker.resumeColor);
- }
- });
- var o = this.getOffset();
- var x = e.pageX - o.left;
- var y = e.pageY - o.top;
- var at;
- if (x < this.chartWidth / 2)
- at = "left+15";
- else
- at = "right-10";
- if (y < this.chartHeight / 2)
- at += " top+15";
- else
- at += " bottom-140";
- $('.colorpicker-label', colorpicker).text("设置趋势笔颜色:" + pen.getLabel());
- colorpicker.show()
- .position({
- my: at,
- of: e,
- collision: "fit"
- });
- $('.colorpicker-resumebk', colorpicker).css('background-color', pen.getPenColor());
- $('.colorpicker-ind', colorpicker)
- .colorpicker('setValue', pen.getPenColor())
- .colorpicker('show')
- .off()
- .on('changeColor.colorpicker', function (event) {
- if (pen)
- pen.setPenColor(event.color.toString());
- })
- .on('hidePicker.colorpicker', function (event) {
- if (colorpicker) {
- colorpicker.prevColor = $(this).data('colorpicker').color.toString();
- colorpicker.hide();
- $('.colorpicker-ind', colorpicker).off();
- $('.colorpicker-resume', colorpicker).unbind();
- $('.colorpicker-prev', colorpicker).unbind();
- colorpicker = null;
- }
- if (pen)
- pen = null;
- });
- },
- setColors: function (who, clr) {
- switch (who) {
- case 'bkColor':
- this.options.bkColor = clr;
- this.canvas.css('background-color', clr);
- break;
- case 'gridColor':
- if (this.options.gridColor != clr) {
- this.options.gridColor = clr;
- this.updateDataArea();
- this.UpdateAxisPan(true);
- }
- break;
- case 'indColor':
- if (this.options.indicatorColor != clr) {
- var img = this.options.buttonImage;
- if (img) {
- img = img.get(0);
- if (img.complete !== true)
- img = null;
- }
- var gw = this.getGridWidth();
- var gh = this.getGridHeight();
- var hw;
- if (this.options.showAxis)
- hw = this.chartWidth;
- else
- hw = gw + 12;
- this.options.indicatorColor = clr;
- var node = this.hIndicator.get(0);
- var hctx = node.getContext('2d');
- hctx.clearRect(0, 0, node.width, node.height);
- hctx.save();
- hctx.translate(0.5, 0.5);
- hctx.lineWidth = 3.0;
- hctx.strokeStyle = this.options.indicatorColor;
- hctx.beginPath();
- hctx.moveTo(1, 5);
- hctx.lineTo(hw, 5);
- hctx.stroke();
- hctx.restore();
- if (img)
- hctx.drawImage(img, 11, 0, 11, 11, gw - 3, 0, 11, 11);
- node = this.vIndicator.get(0);
- var vctx = node.getContext('2d');
- vctx.clearRect(0, 0, node.width, node.height);
- vctx.save();
- vctx.translate(0.5, 0.5);
- vctx.lineWidth = 3.0;
- vctx.strokeStyle = this.options.indicatorColor;
- vctx.beginPath();
- vctx.moveTo(5, 1);
- vctx.lineTo(5, gh + 10);
- vctx.stroke();
- vctx.restore();
- if (img)
- vctx.drawImage(img, 0, 0, 11, 11, 0, gh - 3, 11, 11);
- }
- break;
- case 'bordrColor':
- if (this.options.borderColor != clr) {
- this.options.borderColor = clr;
- this._reDrawAll();
- }
- break;
- case 'timeLabelColor':
- if (this.options.timeLabelColor != clr) {
- this.options.timeLabelColor = clr;
- this._drawTimeLabel();
- }
- break;
- }
- },
- parseDate: function (datestr) {
- var date = null;
- var indate = datestr.split(" ");
- if (indate.length > 0) {
- var d = indate[0].split("-");
- if (d.length == 3) {
- do {
- var y = parseInt(d[0]);
- if (isNaN(y) || y < 0)
- break;
- if (d[0].length <= 2)
- y += 2000;
- var m = parseInt(d[1]);
- if (isNaN(m))
- break;
- if (m < 1 || m > 12)
- break;
- m--;
- var day = parseInt(d[2]);
- if (isNaN(day))
- break;
- if (day < 1 || day > 31)
- break;
- date = new Date(y, m, day, 0, 0, 0, 0);
- if (indate.length < 2)
- break;
- d = indate[1].split(":");
- if (d.length == 3) {
- var h = parseInt(d[0]);
- if (isNaN(h) || h < 0 || h > 23)
- break;
- date.setHours(h);
- var m = parseInt(d[1]);
- if (isNaN(m) || m < 0 || h > 59)
- break;
- date.setMinutes(m);
- var s = parseInt(d[2]);
- if (isNaN(s) || s < 0 || s > 59)
- break;
- date.setSeconds(s);
- var ms = parseFloat(d[2]);
- if (ms != s) {
- ms -= s;
- ms *= 1000;
- ms = ms.toFixed(0);
- date.setMilliseconds(ms);
- }
- }
- } while (false);
- }
- }
- return date;
- },
- _onSetBegTime: function (e) {
- if (this.btipShow) {
- if (this.artTooltip)
- this.artTooltip.close().remove();
- }
- var rtChart = this;
- var d = dialog({
- title: '设置查询起始时间',
- quickClose: true,
- content: '<input type="text" name="dateSet" style="margin-bottom:5px; width:160px;"/><br><label><input name="fixEnd" type="checkbox" checked="checked"/>保持查询截至时间不变</label>',
- onshow: function () {
- var set =
- $('input[name=dateSet]', this.__popup)
- .val(rtChart.FileTimeToDateString(rtChart.getBegTime()) + " " + rtChart.FileTimeToTimeString(rtChart.getBegTime()))
- .datetimepicker({
- changeMonth: true,
- changeYear: true
- });
- $('input[name=dateSet]', this.__popup).keydown(this, function (e) {
- switch (e.which) {
- case 13:
- d.ok();
- break;
- case 27:
- d.close().remove();
- d = null;
- rtChart = null;
- break;
- }
- });
- $('#ui-datepicker-div').draggable();
- },
- okValue: '确定',
- ok: function () {
- var date = rtChart.parseDate($('input[name=dateSet]', this.__popup).val());
- if (date != null) {
- var fixEnd = $('input[name=fixEnd]', this.__popup)[0].checked;
- rtChart.setBegTime(date, fixEnd);
- }
- d.close().remove();
- d = null;
- },
- onclose: function () {
- $('input[name=dateSet]', this.__popup)
- .datetimepicker("hide");
- $('#ui-datepicker-div').draggable("destroy");
- rtChart = null;
- }
- });
- e.pageX += 10;
- e.pageY -= 30;
- d.show(e);
- },
- _onSetEndTime: function (e) {
- if (this.btipShow) {
- if (this.artTooltip)
- this.artTooltip.close().remove();
- }
- var rtChart = this;
- var d = dialog({
- title: '设置查询截至时间',
- quickClose: true,
- content: '<input type="text" name="dateSet" style="margin-bottom:5px; width:160px;"/><br><label><input name="fixBeg" type="checkbox" checked="checked"/>保持查询起始时间不变</label>',
- onshow: function () {
- var set =
- $('input[name=dateSet]', this.__popup)
- .val(rtChart.FileTimeToDateString(rtChart.getEndTime()) + " " + rtChart.FileTimeToTimeString(rtChart.getEndTime()))
- .datetimepicker({
- changeMonth: true,
- changeYear: true
- });
- $('input[name=dateSet]', this.__popup).keydown(this, function (e) {
- switch (e.which) {
- case 13:
- d.ok();
- break;
- case 27:
- d.close().remove();
- d = null;
- rtChart = null;
- break;
- }
- });
- $('#ui-datepicker-div').draggable();
- },
- okValue: '确定',
- ok: function () {
- var date = rtChart.parseDate($('input[name=dateSet]', this.__popup).val());
- if (date != null) {
- var fixBeg = $('input[name=fixBeg]', this.__popup)[0].checked;
- rtChart.setEndTime(date, fixBeg);
- }
- d.close().remove();
- d = null;
- },
- onclose: function () {
- $('input[name=dateSet]', this.__popup)
- .datetimepicker("hide");
- $('#ui-datepicker-div').draggable("destroy");
- rtChart = null;
- }
- });
- e.pageX += 10;
- e.pageY -= 30;
- d.show(e);
- },
- _loadPoints: function (dia, grid, info, start, count, tabfilter, tagfilter, totalCount, descfilter) {
- info.css("color", "rgb(0,0,100)");
- info.text("正在获取数据...");
- var rtchart = this;
- this._loadAddPoints = true;
-
- var str = "http://" + webServiceIP + ":" + webServicePort + "/api/Point?start=" + start + "&count=" + count + "&filter=" + tagfilter + "&tabfilter=" + tabfilter + "&desc=" + descfilter;
- $.ajax({
- url: str,
- type: 'GET',
- dataType: 'json',
- cache: false,
- success: function (data) {
-
- if (data.Count == 0) {
- totalCount.Num = 0;
- info.css("color", "rgb(0,0,100)");
- info.text("未查询到相关数据点");
- info.attr("title", "未查询到相关数据点)");
- return;
- }
- totalCount.Num = data.Count;
- var ind = start;
- if (data.PointsPros && data.PointsPros.length > 0) {
- info.css("color", "rgb(0,0,100)");
- info.text("请选择一个或多个数据点:(总共:" + totalCount.Num + " 个数据点)");
- info.attr("title", "(共有:" + totalCount.Num + " 个数据点)");
- var pointspros = data.PointsPros;
- var len = data.PointsPros.length;
- var newind = 1;
- var append = false;
- if (grid.getRowsNum() == 0)
- append = true;
- for (var i = 0; i < len; i++) {
- var id, name, des, unit, type;
- id = pointspros[i].Id;
- name = pointspros[i].TagName;
- des = pointspros[i].Desc;
- unit = pointspros[i].Uint;
- type = pointspros[i].Type;
- if (append === true) {
- grid.addRow(i, [false, newind++, id, name, des, unit, type]);
- } else {
- var pid = 'p_' + ind;
- grid.cells(pid, 2).setValue(id);
- grid.cells(pid, 3).setValue(name);
- grid.cells(pid, 4).setValue(des);
- grid.cells(pid, 5).setValue(unit);
- grid.cells(pid, 6).setValue(type);
- grid.changeRowId(pid, id);
- ind++;
- }
- }
- } else {
- info.css("color", "rgb(0,0,100)");
- info.text("没有符合搜索条件的数据点");
- info.attr("title", null);
- }
- }
- })
- },
- _loadTableNames: function (comBox) {
- if (typeof (tableNameStr) != "undefined") {
- if (tableNameStr.length > 0) {
- for (var i = 0; i < tableNames.length; i++) {
- comBox.addOption(tableNames[i], tableNames[i]);
- }
- comBox.setComboText(tableNames[0]);
- return;
- }
- }
- var str = "http://" + webServiceIP + ":" + webServicePort + "/api/Table?isAllTalbleInfo=all";
- $.ajax({
- url: str,
- type: 'GET',
- dataType: 'json',
- cache: false,
- success: function (data) {
- for (var i = 0; i < data.length; i++) {
- comBox.addOption(data[i], data[i]);
- }
- }
- })
- },
- _onAddPoint: function () {
- var rtChart = this;
- var w = 660;
- var h = 480;
- if (w > this.canvas.width() - 60)
- w = this.canvas.width() - 60;
- if (h > this.canvas.height() - 110)
- h = this.canvas.height() - 110;
- var content = '<label>所属表:<div name="tabfileter" style="width:180px;display:inline-block; "></div></label><br>';
- content += '<label style="line-height:30px;">标签名:<input type="text" name="tagfileter" placeholder="所有(*)"></input><br>';
- content += '<label style="line-height:30px;">描 述:<input type="text" name="descfileter" placeholder="所有(*)"></input>';
- content += '<input value="选定" type="button" style="float:right" disabled="disabled" name="btnSelected"></input></label><br>';
- content += '<input value="查询" type="button" name="btnSearch" ></input><br>';
- content += '<span style="width:100%; font-size:12px;cursor:pointer" /><br>';
- content += '<div name="gridlist" style="width:' + w + 'px;height:' + h + 'px; margin-top:4px;" class="unselectable"></div>'
- var rowHeight = null;
- var tabRowCount = null;
- var containdiv = null;
- var info = null;
- var grid = null;
- var comBox = null;
- var totalCount = {};
- var tabfilter = null;
- var tagfilter = null;
- var descfilter = null;
- var dia = dialog({
- title: '添加新点',
- quickClose: true,
- content: content,
- onshow: function () {
- containdiv = $('div[name=gridlist]', this.__popup)[0];
- var skin = "dhx_web";
- grid = new dhtmlXGridObject(containdiv);
- grid.setImagePath("htm/codebase/dhtmlxGrid/codebase/imgs/");
- grid.setHeader("选择,序号,Id,点名称,描述,单位,数据类型");
- grid.setColumnsVisibility("false,false,true,false,false,false,false");
- grid.setInitWidths("50,50,45,230,300,60,60");
- grid.setColAlign("center,right,right,left,left,left,left");
- grid.setColTypes("ch,ro,ro,ro,ro,ro,ro");
- grid.setColSorting("na,na,na,na,na,na,na");
- grid.setSkin(skin);
- grid.enableColumnMove(true);
- grid.attachEvent("onScroll", function (sLeft, sTop) {
- var rowCount = grid.getRowsNum();
- if (rowCount == 0) {
- console.log("return");
- return;
- }
- if (tabRowCount == null) {
- rowHeight = $('tr.ev_' + skin, containdiv).height();
- var tabH = $('div.objbox', containdiv).height();
- tabRowCount = Math.ceil(tabH / rowHeight)
- }
- if (rowHeight != null && tabRowCount) {
- var ind = Math.floor(sTop / rowHeight);
- ind += tabRowCount;
- if (ind + 1 >= rowCount && rowCount < totalCount.Num) {
- var count = totalCount.Num - rowCount;
- if (count > 200)
- count = 200;
- var pid = rowCount;
- for (var i = 0; i < count; i++) {
- grid.addRow("p_" + pid, [false, pid + 1]);
- pid++;
- }
- rtChart._loadPoints(dia, grid, info, rowCount, count, tabfilter, tagfilter, totalCount);
- }
- }
- });
- var button = $("input[name=btnSelected]", this.__popup);
- button.click(function () {
- var idsstr = grid.getCheckedRows(0);
- if (idsstr != null) {
- var ids = idsstr.split(',');
- if (ids && ids.length && ids[0] != "") {
- for (var i = 0; i < ids.length; i++) {
- var rowId = parseInt(ids[i]);
- var cell = grid.cells(rowId, 3);
- if (cell)
- var itemDef = new GoldenRtWeb.RtItemDefine(0, 0, 0);
- rtChart.AddPen({
- URI: cell.getValue(),
- itemDef: itemDef
- });
- rtChart.requestHisData({
- URI: cell.getValue(),
- itemDef: itemDef
- }, 100);
- }
- }
- }
- dia.close().remove();
- dia = null;
- })
- grid.attachEvent("onCheck", function (rId, cInd, state) {
- var idsstr = grid.getCheckedRows(0);
- if (idsstr == null)
- button.attr("disabled", "disabled");
- else {
- var ids = idsstr.split(',');
- if (ids && ids.length && ids[0] != "")
- button.removeAttr("disabled");
- else
- button.attr("disabled", "disabled");
- }
- });
- grid.init();
- info = $("span", this.__popup);
- comBox = new dhtmlXCombo($("div[name=tabfileter]", this.__popup).get(0), "combo", 170);
-
-
- if (rtChart.options.perfectGroup) {
- comBox.setComboText(rtChart.options.perfectGroup);
- if (rtChart.options.perfectGroup == "所有(*)")
- tabfilter = "*";
- else
- tabfilter = rtChart.options.perfectGroup;
- } else {
-
- tabfilter = "*";
- }
- comBox.attachEvent("onChange", function () {
- var val = comBox.getComboText();
- rtChart.options.perfectGroup = val;
- if (val == "所有(*)")
- val = "*";
- if (val != tabfilter) {
- tabfilter = val;
-
-
-
- }
- });
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- rtChart._loadTableNames(comBox);
- tabfilter = comBox.getComboText();
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- var sbtn = $("input[name=btnSearch]", this.__popup);
- sbtn.click(function () {
-
- var tagval = $("input[name=tagfileter]", this.parentElement).val();
- if (tagval != tagfilter) {
- tagfilter = tagval;
- }
-
- var descval = $("input[name=descfileter]", this.parentElement).val();
- if (descval != descfilter) {
- descfilter = descval;
- }
- rtChart._loadPoints(dia, grid, info, 0, 100, tabfilter, tagfilter, totalCount, descfilter);
- });
- },
- onremove: function () {
- info = null;
- containdiv = null;
- if (grid) {
- grid.destructor();
- grid = null;
- }
- if (comBox) {
- comBox.unload();
- delete comBox;
- }
- rtChart = null;
- }
- });
- dia.show($('.dhx_toolbar_btn', this.element)[0]);
- },
- _onSaveGroup: function () {
- var rtChart = this;
- var w = 330;
- var h = 130;
- if (w > this.canvas.width() - 60)
- w = this.canvas.width() - 60;
- if (h > this.canvas.height() - 110)
- h = this.canvas.height() - 110;
- var content = '<label style="line-height:30px;">请输入组名称:<input type="text" name="groupName" ></input><br>';
- content += '<input value="确定" type="button" name="btnSaveGroup" style="float:right"></input>';
- var dia = dialog({
- x: 200,
- y: 200,
- title: '设置组名',
- quickClose: true,
- content: content,
- onshow: function () {
- var sbtn = $("input[name=btnSaveGroup]", this.__popup);
- sbtn.click(function () {
- var gName = $("input[name=groupName]", this.parentElement).val();
- if (gName == "") {
- alert("请输入组名称");
- } else {
- }
- });
- },
- onremove: function () {
- info = null;
- containdiv = null;
- if (grid) {
- grid.destructor();
- grid = null;
- }
- if (comBox) {
- comBox.unload();
- delete comBox;
- }
- rtChart = null;
- }
- });
- dia.show($('.dhx_toolbar_btn', this.element)[0]);
- },
- _onEditorPointGroup: function () {
- if (!this.pointGroups) {
- var d = dialog({
- content: "当前没有可用的点组,可以尝试保存点组,<br>从而创建新的点组。",
- quickClose: true
- });
- return;
- }
- var rtChart = this;
- var content = '<input name="save" type="button" value="提交" type="button" style="float:right;"/><input name="delete" type="button" value="删除" type="button" style="float:right;margin-right:8px;" disabled="disabled" /><br><div name="gridlist" style="width:240px;min-height:200px; margin-top:6px;" class="unselectable"></div><span name="info" style="width:280px; font-size:12px;cursor:pointer;color:grb(200,200,200)">可以拖动表格以改变点组的列表顺序</span>'
- var grid = null;
- var dia = dialog({
- title: '编辑点组',
- quickClose: true,
- content: content,
- onshow: function () {
- var containdiv = $('div[name=gridlist]', this.__popup)[0];
- var info = $('span[name=info]', this.__popup);
- grid = new dhtmlXGridObject(containdiv);
- grid.setImagePath("htm/codebase/dhtmlxGrid/codebase/imgs/");
- grid.setHeader("删除,名称,缺省");
- grid.setInitWidths("50,130,60");
- grid.setColAlign("center,left,center");
- grid.setColTypes("ch,ed,ch");
- grid.setColSorting("na,na,na");
- grid.setSkin("dhx_web");
- grid.enableDragAndDrop(true);
- var commitButton = $("input[name=save]", this.__popup);
- commitButton.click(function () {
- var groups = [];
- var i = 0;
- var ids = grid.getAllRowIds();
- if (ids) {
- ids = ids.split(",");
- if (ids && ids.length && ids[0] != "") {
- for (var i = 0; i < ids.length; i++) {
- var rid = ids[i];
- var set = {
- Id: rid,
- name: grid.cells(rid, 1).getValue(),
- default_: grid.cells(rid, 2).isChecked(),
- seq: i
- };
- groups.push(set);
- }
- }
- }
- rtChart._submitPointGroup(dia, groups, info);
- });
- var delteButton = $("input[name=delete]", this.__popup);
- delteButton.click(function () {
- var idsstr = grid.getCheckedRows(0);
- var ids = idsstr.split(',');
- if (ids && ids.length && ids[0] != "") {
- for (var i = 0; i < ids.length; i++)
- grid.deleteRow(ids[i]);
- }
- });
- grid.attachEvent("onCheck", function (rId, cInd, state) {
- if (cInd == 0) {
- var idsstr = grid.getCheckedRows(0);
- if (idsstr == null)
- delteButton.attr("disabled", "disabled");
- else {
- var ids = idsstr.split(',');
- if (ids && ids.length && ids[0] != "")
- delteButton.removeAttr("disabled");
- else
- delteButton.attr("disabled", "disabled");
- }
- } else if (cInd == 2 && state) {
- var ids = grid.getCheckedRows(2);
- ids = ids.split(',');
- for (var i = 0; i < ids.length; i++) {
- if (ids[i] != rId)
- grid.cells(ids[i], 2).setValue(false);
- }
- }
- });
- grid.init();
- for (var i in rtChart.pointGroups) {
- var pg = rtChart.pointGroups[i];
- grid.addRow(pg.Id, [false, pg.name, pg.bDefault]);
- }
- },
- onremove: function () {
- if (grid) {
- grid.destructor();
- grid = null;
- }
- rtChart = null;
- }
- });
- dia.show($('.dhx_toolbar_btn', this.element)[4]);
- },
- _onSetColors: function (clrName) {
- if (!clrName) {
- var rtChart = this;
- var d = dialog({
- title: '设置颜色',
- quickClose: true,
- content: '<form action="" method="get">什么颜色?<br /><label><input name="setColor" type="radio" value="bkColor" />背景色</label><label><input name="setColor" type="radio" value="gridColor" />格线色</label><label><input name="setColor" type="radio" value="indColor" />指示线颜色</label><label><input name="setColor" type="radio" value="bordrColor" />边框色</label><label><input name="setColor" type="radio" value="timeLabelColor" />时间标签颜色</label></form>',
- onshow: function () {
- $('input[type=radio]', this.__popup).change(function () {
- rtChart._onSetColors($(this).val());
- rtChart = null;
- d.close().remove();
- d = null;
- });
- }
- });
- d.show($('.dhx_toolbar_btn', this.element)[2]);
- return;
- } else {
- var clrLabel;
- var clr;
- switch (clrName) {
- case 'bkColor':
- clrLabel = '背景色';
- clr = this.canvas.css('background-color');
- break;
- case 'gridColor':
- clrLabel = '格线色';
- clr = this.options.gridColor;
- break;
- case 'indColor':
- clrLabel = '指示线颜色';
- clr = this.options.indicatorColor;
- break;
- case 'bordrColor':
- clrLabel = '边框色';
- clr = this.options.borderColor;
- break;
- case 'timeLabelColor':
- clrLabel = '时间标签颜色';
- clr = this.options.timeLabelColor;
- break;
- default:
- return;
- }
- if (this.btipShow) {
- if (this.artTooltip)
- this.artTooltip.close().remove();
- }
- if (!this.colorPicker)
- this._buildColorPicker();
- var colorpicker = this.colorPicker;
- if (colorpicker.prevColor != null) {
- $('.colorpicker-prev', colorpicker).show();
- $('.colorpicker-prevbk', colorpicker).css('background-color', colorpicker.prevColor);
- $('.colorpicker-prev', colorpicker).bind("click", function () {
- if (colorpicker) {
- $('.colorpicker-ind', colorpicker).colorpicker('setValue', colorpicker.prevColor);
- }
- });
- } else
- $('.colorpicker-prev', colorpicker).hide();
- colorpicker.resumeColor = clr;
- var rtchart = this;
- $('.colorpicker-resume', colorpicker).bind("click", function () {
- if (colorpicker) {
- $('.colorpicker-ind', colorpicker).colorpicker('setValue', colorpicker.resumeColor);
- }
- });
- $('.colorpicker-label', colorpicker).text("设置 " + clrLabel);
- colorpicker.show()
- .position({
- my: "left+10 top+20",
- of: $('.dhx_toolbar_btn', this.element)[0],
- collision: "fit"
- });
- $('.colorpicker-resumebk', colorpicker).css('background-color', clr);
- $('.colorpicker-ind', colorpicker)
- .colorpicker('setValue', clr)
- .colorpicker('show')
- .off()
- .on('changeColor.colorpicker', function (event) {
- rtchart.setColors(clrName, event.color.toString());
- })
- .on('hidePicker.colorpicker', function (event) {
- if (colorpicker) {
- colorpicker.prevColor = $(this).data('colorpicker').color.toString();
- colorpicker.hide();
- $('.colorpicker-ind', colorpicker).off();
- $('.colorpicker-resume', colorpicker).unbind();
- $('.colorpicker-prev', colorpicker).unbind();
- colorpicker = null;
- }
- if (rtchart)
- rtchart = null;
- });
- }
- },
- setPointGroupName: function (gName, bDefault) {
- if (gName != null)
- window.document.title = gName;
- this.bDeafultGroup = bDefault;
- this.options.pointGroupName = gName;
- },
- loadConfig: function (groupName, config) {
- if (config == null)
- return;
- this.setPointGroupName(groupName, (config.bDefault != null ? config.bDefault : false));
- var pensConfig = null;
- var bRtRefresh = false;
- var bShowAxis = false;
- if (config.spanSec != null)
- this.setTimeSpan(parseInt(config.spanSec), true);
- if (config.bkColor != null)
- this.options.bkColor = config.bkColor;
- if (config.showAxis != null)
- bShowAxis = config.showAxis;
- if (config.rtRefresh != null)
- bRtRefresh = config.rtRefresh;
- if (config.listExpand != null)
- this.options.listExpand = config.listExpand;
- if (config.perfectGroup != null)
- this.options.listExpand = config.perfectGroup;
- if (config.indicatorColor != null)
- this.options.indicatorColor = config.indicatorColor;
- if (config.timeLabelColor != null)
- this.options.timeLabelColor = config.timeLabelColor;
- if (config.panShow != null)
- this.options.panShow = config.panShow;
- if (config.listHeight != null)
- this.options.listHeight = parseInt(config.listHeight);
- if (config.showGrid != null)
- this.options.showGrid = config.showGrid;
- if (config.borderColor != null)
- this.options.borderColor = config.borderColor;
- if (config.timeLabelColor != null)
- this.options.timeLabelColor = config.timeLabelColor;
- if (config.gridColor != null)
- this.options.gridColor = config.gridColor;
- if (config.tooltipDelay != null)
- this.options.tooltipDelay = config.tooltipDelay;
- if (config.panWidth != null)
- this.options.panWidth = config.panWidth;
- if (config.showThumbs != null)
- this.options.showThumbs = config.showThumbs;
- if (config.showList != null)
- this.options.showList = config.showList;
- if (config.trendPens != null) {
- if (pensConfig == null)
- pensConfig = [];
- for (var i = 0; i < config.trendPens.length; i++) {
- var penOption = {};
- pensConfig.push(penOption);
- var pen = config.trendPens[i];
- if (pen.URI != null)
- penOption.URI = pen.URI;
- if (pen.linkReTryTime != null)
- penOption.linkReTryTime = pen.linkReTryTime;
- if (pen.penColor != null)
- penOption.penColor = pen.penColor;
- if (pen.Num != null)
- penOption.Num = pen.Num;
- if (pen.drawLine != null)
- penOption.drawLine = pen.drawLine;
- if (pen.stepLine != null)
- penOption.stepLine = pen.stepLine;
- if (pen.drawTag != null)
- penOption.drawTag = pen.drawTag;
- if (pen.interpolate != null)
- penOption.interpolate = pen.interpolate;
- if (pen.hisReTryTime != null)
- penOption.hisReTryTime = pen.hisReTryTime;
- if (pen.lockRange != null)
- penOption.lockRange = pen.lockRange;
- if (pen.penWidth != null)
- penOption.penWidth = pen.penWidth;
- if (pen.rageMax != null)
- penOption.rageMax = pen.rageMax;
- if (pen.rageMin != null)
- penOption.rageMin = pen.rageMin;
- }
- }
- if (this.trendPens) {
- var pens = [];
- for (var i = 0; i < this.trendPens.length; i++)
- pens.push(this.trendPens[i]);
- for (var i = 0; i < pens.length; i++)
- this.removePen(pens[i]);
- }
- if (this.listGrid)
- this.listGrid.clearAll();
- this.trendPens = [];
- if (pensConfig) {
- for (var i = 0; i < pensConfig.length; i++)
- this.trendPens.push(new TrendPen(this, pensConfig[i]));
- }
- for (var i = 0; i < this.trendPens.length; i++) {
- var pen = this.trendPens[i];
- if (pen.options.commAxis) {
- for (var j = 0; j < pen.options.commAxis.length; j++) {
- var uri = pen.options.commAxis[j];
- for (var k = 0; k < this.trendPens.length; k++) {
- var commpen = this.trendPens[k];
- if (commpen.getURI() == uri) {
- if (pen.commAxis == null)
- pen.commAxis = [];
- pen.commAxis.push(commpen);
- }
- }
- }
- }
- this._linkData(pen);
- }
- this._resetTumbs();
- this._bulidCanvas();
- this.setRtrefresh(bRtRefresh);
- this.setShowAxis(bShowAxis);
- if (this.toolBar)
- this.toolBar.setItemText("timeSpan", this.getTimeSpanString());
- },
- _onSaveConfig: function () {
- var rtChart = this;
- var d = dialog({
- title: '保存设置',
- quickClose: true,
- content: '<form action="" method="get" style="line-height:26px;">点组名称: <input name="groupName" required="true" autofocus style="padding-left:2px;width:160px;line-height:22px;" type="text" placeholder="输入点组名称" title="改变名称将创建新的点组"/><br><Label title="缺省点组可以未指定点组名称的情况下,在趋势页面中打开,\n一个账号只能有一个缺省点组。"><input type="checkbox" ' + (this.bDeafultGroup ? 'checked="checked"' : '') + '></input>缺省点组</Label></form>',
- onshow: function () {
- $('input[name=groupName]', this.__popup).val(rtChart.options.pointGroupName == null ? "" : rtChart.options.pointGroupName);
- $('form', this.__popup).keydown(this, function (e) {
- switch (e.which) {
- case 13:
- d.ok();
- break;
- case 27:
- d.close().remove();
- d = null;
- rtChart = null;
- break;
- }
- });
- },
- okValue: '确定',
- ok: function () {
-
-
- var gName = $('input[name=groupName]', this.__popup).val();
- var bDefault = $('input[type=checkbox]', this.__popup)[0].checked;
- if (gName == null || gName.length == 0) {
- var pd = dialog({
- quickClose: true,
- content: "点组名称不能为空"
- });
- pd.show();
- window.setTimeout(function () {
- pd.close().remove();
- }, 2000);
- $('input[name=groupName]', this.__popup).focus();
- return false;
- }
- rtChart.setPointGroupName(gName, bDefault);
- rtChart.saveConfig(bDefault);
- d.close().remove();
- d = null;
- rtChart = null;
- }
- });
- d.show($('.dhx_toolbar_btn', this.element)[3]);
- },
- saveConfig: function (bDefault) {
- if (this.options.pointGroupName == null || this.options.pointGroupName.length == 0) {
- var pd = dialog({
- quickClose: true,
- content: "点组名称不能为空"
- });
- pd.show();
- window.setTimeout(function () {
- pd.close().remove();
- }, 2000);
- return;
- }
- var config = {};
- config.name = this.options.pointGroupName;
- config.spanSec = this.options.spanSec;
- config.bkColor = this.options.bkColor;
- config.showAxis = this.options.showAxis;
- config.rtRefresh = this.options.rtRefresh;
- config.listExpand = this.options.listExpand;
- if (this.options.perfectGroup) {
- config.perfectGroup = this.options.perfectGroup;
- }
- config.indicatorColor = this.options.indicatorColor;
- config.timeLabelColor = this.options.timeLabelColor;
- config.spanSec = this.options.spanSec;
- config.panShow = this.options.panShow;
- config.listHeight = this.options.listHeight;
- config.showGrid = this.options.showGrid;
- config.borderColor = this.options.borderColor;
- config.timeLabelColor = this.options.timeLabelColor;
- config.gridColor = this.options.gridColor;
- config.tooltipDelay = this.options.tooltipDelay;
- config.panWidth = this.options.panWidth;
- config.showThumbs = this.options.showThumbs;
- config.showList = this.options.showList;
- config.freeRange = this.options.freeRange;
- config.bDefault = (bDefault ? true : false);
- if (this.trendPens) {
- var len = this.trendPens.length;
- config.trendPens = [];
- for (var i = 0; i < len; i++) {
- var pen = this.trendPens[i];
- config.trendPens.push(pen.getConfig());
- }
- } else {
- alert("请添加测点");
- return;
- }
- var configs = localStorage.getItem("goldenTrendConfig");
- if (configs) {
- try {
- configs = JSON.parse(configs);
- } catch (ex) {
- localStorage.removeItem("goldenTrendConfig");
- configs = null;
- }
- }
- if (configs) {
- if (config.bDefault) {
- for (var i in configs) {
- var setconfig = configs[i];
- setconfig.bDeafult = false;
- }
- }
- } else {
- configs = {};
- }
- configs[this.options.pointGroupName] = config;
- var id = 0;
- for (var i in configs) {
- var setconfig = configs[i];
- setconfig.Id = id++;
- }
- localStorage.setItem("goldenTrendConfig", JSON.stringify(configs));
- var d = dialog({
- content: "点组设置保存已成功!",
- quickClose: true
- });
- d.show();
- window.setTimeout(function () {
- d.close().remove();
- d = null;
- }, 2000);
- this._loadPointGroupNames();
- },
- _loadPointGroupNames: function () {
- var dia = null;
- if (this.initDialogShow !== true) {
- this.initDialogShow = true;
- }
- if (typeof localStorage == "undefined") {
- return;
- }
- var pointGroups = localStorage.getItem("goldenTrendConfig");
- if (pointGroups) {
- try {
- pointGroups = JSON.parse(pointGroups);
- } catch (ex) {
- localStorage.removeItem("goldenTrendConfig");
- pointGroups = null;
- }
- }
- this._onPointGroupNamesLoaded(pointGroups);
- },
- _onPointGroupNamesLoaded: function (pointGroups) {
- if (!this.toolBar || !pointGroups)
- return;
- this.pointGroups = pointGroups;
- var opts =
- [
- ['newPiointGroup', 'obj', '新建点组', 'window_new.png'],
- ['editorPointGroup', 'obj', '编辑点组...', 'tag_blue_edit.png'],
- ['refreshPointGroup', 'obj', '刷新点组列表', 'reload.png'],
- ['idsep', 'sep']
- ];
- this.toolBar.removeItem("pointGroup");
- for (var n in this.pointGroups) {
- var pg = this.pointGroups[n];
- if (!this.isNewPage && pg.bDefault === true && this.options.pointGroupName == null) {
- this.options.pointGroupName = n;
- this._loadPointGroup();
- }
- var opt = [pg.Id, 'obj', n, 'tags.png'];
- opts.push(opt);
- }
- this.toolBar.addButtonSelect("pointGroup", 4, "点组", opts, "tag.png");
- },
- _onSetTimeSpan: function (e) {
- var rtChart = this;
- var d = dialog({
- title: '设置时间跨度',
- quickClose: true,
- content: '<form action="" method="get" style="line-height:26px;">时间跨度: <input name="timespan" min="1" max="10000" value="10" required="true" autofocus style="padding-left:2px;width:96px;" type="number"><br>时间单位:<label><input name="setTime" type="radio" value="s" />秒</label><label><input name="setTime" type="radio" value="m" checked="checked" />分</label><label><input name="setTime" type="radio" value="h" />时</label><form>',
- onshow: function () {
- $('form', this.__popup).keydown(this, function (e) {
- switch (e.which) {
- case 13:
- d.ok();
- break;
- case 27:
- d.close().remove();
- d = null;
- rtChart = null;
- break;
- }
- });
- },
- okValue: '确定',
- ok: function () {
- var span = $('input[ name="timespan"]', d.__popup).val();
- span = parseInt(span, 10);
- if (!span || isNaN(span) || span < 1)
- span = 1;
- switch ($('input:radio:checked', this.__popup).val()) {
- case 'm':
- span *= 60;
- break;
- case 'h':
- span *= 3600;
- break;
- }
- d.close().remove();
- d = null;
- if (!rtChart.getHisRefreshing()) {
- d = dialog({
- title: '固定哪个时间?',
- quickClose: true,
- content: '<form action="" method="get" ><label><input name="setTime" type="radio" autofocus value="fixBeg" />查询起始时间不变</label><label><input name="setTime" type="radio" value="fixEnd" />查询截至时间不变</label><form>',
- onshow: function () {
- $('input[type=radio]', this.__popup).change(function () {
- var fixEnd = false;
- if ($(this).val() == 'fixEnd')
- fixEnd = true;
- d.close().remove();
- d = null;
- rtChart.setTimeSpan(span, fixEnd);
- rtChart = null;
- });
- }
- });
- d.show(e);
- } else {
- rtChart.setTimeSpan(span);
- rtChart = null;
- }
- }
- });
- e.pageX += 10;
- e.pageY -= 30;
- d.show(e);
- },
- _toggleZoom: function () {
- this.zooming = this.zooming ? false : true;
- if (this.zooming)
- this.canvas.addClass('zoomcur');
- else
- this.canvas.removeClass('zoomcur');
- },
- _updateReZoom: function () {
- if (this.zoomStack && this.zoomStack.length)
- this.toolBar.enableItem("zoomResume");
- else
- this.toolBar.disableItem("zoomResume");
- },
- _onReZoom: function () {
- if (this.zoomStack && this.zoomStack.length) {
- var zoomItem = this.zoomStack.pop();
- this._updateReZoom();
- if (zoomItem.pens) {
- for (var i in zoomItem.pens) {
- var zoomPen = zoomItem.pens[i];
- }
- }
- this.setBegTimeAndSpan(zoomItem.begTime, zoomItem.spanTime);
- }
- },
- RegistRtPt: function (pen, rtDef, callback, opt) {
- var url = pen.getWebURL().toLowerCase();
- var webLink = this.webLinks[url];
- if (webLink) {
- return webLink.RegistRtPt(rtDef, pen, callback, opt);
- } else
- return null;
- },
- UnRegistRtPt: function (pen, rtRefreshKey) {
- if (!this.webLinks)
- return;
- var url = pen.getWebURL().toLowerCase();
- var webLink = this.webLinks[url];
- if (webLink)
- webLink.UnRegistRtPt(pen, rtRefreshKey);
- },
- requestHisData: function (pen, delay) {
- var url = GoldenRtWeb.getWebURL();
- var webLink = this.webLinks[url];
- if (webLink)
- return webLink.requestHisData(delay);
- else
- return false;
- },
- DateToFileTime: function (date) {
- var epoch_diff = 116444736000000000;
- var rate_diff = 10000;
- var ut = date.getTime();
- var ft = ut * rate_diff + epoch_diff;
- return ft;
- },
- FileTimeToDate: function (fTime) {
- var epoch_diff = 116444736000000000;
- var rate_diff = 10000;
- var ut = (fTime - epoch_diff) / rate_diff;
- return new Date(ut);
- },
- FileTimeToDateString: function (fTime) {
- if (isNaN(fTime) || fTime == 0)
- return "";
- var date = this.FileTimeToDate(fTime);
- var dstr = date.getFullYear().toString();
- dstr += "-";
- if (date.getMonth() + 1 < 10)
- dstr += "0" + (date.getMonth() + 1).toString();
- else
- dstr += (date.getMonth() + 1).toString();
- dstr += "-";
- if (date.getDate() < 10)
- dstr += "0" + date.getDate();
- else
- dstr += date.getDate();
- return dstr;
- },
- FileTimeToTimeString: function (fTime, ms) {
- if (isNaN(fTime) || fTime == 0)
- return "";
- var date = this.FileTimeToDate(fTime);
- var time;
- if (date.getHours() < 10)
- time = "0" + date.getHours();
- else
- time = date.getHours().toString();
- time += ":";
- if (date.getMinutes() < 10)
- time += "0" + date.getMinutes().toString();
- else
- time += date.getMinutes();
- time += ":";
- if (date.getSeconds() < 10)
- time += "0" + date.getSeconds().toString();
- else
- time += date.getSeconds();
- if (ms === true) {
- time += ".";
- if (date.getMilliseconds() < 10)
- time += "00" + date.getMilliseconds().toString();
- else if (date.milliseconds < 100)
- time += "0" + date.getMilliseconds().toString();
- else
- time += date.getMilliseconds().toString();
- }
- return time;
- }
- });
- WebLink.prototype = {
- addPen: function (pen) {
- if (!this.Pens)
- this.Pens = [];
- this.Pens.push(pen);
- this.startLink();
- },
- destroy: function () {
- if (this.hisTimer) {
- window.clearTimeout(this.hisTimer);
- this.hisTimer = null;
- }
- if (this.linkTimer) {
- window.clearTimeout(this.linkTimer);
- this.linkTimer = null;
- }
- if (this.rtRefresher) {
- this.rtRefresher.clear();
- delete this.rtRefresher;
- }
- if (this.Pens)
- delete this.Pens;
- },
- startLink: function (delay) {
- if (this.linkTimer) {
- window.clearTimeout(this.linkTimer);
- this.linkTimer = null;
- }
- var self = this;
- this.linkTimer = window.setTimeout(function () {
- window.clearTimeout(self.linkTimer);
- self.linkTimer = null;
- self._beginLink();
- self = null;
- }, delay || 10);
- },
- _beginLink: function () {
- if (!this.Pens || !this.Pens.length)
- return;
- var self = this;
- for (var i in this.Pens) {
- var pen = this.Pens[i];
- if (pen.isLinkRq()) {
- self._addpenClosure(pen);
- }
- pen.setLinkStatus("linking", "正在连接...");
- }
- },
- _addpenClosure: function (pen) {
- var str = "http://" + webServiceIP + ":" + webServicePort + "/api/Point?tagName=" + encodeURIComponent(pen.getURI());
- $.ajax({
- url: str,
- type: 'GET',
- dataType: 'json',
- cache: false,
- success: function (data) {
- if (data)
- pen.onLinkTab(data);
- }
- });
- },
- RegistRtPt: function (rtDef, scope, callback, opt) {
- if (!this.rtRefresher)
- this.rtRefresher = new GoldenRtWeb.RtRefresher(this.weburl);
- return this.rtRefresher.RegistRtPt(rtDef, scope, callback, opt);
- },
- UnRegistRtPt: function (pen, rtRefreshKey) {
- if (this.rtRefresher)
- this.rtRefresher.UnRegistRtPt(rtRefreshKey);
- if (this.Pens) {
- for (i in this.Pens) {
- if (this.Pens[i] == pen) {
- this.Pens.splice(i, 1);
- break;
- }
- }
- }
- },
- requestHisData: function (delay) {
- if (this.hisTimer) {
- window.clearTimeout(this.hisTimer);
- this.hisTimer = null;
- }
- var self = this;
- this.hisTimer = window.setTimeout(function () {
- window.clearTimeout(self.hisTimer);
- self.hisTimer = null;
- self._pullHisData();
- self = null;
- }, delay || 10);
- return true;
- },
- _pullHisData: function () {
- if (!this.Pens || !this.Pens.length)
- return;
- var reqInfoset = null;
- var tagName = [];
- var metaId = "";
- var beginTime = "";
- var endTime = "";
- var tabs = [];
- for (i in this.Pens) {
- var pen = this.Pens[i];
- if (pen.isHisRq()) {
- var tab = pen.getHisRequestTab();
- tab.reqHisPen = pen;
- tab.clientHandle = i;
- pen.setHisStatus("getting", "正在获取历史数据...");
- tabs.push(tab);
- tab.reqHisPen = pen;
- tab.clientHandle = i;
- if (beginTime == "") {
- if (pen.options.itemDef.beginTime != null) {
- beginTime = pen.options.itemDef.beginTime;
- } else {
- beginTime = 0;
- }
- }
- if (endTime == "") {
- if (pen.options.itemDef.endTime != null) {
- endTime = pen.options.itemDef.endTime;
- } else {
- endTime = 0;
- }
- }
- var item = encodeURIComponent(pen.options.URI);;
- item += "&beginTime=" + beginTime + "&endTime=" + endTime + "&interval=1000";
- tagName.push(item);
- }
- }
- if (tagName.length > 0) {
- for (var i = 0; i < tagName.length; i++) {
- {
- var str = "http://" + webServiceIP + ":" + webServicePort + "/api/HistoryPlot?tagNames=" + tagName[i];
- var self = this;
- var tab = tabs[i];
- $.ajax({
- url: str,
- type: 'GET',
- dataType: 'json',
- cache: false,
- complete: function (xhr, ts) {
- if (xhr.tab) {
- var data = xhr.responseJSON;
- if (typeof (data) == "undefined") return;
- if (data.length > 0)
- self._onHisEnd(xhr.tab, data);
- delete xhr.tab;
- }
- }
- }).tab = tab;
- }
- }
- } else
- this._onHisEnd();
- },
- _onHisEnd: function (tab, data) {
- if (tab && data && data.length > 0) {
- if (tab.reqHisPen) {
- tab.hisData = data[0];
- tab.reqHisPen.onHisTab(tab);
- tab.reqHisPen = null;
- }
- }
- if (!this.Pens || !this.Pens.length)
- return;
- this.requestHisData(3000);
- }
- };
- TrendPen.prototype = {
- destroy: function () {
- if (this.linkingTime) {
- window.clearTimeout(this.linkingTime);
- this.linkingTime = null;
- }
- if (this.hisingTime) {
- window.clearTimeout(this.hisingTime);
- this.hisingTime = null;
- }
- if (this.rtRefreshKey) {
- this.rtChart.UnRegistRtPt(this, this.rtRefreshKey);
- this.rtRefreshKey = null;
- }
- var oldComm = this.commAxis;
- this.commAxis = null;
- if (oldComm) {
- for (var i = 0; i < oldComm.length; i++)
- oldComm[i].removeCommAxis(this);
- }
- this.rtChart = null;
- },
- hisDatRemove: function (array, from, to) {
- var rest = array.slice((to || from) + 1 || array.length);
- array.length = from < 0 ? array.length + from : from;
- return array.push.apply(array, rest);
- },
- updateRangeList: function () {
- if (this.rageMax != null && this.rageMin != null) {
- this.setGridSelf = true;
- this.rtChart._updateList(this.rowId, "量程下限", this.rageMin.toFixed(this.options.Num));
- this.rtChart._updateList(this.rowId, "量程上限", this.rageMax.toFixed(this.options.Num));
- this.setGridSelf = false;
- } else {
- this.setGridSelf = true;
- this.rtChart._updateList(this.rowId, "量程下限", null);
- this.rtChart._updateList(this.rowId, "量程上限", null);
- this.setGridSelf = false;
- }
- },
- setDataReader: function () {
- if (this.rtChart == null)
- return;
- var ft = this.rtChart.getReaderTimer();
- var vqt = null;
- var prev = null;
- var next = null;
- if (this.hisData) {
- var len = this.hisData.length;
- for (var i = 0; i < len; i++) {
- var findVQT = this.hisData[i];
- if (findVQT.StampTime == ft) {
- vqt = findVQT;
- break;
- } else if (findVQT.StampTime > ft) {
- if (prev) {
- vqt = prev;
- next = findVQT;
- } else
- vqt = findVQT;
- break;
- } else
- prev = findVQT;
- }
- }
- if (vqt) {
- if (vqt.Value != null) {
- if (next && next.StampTime > vqt.StampTime && next.Value != null) {
- var val;
- if (this.isString(vqt))
- val = vqt.Value ? vqt.Value : "";
- else if (this.isBoolen(vqt)) {
- if (vqt.Value)
- val = "1";
- else
- val = "0";
- } else {
- val = vqt.Value + (next.Value - vqt.Value) * (ft - vqt.StampTime) / (next.StampTime - vqt.StampTime);
- val = val.toFixed(this.options.Num);
- }
- if (this.unit)
- val += " " + this.unit;
- var time = this.rtChart.FileTimeToDateString(ft) + " " + this.rtChart.FileTimeToTimeString(ft);
- this.rtChart._updateList(this.rowId, "数据时间", time);
- this.rtChart._updateList(this.rowId, "数据值", val);
- } else {
- var time = this.getFullStampTimeStr(vqt);
- var val;
- if (this.isString(vqt))
- val = vqt.Value ? vqt.Vvalue : "";
- else if (this.isBoolen(vqt)) {
- if (vqt.Value)
- val = "1";
- else
- val = "0";
- } else
- val = (this.isFloat(vqt) ? vqt.Value.toFixed(this.options.Num) : vqt.Value);
- if (this.unit)
- val += " " + this.unit;
- this.rtChart._updateList(this.rowId, "数据时间", time);
- this.rtChart._updateList(this.rowId, "数据值", val);
- }
- }
- } else {
- var time = this.rtChart.FileTimeToDateString(ft) + " " + this.rtChart.FileTimeToTimeString(ft);
- var val = '[!!无历史数据]';
- this.rtChart._updateList(this.rowId, "数据时间", time);
- this.rtChart._updateList(this.rowId, "数据值", val);
- }
- },
- updateDataReader: function () {
- if (this.rtChart == null)
- return;
- if (this.dataReaderTime == null) {
- var me = this;
- this.dataReaderTime = window.setTimeout(function () {
- window.clearTimeout(me.dataReaderTime);
- me.dataReaderTime = null;
- me.setDataReader();
- me = null;
- }, 100);
- }
- },
- setRangeLock: function (lock, updateList) {
- if (this.options.lockRange === lock)
- return;
- this.options.lockRange = lock;
- if (!lock) {
- var gh = this.rtChart.getGridHeight();
- }
- if (updateList !== false)
- this.rtChart._updateList(this.rowId, "量程锁定", this.options.lockRange);
- },
- onSetMinRange: function (nValue) {
- if (!this.setGridSelf) {
- var minset = parseFloat(nValue);
- if (this.rageMax > minset) {
- this.options.lockRange = true;
- this.rtChart._updateList(this.rowId, "量程锁定", this.options.lockRange);
- this.setRange(minset, this.rageMax, null);
- }
- this.updateRangeList();
- }
- },
- onSetMaxRange: function (nValue) {
- if (!this.setGridSelf) {
- var maxset = parseFloat(nValue);
- var gh = this.rtChart.getGridHeight();
- if (maxset > this.rageMin) {
- this.options.lockRange = true;
- this.rtChart._updateList(this.rowId, "量程锁定", this.options.lockRange);
- this.setRange(this.rageMin, maxset, null);
- }
- this.updateRangeList();
- }
- },
- log10: function (val) {
- return Math.log(val) / Math.LN10;
- },
- setRange: function (rageMin, rageMax, calls) {
- if (this.rageMin != rageMin || this.rageMax != rageMax) {
- this.rageMin = rageMin;
- this.rageMax = rageMax;
- if ((this.maxVqt && this.isFloat(this.maxVqt)) ||
- (this.minVqt && this.isFloat(this.minVqt))) {
- var r = Math.abs(this.rageMax - this.rageMin);
- if (r < 1) {
- var bSet = false;
- if (r > 0.1) {
- if (this.options.Num < 3) {
- this.options.Num = 3;
- bSet = true;
- }
- } else if (r > 0.01) {
- if (this.options.Num < 4) {
- this.options.Num = 4;
- bSet = true;
- }
- } else if (r > 0.001) {
- if (this.options.Num < 5) {
- this.options.Num = 5;
- bSet = true;
- }
- } else if (this.options.Num < 6) {
- this.options.Num = 6;
- bSet = true
- }
- if (bSet)
- this.updateListGrid();
- }
- }
- this.rtChart.updateDataArea();
- this.rtChart.UpdateAxisPan(true);
- this.updateRangeList();
- }
- if (this.commAxis && this.commAxis.length) {
- if (calls == null)
- calls = [];
- calls.push(this);
- for (var i = 0; i < this.commAxis.length; i++) {
- var pen = this.commAxis[i];
- var seted = false;
- for (var k in calls) {
- if (calls[k] == pen) {
- seted = true;
- break;
- }
- }
- if (!seted)
- pen.setRange(rageMin, rageMax, calls);
- }
- }
- },
- moveY: function (deltY) {
- if (this.rageMin == null || this.rageMax == null || this.rageMax == this.rageMin)
- return;
- var gh = this.rtChart.getGridHeight();
- var delt = (this.rageMax - this.rageMin) * deltY / gh;
- this.setRange(this.rageMin + delt, this.rageMax + delt);
- },
- isGood: function (vqt) {
- if (!vqt)
- return false;
- return (vqt.Qua == 0 || ((vqt.Qua & 0x100) && (vqt.Qua & 0xc0) == 0xc0));
- },
- isBad: function (vqt) {
- return !this.isGood(vqt);
- },
- isUncertain: function (vqt) {
- return false;
- },
- isFloat: function (vqt) {
- if (!vqt || !vqt.Value)
- return false;
- var num = parseFloat(vqt.Value);
- if (isNaN(num))
- return false;
- else {
- if (num.toString().indexOf(".") > 0)
- return true;
- else
- return false;
- }
- },
- GetNumber: function (vqt) {
- if (!vqt)
- return 0;
- var num = parseFloat(vqt.Value);
- if (num == null)
- return 0;
- if (!isNaN(num))
- return num;
- else if (num.toString().toLowerCase() == "true")
- return 1;
- else if (num.toString().toLowerCase() == "false")
- return 0;
- var hash = 0;
- if (!this.value || !this.value.length) return hash;
- for (i = 0; i < this.value.length; i++) {
- char = this.value.charCodeAt(i);
- hash = ((hash << 5) - hash) + char;
- hash = hash & hash;
- }
- return hash;
- },
- isBoolen: function (vqt) {
- if (!vqt)
- return false;
- else if (vqt.Value == "true" || vqt.Value == "false")
- return true;
- else
- return false;
- },
- isString: function (vqt) {
- if (!vqt)
- return false;
- else if (vqt.Value == null)
- return false;
- else if (typeof vqt.Value == 'string')
- return true;
- else
- return false;
- },
- getQuaStr: function (vqt) {
- var re = "";
- if (!vqt || vqt.Qua == null)
- return re;
- switch (vqt.Qua) {
- case 0:
- re = "正常";
- break;
- case 1:
- re = "无数据";
- break;
- case 2:
- re = "创建";
- break;
- case 3:
- re = "停机";
- break;
- case 4:
- re = "计算停止";
- break;
- case 5:
- re = "坏点";
- break;
- case 6:
- re = "被零除";
- break;
- case 7:
- re = "已被删除";
- break;
- default:
- if (this.qua & 0x0100)
- {
- switch (this.qua & 0xFC) {
- case 0x00:
- re = "坏值";
- break;
- case 0x04:
- re = "坏值(组态错误)";
- break;
- case 0x08:
- re = "坏值(没有连接)";
- break;
- case 0x0C:
- re = "坏值(设备故障)";
- break;
- case 0x10:
- re = "坏值(传感器故障)";
- break;
- case 0x14:
- re = "坏值(最后值)";
- break;
- case 0x18:
- re = "坏值(通讯故障)";
- break;
- case 0x1C:
- re = "坏值(退出服务)";
- break;
- case 0x20:
- re = "坏值(不被许可)";
- break;
- case 0x24:
- re = "坏值(超出量程)";
- break;
- case 0x2C:
- re = "坏值(未定义值)";
- break;
- case 0x28:
- re = "坏值(计算错误)";
- break;
- case 0x30:
- re = "坏值(输出开路)";
- break;
- case 0x34:
- re = "坏值(输入开路)";
- break;
- case 0x3C:
- re = "坏值(转换错误)";
- break;
- case 0x40:
- re = "坏值(可疑值)";
- break;
- case 0x44:
- re = "可疑值(最后值)";
- break;
- case 0x48:
- re = "可疑值(输出开路)";
- break;
- case 0x4C:
- re = "可疑值(等待同步)";
- break;
- case 0x50:
- re = "可疑值(传感器校正)";
- break;
- case 0x54:
- re = "可疑值(超出量程)";
- break;
- case 0x58:
- re = "可疑值(子故障)";
- break;
- case 0x5C:
- re = "可疑值(输入开路)";
- break;
- case 0x60:
- re = "可疑值(转换错误)";
- break;
- case 0xC0:
- re = "正常";
- break;
- case 0xC4:
- re = "正常(初始化)";
- break;
- case 0xC4:
- re = "正常(无状态)";
- break;
- case 0xD8:
- re = "正常(当地重载)";
- break;
- }
- } else {
- re = "用户自定义";
- }
- break;
- }
- return re;
- },
- getFullStampTimeStr: function (vqt) {
- return GoldenRtWeb.FileTimeToString(vqt.StampTime, false);
- },
- getStampTimeStr: function (vqt) {
- return GoldenRtWeb.FileTimeToString(vqt.StampTime, false);
- },
- expendY: function (deltaY) {
- if (this.rageMin == null || this.rageMax == null || this.rageMax == this.rageMin)
- return;
- var gh = this.rtChart.getGridHeight();
- var delt = (this.rageMax - this.rageMin) * deltaY / gh;
- var M = null;
- if (this.minVqt && this.isGood(this.minVqt) && this.maxVqt && this.isGood(this.maxVqt)) {
- if (this.isBoolen(this.minVqt))
- M = 0.5;
- else if (this.GetNumber(this.minVqt) != this.GetNumber(this.maxVqt))
- M = 0.5 * (this.GetNumber(this.maxVqt) - this.GetNumber(this.minVqt)) + this.GetNumber(this.minVqt);
- else
- M = 0.5 * this.GetNumber(this.maxVqt);
- } else if (this.minVqt && this.isGood(this.minVqt)) {
- if (this.isBoolen(this.minVqt))
- M = 0.5;
- else
- M = 0.5 * this.GetNumber(this.minVqt);
- } else if (this.maxVqt && this.isGood(this.maxVqt)) {
- if (this.isBoolen(this.maxVqt))
- M = 0.5;
- else
- M = 0.5 * this.GetNumber(this.maxVqt);
- } else
- return;
- var K = (M - this.rageMin) / (this.rageMax - this.rageMin);
- var max = this.rageMax + delt;
- var min = (M - K * max) / (1 - K);
- if (max <= min)
- return;
- this.setRange(min, max);
- },
- getY: function (val) {
- if (this.rageMin == null || this.rageMax == null || this.rageMin == this.rageMax)
- return null;
- var gh = this.rtChart.getGridHeight();
- var y = gh - gh * (val - this.rageMin) / (this.rageMax - this.rageMin);
- return y;
- },
- getVal: function (y) {
- if (this.rageMin == null || this.rageMax == null || this.rageMin == this.rageMax)
- return null;
- var gh = this.rtChart.getGridHeight();
- var v = this.rageMin + (gh - y) * (this.rageMax - this.rageMin) / gh;
- return v;
- },
- hasDataAtTime: function (ft, y) {
- if (this.hisData) {
- var yVal = this.getVal(y);
- if (yVal == null)
- return false;
- if (this.minVqt && this.isGood(this.minVqt) && this.GetNumber(this.minVqt) > yVal) {
- if (this.isBoolen(this.minVqt) && yVal < 0)
- return false;
- if (this.maxVqt && this.isGood(this.maxVqt) && this.GetNumber(this.maxVqt) == this.GetNumber(this.minVqt)) {
- if (this.rageMin > yVal)
- return false;
- } else
- return false;
- }
- if (this.maxVqt && this.isGood(this.maxVqt) && this.GetNumber(this.maxVqt) < yVal) {
- if (this.isBoolen(this.maxVqt) && yVal > 1)
- return false;
- else if (this.minVqt && this.isGood(this.minVqt) && this.GetNumber(this.maxVqt) == this.GetNumber(this.minVqt)) {
- if (this.rageMax < yVal)
- return false;
- } else
- return false;
- }
- var prev = null;
- var len = this.hisData.length;
- for (var i = 0; i < len; i++) {
- var vqt = this.hisData[i];
- if (vqt.StampTime == ft)
- return true;
- else if (vqt.StampTime > ft) {
- if (prev)
- return true;
- else
- return false;
- } else
- prev = vqt;
- }
- return false;
- } else
- return false;
- },
- hasDataBetweenTime: function (begTime, endTime) {
- if (this.hisData) {
- var len = this.hisData.length;
- for (var i = 0; i < len; i++) {
- var vqt = this.hisData[i];
- if (vqt.StampTime >= begTime && vqt.StampTime <= endTime)
- return true;
- }
- return false;
- } else
- return false;
- },
- getPanHeight: function () {
- var h = 55;
- if (this.vqt)
- h += SPANLINEHEIGHT;
- if (this.avg != null)
- h += SPANLINEHEIGHT;
- if (this.maxVqt)
- h += SPANLINEHEIGHT
- if (this.minVq)
- h += SPANLINEHEIGHT;
- return h;
- },
- isLinkRq: function () {
- if (this.itemDef)
- return false;
- else if (this.linkTime && (new Date() - this.linkTime < this.options.linkReTryTime))
- return false;
- else
- return true;
- },
- isLinked: function () {
- return this.itemDef != null;
- },
- getConfig: function () {
- var config = {};
- config.URI = this.getURI();
- config.linkReTryTime = this.options.linkReTryTime;
- config.penColor = this.options.penColor;
- config.Num = this.options.Num;
- config.penWidth = this.options.penWidth || 1;
- config.drawLine = this.options.drawLine;
- config.stepLine = this.options.stepLine == null ? false : this.options.stepLine;
- config.drawTag = this.options.drawTag;
- config.interpolate = this.options.interpolate == null ? false : this.options.interpolate;
- config.hisReTryTime = this.options.hisReTryTime;
- config.lockRange = this.options.lockRange;
- config.rageMax = this.rageMax;
- config.rageMin = this.rageMin;
- if (this.commAxis) {
- var axis = [];
- for (var i = 0; i < this.commAxis.length; i++) {
- var pen = this.commAxis[i];
- axis.push(pen.getURI());
- }
- config.commAxis = axis;
- }
- return config;
- },
- setDes: function (des) {
- this.des = des;
- if (this.rtChart && this.rowId)
- this.rtChart._updateList(this.rowId, "描述", this.getDes());
- },
- getDes: function () {
- return this.des;
- },
- getWebURL: function () {
- return GoldenRtWeb.getWebURL();
- },
- getURI: function () {
- return this.options.URI;
- },
- getLabel: function () {
- var uri = this.getURI();
- var i = uri.lastIndexOf(".");
- if (i > 0)
- return uri.substring(i + 1);
- else
- return uri;
- },
- getPenColor: function () {
- return this.options.penColor;
- },
- onSetLineWidth: function (nValue, fromgrid) {
- this.options.penWidth = parseInt(nValue);
- this.rtChart.updateDataArea();
- if (!fromgrid)
- this.rtChart._updateList(this.rowId, "线宽", this.options.penWidth);
- },
- setPenColor: function (rgba) {
- this.options.penColor = rgba;
- this.panPos = null;
- this.rtChart.UpdatePan(false);
- this.rtChart.updateDataArea();
- this.rtChart._updateList(this.rowId, "点名称", {
- uri: this.getURI(),
- color: this.getPenColor()
- });
- },
- drawPan: function (bredraw, ctx, t, w) {
- var bReDaw = this.activeChanged || bredraw || ((t === this.panPos) ? false : true);
- var cleared = false;
- var dt = SPANPAD;
- var h = SPANLINEHEIGHT;
- if (bReDaw) {
- this.activeChanged = false;
- this.panPos = t;
- ctx.clearRect(1, 0, w - 2, this.getPanHeight());
- cleared = true;
- ctx.translate(0.5, 0.5);
- ctx.lineWidth = 1;
- ctx.beginPath();
- ctx.strokeStyle = "rgb(30,30,30)";
- ctx.moveTo(1, 1)
- ctx.lineTo(w - 2, 1);
- ctx.stroke();
- ctx.beginPath();
- ctx.strokeStyle = "rgb(220,220,220)";
- ctx.moveTo(1, 2)
- ctx.lineTo(w - 2, 2);
- ctx.stroke();
- ctx.beginPath();
- ctx.fillStyle = this.options.penColor;
- ctx.strokeStyle = this.options.penColor;
- ctx.rect(6.5, 9.5, 8, 8);
- ctx.fill();
- ctx.textAlign = "left";
- ctx.fillText(this.getLabel(), 18, dt, w - 12);
- if (this.bActive) {
- ctx.rect(2, 3, w - 4, this.getPanHeight() - 4);
- ctx.stroke();
- }
- var r = w - 10;
- ctx.beginPath();
- ctx.moveTo(r, 6)
- ctx.lineTo(r + 6, 12);
- ctx.moveTo(r + 6, 6)
- ctx.lineTo(r, 12);
- ctx.stroke();
- }
- var img = this.rtChart.getButtonImage();
- if (img && !img.complete)
- img = null;
- var likdarwed = false;
- dt += h;
- if ((bReDaw || this.linkChanged) && this.linkStatus != null) {
- this.linkChanged = false;
- if (!cleared)
- ctx.clearRect(3, dt, w - 5, h);
- likdarwed = true;
- if (img) {
- switch (this.linkStatus) {
- case 'linking':
- ctx.drawImage(img, 22, 0, 5, 6, 8, dt, 5, 6);
- break;
- case 'linked':
- ctx.drawImage(img, 36, 0, 10, 7, 8, dt, 10, 7);
- break;
- case 'error':
- ctx.drawImage(img, 27, 0, 5, 5, 8, dt, 5, 5);
- break;
- default:
- ctx.drawImage(img, 32, 0, 4, 5, 8, dt, 4, 5);
- break;
- }
- }
- if (this.unit) {
- ctx.fillStyle = this.options.penColor;
- ctx.textAlign = "right";
- ctx.textBaseline = "top";
- ctx.fillText(this.unit, w - 2, dt, w - 50);
- }
- }
- if ((bReDaw || this.hisChanged || likdarwed) && this.hisGetStaus != null) {
- this.hisChanged = false;
- if (!likdarwed && !cleared)
- ctx.clearRect(20, dt, 10, h);
- if (img) {
- switch (this.hisGetStaus) {
- case 'getting':
- ctx.drawImage(img, 22, 0, 5, 6, 20, 23, 5, 6);
- break;
- case 'error':
- ctx.drawImage(img, 27, 0, 5, 5, 20, 23, 5, 5);
- break;
- case 'linked':
- ctx.drawImage(img, 22, 6, 8, 5, 20, 24, 8, 5);
- break;
- case "nodata":
- case "wait":
- ctx.drawImage(img, 46, 0, 10, 10, 20, 23, 10, 10);
- break;
- default:
- ctx.drawImage(img, 32, 0, 4, 5, 20, 23, 4, 5);
- break;
- }
- }
- }
- dt += h;
- if (bReDaw || this.vqtChanged) {
- this.vqtChanged = false;
- if (!cleared)
- ctx.clearRect(3, dt, w - 5, h);
- if (this.vqt) {
- ctx.fillStyle = this.options.penColor;
- ctx.textAlign = "left";
- ctx.textBaseline = "top";
- ctx.fillText("实时", 5, dt, 30);
- if (this.vqt.isBad())
- ctx.fillStyle = "rgb(200,0,0)";
- else if (this.vqt.isUncertain())
- ctx.fillStyle = "rgb(160,150,0)";
- ctx.textAlign = "right";
- if (this.vqt.value != null)
- ctx.fillText((this.vqt.isFloat() ? this.vqt.value.toFixed(this.options.Num) : this.vqt.value), w - 3, dt, w - 30);
- else if (this.vqt.isBad())
- ctx.fillText("####", w - 3, dt, w - 30);
- else if (this.vqt.isUncertain())
- ctx.fillText("????", w - 3, dt, w - 30);
- }
- }
- if (this.vqt)
- dt += h;
- if (bReDaw || this.avgChanged) {
- this.avgChanged = false;
- if (!cleared)
- ctx.clearRect(3, dt, w - 5, h);
- if (this.avg != null) {
- ctx.fillStyle = this.options.penColor;
- ctx.textAlign = "left";
- ctx.textBaseline = "top";
- ctx.fillText("平均", 5, dt, 30);
- ctx.textAlign = "right";
- ctx.fillText(this.avg.toFixed(this.options.Num), w - 3, dt, w - 30);
- }
- }
- if (this.avg != null)
- dt += h;
- if (bReDaw || this.minChanged) {
- this.minChanged = false;
- if (!cleared)
- ctx.clearRect(3, dt, w - 5, h);
- if (this.minVqt) {
- ctx.fillStyle = this.options.penColor;
- ctx.textAlign = "left";
- ctx.textBaseline = "top";
- ctx.fillText("最小", 5, dt, 30);
- if (!this.isGood(this.minVqt)) {
- ctx.fillStyle = "rgb(120,0,0)";
- }
- ctx.textAlign = "right";
- if (this.minVqt.Value != null)
- ctx.fillText((this.isFloat(this.minVqt) ? this.minVqt.Value.toFixed(this.options.Num) : this.minVqt.Value), w - 3, dt, w - 30);
- else if (!this.isGood(this.minVqt))
- ctx.fillText("####", w - 3, dt, w - 30);
- }
- }
- if (this.minVqt)
- dt += h;
- if (bReDaw || this.maxChanged) {
- this.maxChanged = false;
- if (!cleared)
- ctx.clearRect(3, dt, w - 5, h);
- if (this.maxVqt) {
- ctx.fillStyle = this.options.penColor;
- ctx.textAlign = "left";
- ctx.textBaseline = "top";
- ctx.fillText("最大", 5, dt, 30);
- if (!this.isGood(this.maxVqt)) {
- ctx.fillStyle = "rgb(120,0,0)";
- }
- ctx.textAlign = "right";
- if (this.maxVqt.Value != null)
- ctx.fillText((this.isFloat(this.maxVqt) ? this.maxVqt.Value.toFixed(this.options.Num) : this.maxVqt.Value), w - 3, dt, w - 30);
- else if (!this.isGood(this.maxVqt))
- ctx.fillText("####", w - 3, dt, w - 30);
- }
- }
- },
- setLinkStatus: function (status, info, nodelay) {
- if (!this.rtChart)
- return;
- if (status == "linking")
- this.linkTime = new Date();
- else if (this.linkStatus == "linking" && !(nodelay === true)) {
- var self = this;
- if (this.linkingTime)
- window.clearTimeout(this.linkingTime);
- this.linkingTime = window.setTimeout(function () {
- window.clearTimeout(self.linkingTime);
- self.linkingTime = null;
- self.setLinkStatus(status, info, true);
- self = null;
- }, 100);
- return;
- }
- if (this.linkStatus != status || this.linkInfo != info) {
- this.linkStatus = status;
- this.linkInfo = info;
- if (this.linkStatus == "error" && this.linkInfo && this.linkInfo.lastIndexOf("E_AUTHENERR") >= 0) {
- this.requestLogin = true;
- this.rtChart.requestLogin();
- } else if (this.linkStatus != 'linking')
- this.requestLogin = false;
- this.linkChanged = true;
- this.rtChart.UpdateDataPan(false);
- if (!this.preventTooltipUpdate && this.showTolltip && this.toolTipAt == "linkStatus" && !(this.requestLogin === true))
- this.rtChart.UpdateTooltip(this.getLinkStatus());
- }
- },
- getLinkStatus: function () {
- var st;
- switch (this.linkStatus) {
- case "linking":
- st = '<span style="color:#00BFFF">正在连接...</span>';
- break;
- case "error":
- st = '<span style="color:#DF0101">连接故障!</span>';
- break;
- case "linked":
- st = '<span style="color:#00aa00">已连接</span>';
- break;
- default:
- st = '<span style="color:#DF0101">状态码未知!</span>';
- }
- if (this.linkInfo) {
- st += "<br>";
- st += this.linkInfo;
- }
- return st;
- },
- resetAxisDrawed: function () {
- this.axisDrawed = false;
- this.axisBeg = null;
- this.axisEnd = null;
- },
- setAxisDrawed: function (calls) {
- this.axisDrawed = true;
- if (this.commAxis && this.commAxis.length) {
- if (calls == null)
- calls = [];
- calls.push(this);
- for (var i = 0; i < this.commAxis.length; i++) {
- var pen = this.commAxis[i];
- var seted = false;
- for (var k in calls) {
- if (calls[k] == pen) {
- seted = true;
- break;
- }
- }
- if (!seted)
- pen.setAxisDrawed(calls);
- }
- }
- },
- drawAxis: function (begX, h, ctx) {
- if (this.axisDrawed || !this.options.drawLine)
- return 0;
- var maxW = 30;
- ctx.beginPath();
- if (this == this.rtChart.getActivePen())
- ctx.strokeStyle = this.getPenColor();
- else if (this.commAxis && this.commAxis.length) {
- for (var i = 0; i < this.commAxis.length; i++) {
- var pen = this.commAxis[i];
- if (pen == this.rtChart.getActivePen()) {
- ctx.strokeStyle = pen.getPenColor();
- break;
- }
- }
- }
- if ((this.minVqt && this.isBoolen(this.minVqt)) || (this.maxVqt && this.isBoolen(this.maxVqt))) {
- var t = this.getY(1);
- if (t == null)
- return 0;
- var b = this.getY(0);
- ctx.moveTo(begX, t);
- ctx.lineTo(begX, b);
- ctx.moveTo(begX, t);
- ctx.lineTo(begX + 3, t);
- ctx.textBaseline = "top";
- ctx.fillText("1", begX + 2, t);
- ctx.moveTo(begX, b);
- ctx.lineTo(begX + 3, b);
- ctx.textBaseline = "bottom";
- ctx.fillText("0", begX + 2, b);
- ctx.stroke();
- maxW -= 22;
- } else {
- if (this.rageMax == null || this.rageMin == null || this.rageMax == this.rageMin)
- return 0;
- var r = Math.abs(this.rageMax - this.rageMin) / 20;
- var Num = 0;
- if (r < 1) {
- r = 1.0 / r;
- Num = Math.ceil(this.log10(r));
- }
- ctx.moveTo(begX, 0);
- ctx.lineTo(begX, h);
- ctx.moveTo(begX - 2, 0)
- ctx.lineTo(begX + 2, 0);
- ctx.textBaseline = "top";
- var str = this.rageMax.toFixed(Num).toString();
- if (str.length > 5) {
- var d = (str.length - 5) * 5;
- if (d > 20)
- d = 20;
- maxW += d;
- }
- ctx.fillText(str, begX + 2, -2, maxW - 2);
- ctx.moveTo(begX - 2, h)
- ctx.lineTo(begX + 2, h);
- ctx.textBaseline = "middle";
- ctx.fillText(this.rageMin.toFixed(Num), begX + 2, h, maxW - 2);
- ctx.textBaseline = "middle";
- var y = h / 20.0;
- for (var i = 1; i < 20; i++) {
- var iy = Math.floor(y);
- ctx.moveTo(begX - 2, iy)
- ctx.lineTo(begX + 1, iy);
- ctx.fillText((this.rageMax - i * (this.rageMax - this.rageMin) / 20).toFixed(Num), begX + 3, iy, maxW - 2);
- y += h / 20.0;
- }
- ctx.stroke();
- }
- var x = begX;
- var y;
- if ((this.minVqt && this.isBoolen(this.minVqt)) || (this.maxVqt && this.isBoolen(this.maxVqt)))
- y = this.getY(0) + 6;
- else
- y = h + 6;
- ctx.beginPath();
- ctx.fillStyle = this.getPenColor();
- ctx.rect(x, y, 5, 5);
- ctx.fill();
- x += 7;
- if (x + 5 > begX + maxW) {
- x = begX;
- y += 7;
- }
- this.setAxisDrawed();
- if (this.commAxis && this.commAxis.length) {
- for (var i = 0; i < this.commAxis.length; i++) {
- var pen = this.commAxis[i];
- ctx.beginPath();
- ctx.fillStyle = pen.getPenColor();
- ctx.rect(x, y, 5, 5);
- ctx.fill();
- x += 7;
- if (x + 5 > begX + maxW) {
- x = begX;
- y += 7;
- }
- }
- }
- this.axisBeg = begX;
- this.axisEnd = begX + maxW;
- return maxW;
- },
- removeCommAxis: function (pen) {
- if (this.commAxis) {
- var len = this.commAxis.length;
- for (var i = 0; i < len; i++) {
- if (this.commAxis[i] == pen) {
- this.commAxis.splice(i, 1);
- break;
- }
- }
- }
- },
- addCommAxis: function (pen) {
- var oldComm = this.commAxis;
- this.commAxis = null;
- if (oldComm) {
- for (var i = 0; i < oldComm.length; i++)
- oldComm[i].removeCommAxis(this);
- }
- this.setRange(pen.rageMin, pen.rageMax);
- this.commAxis = [];
- this.commAxis.push(pen);
- },
- onCommAxisSet: function (arr) {
- var newComm = null;
- for (var i = 0; i < arr.length; i++) {
- var ind = arr[i];
- var pen = this.rtChart.trendPens[ind];
- if (pen && pen != this) {
- if (newComm == null)
- newComm = [];
- newComm.push(pen);
- }
- }
- var oldComm = this.commAxis;
- this.commAxis = null;
- if (oldComm) {
- for (var i = 0; i < oldComm.length; i++) {
- var pen = oldComm[i];
- pen.removeCommAxis(this);
- }
- }
- if (newComm) {
- for (var i = 0; i < newComm.length; i++)
- newComm[i].addCommAxis(this);
- }
- this.commAxis = newComm;
- this.rtChart.UpdateAxisPan(true);
- },
- onSetCommAxis: function (e) {
- this.rtChart.requestActive(this);
- var pen = this;
- var content = '<form action="" method="get" style="line-height:26px;width:100%">选择共轴位号:';
- var bIsBool = false;
- if (this.minVqt && this.isBoolen(this.minVqt))
- bIsBool = true;
- else if (this.maxVqt && this.isBoolen(this.maxVqt))
- bIsBool = true;
- var pens = this.rtChart.trendPens;
- for (var i = 0; i < pens.length; i++) {
- var pen = pens[i];
- if (pen == this)
- content += '<br><label ' + (pen.getDes() ? ('title="' + pen.getDes() + ' (*)"') : 'title="(*)"') + ' style="color:' + pen.getPenColor() + '"><input type="checkbox" disabled="true" checked="checked" value="' + i + '"/>' + pen.getLabel() + '</label>';
- else {
- var bIsComm = false;
- if (this.commAxis && this.commAxis.length) {
- for (var k = 0; k < this.commAxis.length; k++) {
- if (this.commAxis[k] == pen) {
- bIsComm = true;
- break;
- }
- }
- }
- if (bIsComm) {
- content += '<br><label ' + (pen.getDes() ? ('title="' + pen.getDes() + '"') : '') + ' style="color:' + pen.getPenColor() + '"><input type="checkbox" checked="checked" value="' + i + '"/>' + pen.getLabel() + '</label>';
- } else {
- var bpenIsBool = false;
- if (pen.minVqt && pen.isBoolen(pen.minVqt))
- bpenIsBool = true;
- else if (pen.maxVqt && pen.isBoolen(pen.maxVqt))
- bpenIsBool = true;
- if (bpenIsBool == bIsBool) {
- content += '<br><label ' + (pen.getDes() ? ('title="' + pen.getDes() + '"') : '') + ' style="color:' + pen.getPenColor() + '"><input type="checkbox" value="' + i + '"/>' + pen.getLabel() + '</label>';
- }
- }
- }
- }
- content += '</form>';
- var pen = this;
- var d = dialog({
- title: '设置 ' + this.getLabel() + ' 的共轴显示',
- quickClose: true,
- content: content,
- padding: 10,
- okValue: '确定',
- ok: function () {
- var arr = [];
- var sel = $('input[type=checkbox]', this.__popup);
- for (var i = 0; i < sel.length; i++) {
- if (sel[i].checked)
- arr.push(parseInt(sel[i].value));
- }
- pen.onCommAxisSet(arr);
- pen = null;
- d.close().remove();
- d = null;
- }
- });
- e.pageX += 10;
- e.pageY -= 30;
- d.show(e);
- },
- getCommGroup: function (penGroup) {
- penGroup.push(this);
- if (this.commAxis && this.commAxis.length) {
- for (var i = 0; i < this.commAxis.length; i++) {
- var pen = this.commAxis[i];
- var find = false;
- for (var k in penGroup) {
- if (penGroup[k] == pen) {
- find = true;
- break;
- }
- }
- if (!find)
- pen.getCommGroup(penGroup);
- }
- }
- },
- setHisStatus: function (status, info, nodelay) {
- if (!this.rtChart)
- return;
- if (status == "getting")
- this.hisTime = new Date();
- else if (this.hisGetStaus == "getting" && !(nodelay === true)) {
- var self = this;
- if (this.hisingTime)
- window.clearTimeout(this.hisingTime);
- this.hisingTime = window.setTimeout(function () {
- window.clearTimeout(self.hisingTime);
- self.hisingTime = null;
- self.setHisStatus(status, info, true);
- self = null;
- }, 100);
- return;
- }
- if (this.hisGetStaus != status || this.hisInfo != info) {
- this.hisGetStaus = status;
- this.hisInfo = info;
- this.hisChanged = true;
- this.rtChart.UpdateDataPan(false);
- if (!this.preventTooltipUpdate && this.showTolltip && this.toolTipAt == "hisStatus" && !(this.requestLogin === true))
- this.rtChart.UpdateTooltip(this.getHisStatus());
- }
- },
- getHisStatus: function () {
- var st;
- switch (this.hisGetStaus) {
- case "getting":
- st = '<span style="color:#00BFFF">正在获取...</span>';
- break;
- case "wait":
- st = '<span style="color:#00BFFF">正在等待...</span>';
- break;
- case "error":
- st = '<span style="color:#DF0101">连接故障!</span>';
- break;
- case "linked":
- st = '<span style="color:#00aa00">已获得历史数据</span>';
- break;
- case "nodata":
- st = '<span style="color:#003366">无历史数据</span>';
- break;
- default:
- st = '<span style="color:#DF0101">状态码未知!</span>';
- }
- if (this.hisInfo) {
- st += "<br>";
- st += this.hisInfo;
- }
- return st;
- },
- getpreventTooltipUpdate: function () {
- return this.preventTooltipUpdate;
- },
- onTooltipShowed: function () {
- this.showTolltip = true;
- },
- onTooltipHided: function () {
- this.showTolltip = false;
- this.preventTooltipUpdate = false;
- this.toolTipAt = null;
- },
- isActive: function () {
- return this.bActive;
- },
- setActive: function (bActive) {
- if (this.bActive == bActive || !this.rtChart)
- return;
- this.bActive = bActive;
- this.activeChanged = true;
- this.rtChart.UpdatePan(false);
- },
- activePen: function () {
- var nowActived = this.rtChart.getActivePen() == this;
- if (nowActived)
- this.bActive = true;
- else
- this.rtChart.requestActive(this);
- },
- onMouseMove: function (x, y, e, clientX, clientY, panH) {
- var w = this.rtChart.getPanWidth();
- var ta = (clientY > panH / 2) ? 'top right' : 'bottom right';
- var ty = e.pageY + ((clientY > panH / 2) ? -8 : 8);
- var t = SPANPAD;
- var h = SPANLINEHEIGHT;
- if (y >= 0 && y < t + h) {
- if (x < 20) {
- var opt = {
- content: "点击设置趋势笔颜色",
- align: ta,
- skin: 'tooltipTans',
- x: e.pageX + 10,
- y: ty
- }
- this.toolTipAt = null;
- this.rtChart.showTooltip(opt, this);
- this.rtChart.setCursor("pointer");
- return true;
- } else if (x < w - 10) {
- if (this.rtChart && this.rtChart.getLoginPen && this.rtChart.getLoginPen() != this) {
- var opt = {
- title: this.getLabel(),
- content: "<b>存取路径:</b><br>" + this.getURI() + (this.des && this.des.length ? ("<br><b>描 述:</b><br>" + this.des) : "") + "<br><b>Web服务:</b><br>" + this.getWebURL(),
- skin: 'tooltipTans',
- align: ta,
- x: e.pageX + 20,
- y: ty
- }
- this.toolTipAt = null;
- this.rtChart.showTooltip(opt, this, e);
- this.rtChart.setCursor("pointer");
- return true;
- }
- } else {
- var opt = {
- content: "单击移除趋势笔",
- skin: 'tooltipTans',
- align: ta,
- x: e.pageX,
- y: ty
- }
- this.toolTipAt = null;
- this.rtChart.showTooltip(opt, this);
- this.rtChart.setCursor("pointer");
- return true;
- }
- } else if (y >= t + h && y < t + 2 * h) {
- if (x >= 0 && x < 18) {
- var st;
- var bHook = false;
- if (this.requestLogin === true) {
- st = '实时信息网站:<br><span style="color:#00BFFF">' + this.getWebURL() + "</span><br>需要登录,点击<a href='Javascript: void(0)'>这里</a>进行操作";
- this.preventTooltipUpdate = true;
- bHook = true;
- } else {
- st = this.getLinkStatus();
- this.preventTooltipUpdate = false;
- }
- var opt = {
- title: '连接状态',
- content: st,
- skin: 'tooltipTans',
- align: ta,
- x: e.pageX + 20,
- y: ty
- }
- if (bHook) {
- var trendPen = this;
- var showed = false;
- opt.onshow = function () {
- if (showed === false) {
- showed = true;
- $('a', this.__popup).click(function () {
- $(this).unbind('click');
- trendPen.rtChart.requestLogin();
- trendPen = null;
- });
- }
- };
- } else
- opt.width = 180;
- this.rtChart.showTooltip(opt, this);
- this.toolTipAt = "linkStatus";
- } else if (x >= 20 && x < 30 && this.hisGetStaus != null) {
- var opt = {
- title: '历史数据获取状态',
- content: this.getHisStatus(),
- skin: 'tooltipTans',
- width: 180,
- align: ta,
- x: e.pageX + 20,
- y: ty
- }
- this.rtChart.showTooltip(opt, this);
- this.toolTipAt = "hisStatus";
- } else if (x > w - 22) {
- if (this.unit) {
- var opt = {
- content: '工程单位:' + this.unit,
- skin: 'tooltipTans',
- align: ta,
- x: e.pageX + 10,
- y: ty
- }
- this.rtChart.showTooltip(opt, this);
- this.toolTipAt = null;
- }
- }
- } else if (y >= t + 2 * h && y < t + 3 * h) {
- if (this.vqt) {
- var opt = {
- title: this.getLabel() + ' 的实时数据',
- content: this.getVQTTooltip(),
- align: ta,
- skin: 'tooltipTans',
- width: 250,
- x: e.pageX + 10,
- y: ty
- }
- this.rtChart.showTooltip(opt, this);
- this.toolTipAt = "vqt";
- }
- } else if (y >= t + 3 * h && y < t + 4 * h) {
- if (this.avg != null) {
- var opt = {
- title: this.getLabel() + ' 的平均值(中值)',
- content: this.getAVGTooltip(),
- align: ta,
- skin: 'tooltipTans',
- width: 250,
- x: e.pageX + 10,
- y: ty
- }
- this.rtChart.showTooltip(opt, this);
- this.toolTipAt = "avg";
- }
- } else if (y >= t + 4 * h && y < t + 5 * h) {
- if (this.minVqt != null) {
- var opt = {
- title: this.getLabel() + ' 的最小值',
- content: this.getMinVQTTooltip(),
- align: ta,
- skin: 'tooltipTans',
- width: 250,
- height: 90,
- x: e.pageX + 10,
- y: ty
- }
- this.rtChart.showTooltip(opt, this);
- this.toolTipAt = "minVQT";
- this.rtChart.setCursor("pointer");
- return true;
- }
- } else if (y >= t + 5 * h && y < t + 6 * h) {
- if (this.maxVqt != null) {
- var opt = {
- title: this.getLabel() + ' 的最大值',
- content: this.getMaxVQTTooltip(),
- align: ta,
- skin: 'tooltipTans',
- width: 250,
- height: 90,
- x: e.pageX + 10,
- y: ty
- }
- this.rtChart.showTooltip(opt, this);
- this.toolTipAt = "maxVQT";
- this.rtChart.setCursor("pointer");
- return true;
- }
- }
- },
- onClick: function (x, y, e) {
- var w = this.rtChart.getPanWidth();
- var t = SPANPAD;
- var h = SPANLINEHEIGHT;
- if (x > 20 && x < w - 10 && this.requestLogin !== true && !this.bActive) {
- this.rtChart.requestActive(this);
- return;
- }
- if (y >= 0 && y < t + h) {
- if (x < 20) {
- this.rtChart.setPenColor(this, e);
- } else if (x < w - 10) {
- if (this.requestLogin === true) {
- this.rtChart.requestLogin();
- } else {
- if (this.bActive)
- this.rtChart.requestActive(null);
- else
- this.rtChart.requestActive(this);
- }
- } else
- this.rtChart.removePen(this);
- } else if (y >= t + 4 * h && y < t + 5 * h)
- this.posVQT("min");
- else if (y >= t + 5 * h && y < t + 6 * h)
- this.posVQT("max");
- },
- onLinkTab: function (data) {
- if (!data || !data.length || !this.rtChart)
- return;
- var base = data[0].BasePointInfo;
- if (base && base.Unit)
- this.unit = base.Unit;
- if (base && base.Desc)
- this.setDes(base.Desc);
- this.rtRefreshKey = this.rtChart.RegistRtPt(this, this.getURI(), this.onRtRefresh);
- if (!this.rtRefreshKey)
- this.setLinkStatus("error", "实时刷新注册失败!");
- if (!this.rtChart.requestHisData(this))
- this.setHisStatus("error", "历史数据查询请求失败!");
- },
- setRtVQT: function (vqt) {
- if (!this.rtChart)
- return;
- var bReDraw = (this.vqt && !vqt) || (!this.vqt && vqt);
- this.vqt = vqt;
- this.vqtChanged = true;
- if (this.rowId)
- this.rtChart._updateList(this.rowId, "实时值", this.getVQTList());
- this.rtChart.UpdateDataPan(bReDraw);
- if (!this.preventTooltipUpdate && this.showTolltip && this.toolTipAt == "vqt")
- this.rtChart.UpdateTooltip(this.getVQTTooltip());
- },
- getVQTList: function () {
- if (!this.vqt) {
- return {
- title: "尚未获取实时值",
- color: "rgb(160,0,0)",
- value: "[!!尚未获取实时值]"
- };
- } else {
- var vqt = {};
- vqt.title = "质量码:" + this.vqt.getQuaStr() + "\n" + "时间戳:" + this.vqt.getFullStampTimeStr();
- if (this.vqt.isGood())
- vqt.color = "rgb(0,30,0)";
- else if (this.vqt.isUncertain())
- vqt.color = "rgb(100,100,0)";
- else
- vqt.color = "rgb(180,0,0)";
- vqt.value = (this.vqt.isFloat() ? this.vqt.value.toFixed(this.options.Num) : this.vqt.value);
- if (this.unit && this.unit.length) {
- vqt.unit = this.unit;
- }
- vqt.numberVal = this.vqt.GetNumber();
- return vqt;
- }
- },
- getMaxVQTList: function () {
- if (!this.maxVqt) {
- return {
- title: "尚未获得最大值",
- color: "rgb(160,0,0)",
- value: "[!!尚未获得最大值]"
- };
- } else {
- var vqt = {};
- vqt.tip = "max";
- vqt.title = "质量码:" + this.getQuaStr(this.maxVqt) + "\n" + "时间戳:" + this.rtChart.FileTimeToDateString(this.maxVqt.StampTime) + " " + this.rtChart.FileTimeToTimeString(this.maxVqt.StampTime);
- if (this.isGood(this.maxVqt))
- vqt.color = "rgb(0,80,0)";
- else if (this.isUncertain(this.maxVqt))
- vqt.color = "rgb(100,100,0)";
- else
- vqt.color = "rgb(180,0,0)";
- vqt.value = (this.isFloat(this.maxVqt) ? this.maxVqt.Value.toFixed(this.options.Num) : this.maxVqt.Value);
- if (this.unit && this.unit.length) {
- vqt.unit = this.unit;
- }
- return vqt;
- }
- },
- getMinVQTList: function () {
- if (!this.minVqt) {
- return {
- title: "尚未获得最小值",
- color: "rgb(160,0,0)",
- value: "[!!尚未获得最小值]"
- };
- } else {
- var vqt = {};
- vqt.tip = "min";
- vqt.title = "质量码:" + this.getQuaStr(this.minVqt) + "\n" + "时间戳:" + this.rtChart.FileTimeToDateString(this.minVqt.StampTime) + " " + this.rtChart.FileTimeToTimeString(this.minVqt.StampTime);
- if (this.isGood(this.minVqt))
- vqt.color = "rgb(0,80,0)";
- else if (this.isUncertain(this.minVqt))
- vqt.color = "rgb(100,100,0)";
- else
- vqt.color = "rgb(180,0,0)";
- vqt.value = (this.isFloat(this.minVqt) ? this.minVqt.Value.toFixed(this.options.Num) : this.minVqt.Value);
- if (this.unit && this.unit.length) {
- vqt.unit = this.unit;
- }
- return vqt;
- }
- },
- getVQTTooltip: function () {
- if (!this.vqt)
- return null;
- var tip = '<div class="'
- if (this.vqt.isGood())
- tip += 'tooltpgoodval">';
- else
- tip += 'tooltpbadval">';
- tip += '<span class="tooltiplabel">实时值:</span>';
- if (this.vqt.value != null) {
- tip += (this.vqt.isFloat() ? this.vqt.value.toFixed(this.options.Num) : this.vqt.value);
- if (this.unit && this.unit.length) {
- tip += " " + this.unit;
- }
- }
- tip += '</div>';
- if (this.vqt.isGood())
- tip += '<div class="tooltipQGood">';
- else
- tip += '<div class="tooltipQBad">';
- tip += '<span class="tooltiplabel">质量码:</span>';
- tip += this.vqt.getQuaStr();
- tip += '</div>';
- tip += '<div class="tooltipT">';
- tip += '<span class="tooltiplabel">时间戳:</span>';
- tip += this.vqt.getFullStampTimeStr();
- tip += '</div>';
- tip += '</div>';
- return tip;
- },
- getAVGTooltip: function () {
- if (this.avg == null)
- return null;
- var tip = '<div class="tooltpgoodval">'
- tip += '<span class="tooltiplabel">平均值:</span>';
- tip += (Math.floor(this.avg) != this.avg ? this.avg.toFixed(this.options.Num) : this.avg);
- if (this.unit && this.unit.length) {
- tip += " " + this.unit;
- }
- tip += '</div>';
- return tip
- },
- getAVGList: function () {
- var avg = {};
- if (this.avg != null) {
- avg.value = (Math.floor(this.avg) != this.avg ? this.avg.toFixed(this.options.Num) : this.avg);
- if (this.unit && this.unit.length) {
- avg.unit = this.unit;
- }
- }
- return avg;
- },
- getMinVQTTooltip: function () {
- if (!this.minVqt)
- return null;
- var tip = '<div class="'
- if (this.isGood(this.minVqt))
- tip += 'tooltpgoodval">';
- else
- tip += 'tooltpbadval">';
- tip += '<span class="tooltiplabel">最小值:</span>';
- if (this.minVqt.Value != null) {
- tip += (this.isFloat(this.minVqt) ? this.minVqt.Value.toFixed(this.options.Num) : this.minVqt.Value);
- if (this.unit && this.unit.length) {
- tip += " " + this.unit;
- }
- }
- tip += '</div>';
- if (this.isGood(this.minVqt))
- tip += '<div class="tooltipQGood">';
- else
- tip += '<div class="tooltipQBad">';
- tip += '<span class="tooltiplabel">质量码:</span>';
- tip += this.getQuaStr(this.minVqt);
- tip += '</div>';
- tip += '<div class="tooltipT">';
- tip += '<span class="tooltiplabel">时间戳:</span>';
- tip += this.rtChart.FileTimeToDateString(this.minVqt.StampTime) + " " + this.rtChart.FileTimeToTimeString(this.minVqt.StampTime);
- tip += '</div>';
- tip += '<div class="tooltipT">';
- tip += '点击可定位最小值';
- tip += '</div>';
- tip += '</div>';
- return tip;
- },
- getMaxVQTTooltip: function () {
- if (!this.maxVqt)
- return null;
- var tip = '<div class="'
- if (this.isGood(this.maxVqt))
- tip += 'tooltpgoodval">';
- else
- tip += 'tooltpbadval">';
- tip += '<span class="tooltiplabel">最大值:</span>';
- if (this.maxVqt.Value != null) {
- tip += (this.isFloat(this.maxVqt) ? this.maxVqt.Value.toFixed(this.options.Num) : this.maxVqt.Value);
- if (this.unit && this.unit.length) {
- tip += " " + this.unit;
- }
- }
- tip += '</div>';
- if (this.isGood(this.maxVqt))
- tip += '<div class="tooltipQGood">';
- else
- tip += '<div class="tooltipQBad">';
- tip += '<span class="tooltiplabel">质量码:</span>';
- tip += this.getQuaStr(this.maxVqt);
- tip += '</div>';
- tip += '<div class="tooltipT">';
- tip += '<span class="tooltiplabel">时间戳:</span>';
- tip += this.rtChart.FileTimeToDateString(this.maxVqt.StampTime) + " " + this.rtChart.FileTimeToTimeString(this.maxVqt.StampTime);
- tip += '</div>';
- tip += '<div class="tooltipT">';
- tip += '<span class="tooltiplabel">点击可定位最大值</span>';
- tip += '</div>';
- tip += '</div>';
- return tip;
- },
- posVQT: function (tip) {
- switch (tip) {
- case 'max':
- if (this.maxVqt != null)
- this.rtChart.posvIndicator(this.maxVqt.StampTime);
- break;
- case 'min':
- if (this.minVqt != null)
- this.rtChart.posvIndicator(this.minVqt.StampTime);
- break;
- }
- },
- getValueTooltipAtTime: function (ft) {
- var vqt = null;
- var prev = null;
- var next = null;
- if (this.hisData) {
- var len = this.hisData.length;
- for (var i = 0; i < len; i++) {
- var findVQT = this.hisData[i];
- if (findVQT.StampTime == ft) {
- vqt = findVQT;
- break;
- } else if (findVQT.StampTime > ft) {
- if (prev) {
- vqt = prev;
- next = findVQT;
- } else
- vqt = findVQT;
- break;
- } else
- prev = findVQT;
- }
- }
- var tip = '<div class="';
- if (vqt) {
- if (this.isGood(vqt))
- tip += 'tooltpgoodval" ';
- else
- tip += 'tooltpbadval" ';
- tip += 'title="质量码:' + this.getQuaStr(vqt) + '" ';
- tip += 'style="color:';
- tip += this.getPenColor();
- tip += '">';
- } else {
- tip += 'tooltpnoval" ';
- tip += 'style="color:';
- tip += this.getPenColor();
- tip += '">';
- tip += '[!!无历史数据]';
- }
- tip += '<span class="tooltiplabel"';
- tip += 'style="color:';
- tip += this.getPenColor();
- tip += '">';
- tip += this.getLabel();
- tip += '</span>';
- if (vqt) {
- if (vqt.Value != null) {
- if (next && next.StampTime > vqt.StampTime && next.Value != null) {
- if (this.isString(vqt))
- tip += (vqt.Value ? vqt.Value : "");
- else if (this.isBoolen(vqt)) {
- if (vqt.Value)
- tip += "1";
- else
- tip += "0";
- } else {
- var inter = vqt.Value + (next.Value - vqt.Value) * (ft - vqt.StampTime) / (next.StampTime - vqt.StampTime);
- tip += inter.toFixed(this.options.Num);
- }
- } else {
- tip += '<span class="tooltipvalstamp">';
- tip += this.getStampTimeStr(vqt);
- tip += '</span>';
- if (this.isString(vqt))
- tip += (vqt.Value ? vqt.Value : "");
- else if (this.isBoolen(vqt)) {
- if (vqt.Value)
- tip += "1";
- else
- tip += "0";
- } else
- tip += (this.isFloat(vqt) ? vqt.Value.toFixed(this.options.Num) : vqt.Value);
- }
- if (this.unit && this.unit.length)
- tip += " " + this.unit;
- } else {
- tip += '<span class="tooltipvalstamp">';
- tip += this.getStampTimeStr(vqt);
- tip += '</span>';
- tip += '[!!空值]';
- }
- }
- tip += '</div>';
- return tip;
- },
- getValueLine: function (iy) {
- var tip = '<div class="valine">';
- tip += '<span class="tooltiplabel"';
- tip += 'style="color:';
- tip += this.getPenColor();
- tip += '">';
- tip += this.getLabel();
- tip += '</span>';
- var val = this.getVal(iy);
- if (val == null) {
- tip += '</div>';
- return tip;
- }
- val = val.toFixed(this.options.Num)
- tip += val;
- if (this.unit && this.unit.length)
- tip += " " + this.unit;
- tip += '</div>';
- return tip;
- },
- _setListRowId: function (rowId) {
- this.rowId = rowId;
- this.updateListGrid();
- },
- setDisplay: function (drawLine, updateList) {
- if (this.options.drawLine === drawLine)
- return;
- this.options.drawLine = drawLine;
- if (!this.options.drawLine) {
- if (this.rtChart.activePen == this)
- this.rtChart.requestActive(null);
- }
- if (updateList !== false)
- this.rtChart._updateList(this.rowId, "显示", this.options.drawLine);
- this.rtChart.updateDataArea();
- this.rtChart.UpdateAxisPan(true);
- },
- setStepLine: function (stepline, updateList, force) {
- if (this.options.stepLine === stepline)
- return;
- if (!force && stepline === false) {
- var type = null;
- if ((this.minVqt && this.isString(this.minVqt)) || (this.maxVqt && this.isString(this.maxVqt))) {
- type = "字符串";
- } else if ((this.minVqt && this.isBoolen(this.minVqt)) || (this.maxVqt && this.isBoolen(this.maxVqt))) {
- type = "开关量";
- }
- if (type != null) {
- var pen = this;
- var d = dialog({
- title: '设置阶跃绘制',
- content: '点:' + this.getLabel() + " 的数据类型为:" + type + ",<br>不适合采用非阶跃的方式绘制趋势线,是否仍改变趋势线绘制方式?",
- okValue: '确定',
- ok: function () {
- pen.setStepLine(stepline, updateList, true);
- pen = null;
- return true;
- },
- cancelValue: '取消',
- cancel: function () {
- pen.rtChart._updateList(pen.rowId, "阶跃", pen.options.stepLine == null ? false : pen.options.stepLine);
- }
- });
- d.showModal();
- return;
- }
- }
- this.options.stepLine = stepline;
- if (updateList !== false)
- this.rtChart._updateList(this.rowId, "阶跃", this.options.stepLine == null ? false : this.options.stepLine);
- this.rtChart.updateDataArea();
- },
- setDrawTag: function (drawTag, updateList) {
- if (this.options.drawTag === drawTag)
- return;
- this.options.drawTag = drawTag;
- if (updateList !== false)
- this.rtChart._updateList(this.rowId, "标记", this.options.drawTag);
- this.rtChart.updateDataArea();
- },
- setInterpolate: function (inter, updateList) {
- if (this.options.interpolate === inter)
- return;
- if (inter) {
- var type = null;
- if ((this.minVqt && this.isString(this.minVqt)) || (this.maxVqt && this.isString(this.maxVqt))) {
- type = "字符串";
- } else if ((this.minVqt && this.isBoolen(this.minVqt)) || (this.maxVqt && this.isBoolen(this.maxVqt))) {
- type = "开关量";
- }
- if (type != null) {
- var pen = this;
- var d = dialog({
- title: '插值显示设置',
- content: '点:' + this.getLabel() + " 的数据类型为:" + type + ",<br>不适合采用插值显示方式?"
- });
- d.show();
- this.rtChart._updateList(pen.rowId, "插值", false);
- window.setTimeout(function () {
- d.close().remove();
- d = null;
- }, 2000);
- return;
- }
- }
- this.options.interpolate = inter;
- if (updateList !== false)
- this.rtChart._updateList(this.rowId, "插值", this.options.interpolate);
- this.updateDataReader();
- this.rtChart._updatevIndicatorTooltip();
- },
- updateListGrid: function () {
- if (!this.rowId)
- return;
- this.rtChart._updateList(this.rowId, "点名称", {
- uri: this.getURI(),
- color: this.getPenColor()
- });
- this.rtChart._updateList(this.rowId, "线宽", this.options.penWidth);
- this.rtChart._updateList(this.rowId, "显示", this.options.drawLine);
- this.rtChart._updateList(this.rowId, "阶跃", this.options.stepLine == null ? false : this.options.stepLine);
- this.rtChart._updateList(this.rowId, "标记", this.options.drawTag);
- this.rtChart._updateList(this.rowId, "插值", this.options.interpolate);
- this.rtChart._updateList(this.rowId, "描述", this.getDes());
- this.rtChart._updateList(this.rowId, "实时值", this.getVQTList());
- this.rtChart._updateList(this.rowId, "最大值", this.getMaxVQTList());
- this.rtChart._updateList(this.rowId, "最小值", this.getMinVQTList());
- this.rtChart._updateList(this.rowId, "平均值", this.getAVGList());
- this.rtChart._updateList(this.rowId, "量程锁定", this.options.lockRange);
- this.updateRangeList();
- this.updateDataReader();
- },
- onRtRefresh: function (status, data, opt) {
- switch (status) {
- case "getting":
- this.setLinkStatus("linking", "正在获取实时数据...");
- break;
- case "error":
- this.setLinkStatus("error", "获取实时数据失败" + ((data && data.length) ? ("\n" + data) : ""));
- if (this.vqt && this.vqt.isGood()) {
- this.vqt.qua = 0x14;
- this.vqt.errMess = data;
- this.setRtVQT(this.vqt);
- }
- break;
- case "success":
- this.setLinkStatus("linked", "已成功获取实时数据");
- this.setRtVQT(data);
- break;
- }
- },
- refreshHisData: function (bClearData) {
- if (bClearData === true)
- delete this.hisData;
- else if (this.hisData) {
- var begTime = this.rtChart.getBegTime();
- var endTime = this.rtChart.getEndTime();
- if (this.getBegTime() <= begTime && this.getEndTime() >= endTime)
- return;
- else if (!((this.getBegTime() <= begTime && this.getEndTime() <= endTime) ||
- (this.getBegTime() >= begTime && this.getEndTime() >= endTime)))
- delete this.hisData;
- }
- this.setHisStatus("wait", "正在等待查询启动");
- if (!this.rtChart.requestHisData(this))
- this.setHisStatus("error", "历史数据查询请求失败!");
- },
- getBegTime: function () {
- if (this.hisData && this.hisData.length)
- return this.hisData[0].StampTime;
- else
- return null;
- },
- getEndTime: function () {
- if (this.hisData && this.hisData.length)
- return this.hisData[this.hisData.length - 1].StampTime;
- else
- return null;
- },
- isHisRq: function () {
- if (!this.rtChart)
- return false;
- else if (this.options.itemDef != null && this.options.itemDef.entityId != null && this.options.itemDef.propId != null)
- return true;
- else if (this.hisGetStaus == null)
- return true;
- else if (this.hisGetStaus == 'wait')
- return true;
- else if (this.hisGetStaus == 'error') {
- if (this.hisTime && (new Date() - this.hisTime > this.options.hisReTryTime))
- return true;
- else
- return false;
- } else if (this.hisGetStaus != 'getting') {
- if (this.rtChart.getHisRefreshing())
- return true;
- else if (this.hisGetStaus == 'nodata')
- return false;
- else if (!this.getEndTime())
- return true;
- else if (this.getEndTime() < this.rtChart.getEndTime())
- return true;
- else
- return false;
- } else {
- if (this.linkTime && new Date() - this.hisTime > this.options.hisReTryTime)
- return true;
- else
- return false;
- }
- },
- getHisRequestTab: function () {
- var tab = new GoldenRtWeb.Tab();
- tab.resultCode = 'S_RTREFRESHHISDATA';
- if (this.options.itemDef == null)
- this.options.itemDef = {};
- this.options.itemDef.dataMethod = 'HDBAGGREG_MAXMINMUM';
- var gw = this.rtChart.getGridWidth();
- var begTime = this.rtChart.getBegTime();
- var endTime = this.rtChart.getEndTime();
- if (this.rtChart.getHisRefreshing()) {
- if (this.getEndTime() != null && this.getEndTime() > begTime) {
- this.options.itemDef.beginTime = this.getEndTime();
- this.options.itemDef.endTime = null;
- } else {
- this.options.itemDef.beginTime = begTime;
- this.options.itemDef.endTime = null;
- }
- this.options.itemDef.slotTime = gw;
- } else if (this.getBegTime() != null && this.getBegTime() <= begTime && this.getEndTime() != null && this.getEndTime() <= endTime) {
- this.options.itemDef.beginTime = this.getEndTime();
- this.options.itemDef.endTime = endTime;
- this.options.itemDef.slotTime = gw * (this.options.itemDef.endTime - this.options.itemDef.beginTime) / this.rtChart.getTimeSpan();
- } else if (this.getBegTime() >= begTime && this.getEndTime() >= endTime) {
- this.options.itemDef.beginTime = begTime;
- this.options.itemDef.endTime = this.getBegTime();
- this.options.itemDef.slotTime = gw * (this.options.itemDef.endTime - this.options.itemDef.beginTime) / this.rtChart.getTimeSpan();
- } else {
- this.options.itemDef.beginTime = begTime;
- this.options.itemDef.endTime = endTime;
- this.options.itemDef.slotTime = gw;
- }
-
- if (this.vqt) {
- if (this.options.itemDef.beginTime > this.vqt.StampTime)
- this.options.itemDef.beginTime = this.vqt.StampTime;
- if (this.options.itemDef.endTime > this.vqt.StampTime)
- this.optionsitemDef.endTime = 0;
- }
-
-
-
- var col = new GoldenRtWeb.Col();
- col.key = "hisdata";
- col.value = this.itemDef;
- var row = new GoldenRtWeb.Row();
- row.addCol(col);
- tab.addRow(row);
- tab.hisRequestSeed = ++this.hisRequestSeed;
- return tab;
- },
- onHisTab: function (tab) {
-
- if (!this.rtChart)
- return;
- var err = null;
- if (tab.hisRequestSeed == this.hisRequestSeed) {
- var newData = tab.hisData;
- var lastVQT = newData[newData.length - 1];
- if (lastVQT.StampTime < this.rtChart.getBegTime()) {
- this.setHisStatus("nodata", "查询不到有效的历史数据");
- return;
- }
- this.newHisData = newData;
- this.setHisStatus("linked");
- if (this.rtChart.getHisRefreshing())
- this.rtChart._setNewLastTime(lastVQT.StampTime);
- this.rtChart._setNewLastTime(lastVQT.StampTime);
- this.rtChart._onNewHisData();
- } else if (tab.isErr()) {
- err = "信息服务返回错误,错误码是:" + tab.resultCode + "<br/>" + "错误信息是:" + tab.errMess + "<br/>" + "错误源是:" + tab.errorSource;
- this.setHisStatus("error", err);
- }
- },
- prepareHisData: function (begTime, endTime) {
- if (this.hisData && this.hisData.length) {
- var i = 0;
- var len = this.hisData.length;
- for (; i < len; i++) {
- if (this.hisData[i].StampTime >= begTime)
- break;
- }
- var prev = this.rtChart.options.reservePrevData || 1;
- if (i >= prev)
- this.hisDatRemove(this.hisData, 0, (i - prev));
- }
- var dataChanged = false;
- if (this.newHisData && this.newHisData.length) {
- if (this.hisData && this.hisData.length > 0) {
- var firstTime = this.newHisData[0].StampTime;
- var lastTime = this.newHisData[this.newHisData.length - 1].StampTime;
- if (lastTime <= this.getBegTime()) {
- if (lastTime == this.getBegTime())
- this.hisDatRemove(this.hisData, 0);
- dataChanged = true;
- this.hisData = this.newHisData.concat(this.hisData);
- } else if (firstTime < this.getBegTime() && lastTime <= this.getEndTime()) {
- var i = 0;
- for (; i < this.hisData.length; i++) {
- if (this.hisData[i].StampTime > lastTime)
- break;
- }
- if (i > 0)
- this.hisDatRemove(this.hisData, 0, i - 1);
- dataChanged = true;
- this.hisData = this.newHisData.concat(this.hisData);
- } else if (firstTime >= this.getBegTime() && lastTime > this.getEndTime()) {
- var i = 0;
- var len = this.hisData.length;
- for (; i < len; i++) {
- if (this.hisData[i].StampTime >= firstTime)
- break;
- }
- if (i < this.hisData.length)
- this.hisDatRemove(this.hisData, i, this.hisData.length - 1);
- dataChanged = true;
- this.hisData = this.hisData.concat(this.newHisData);
- } else if (firstTime >= this.getEndTime()) {
- if (firstTime == this.getEndTime())
- this.hisDatRemove(this.hisData, -1);
- dataChanged = true;
- this.hisData = this.hisData.concat(this.newHisData);
- }
- } else {
- dataChanged = true;
- this.hisData = this.newHisData;
- }
- delete this.newHisData;
- }
- if (dataChanged || this.lastBegTime != begTime || this.lastEndTime != endTime) {
- this.lastBegTime = begTime;
- this.lastEndTime = endTime;
- var minVqt = null;
- var maxVqt = null;
- var goodCount = 0;
- var badCount = 0;
- var unCertain = 0;
- var sum = 0.0;
- var det = 0.0;
- var avg;
- var prevVQT;
- var min = this.rageMin;
- var max = this.rageMax;
- if (this.hisData) {
- var len = this.hisData.length;
- for (var i = 0; i < len; i++) {
- var vqt = this.hisData[i];
- if (vqt.StampTime >= begTime &&
- vqt.StampTime <= endTime) {
- if (this.isGood(vqt))
- goodCount++;
- else if (this.isBad(vqt))
- badCount++;
- else
- unCertain++;
- if (vqt.Value != null) {
- var val = this.GetNumber(vqt);
- if (minVqt == null || val < this.GetNumber(minVqt))
- minVqt = vqt;
- if (maxVqt == null || val > this.GetNumber(maxVqt))
- maxVqt = vqt;
- if (prevVQT && prevVQT.Value != null) {
- var dt = (vqt.StampTime - prevVQT.StampTime);
- sum += 0.5 * (val + this.GetNumber(prevVQT)) * dt;
- det += dt;
- }
- }
- prevVQT = vqt;
- } else if (vqt.StampTime < begTime)
- prevVQT = vqt;
- }
- }
- if (det != 0.0)
- avg = sum / det;
- else
- avg = null;
- var fix = false;
- var bIsBoolen = false;
- if (minVqt) {
- if (this.isString(minVqt) || this.isBoolen(minVqt)) {
- if (this.options.stepLine == null)
- this.setStepLine(true, true);
- }
- if (isNaN(min)) {
- if (this.isBoolen(maxVqt))
- min = -1;
- else
- min = this.GetNumber(minVqt);
- } else if (!this.options.lockRange && (this.commAxis == null || this.commAxis.length == 0)) {
- if (min > this.GetNumber(minVqt)) {
- min = this.GetNumber(minVqt);
- fix = true;
- }
- }
- }
- if (maxVqt) {
- if (this.isString(maxVqt) || this.isBoolen(maxVqt)) {
- if (this.options.stepLine == null)
- this.setStepLine(true, true);
- }
- if (isNaN(max)) {
- if (this.isBoolen(maxVqt))
- max = 5;
- else
- max = this.GetNumber(maxVqt);
- } else if (!this.options.lockRange && (this.commAxis == null || this.commAxis.length == 0)) {
- if (max < this.GetNumber(maxVqt)) {
- max = this.GetNumber(maxVqt);
- fix = true;
- }
- }
- }
-
-
-
-
- min = this.GetNumber(minVqt);
- max = this.GetNumber(maxVqt);
- (function () {
- var diff = Math.abs(max - min);
- if (diff === 0 && avg !== 0) {
- diff = avg * 0.2;
- } else if (diff === 0 && avg === 0) {
- diff = 250;
- }
- min = min - diff * 0.2;
- max = max + diff * 0.2;
- })();
-
- if (this.rtChart && this.rtChart.options && this.rtChart.options.freeRange) {
- this.setRange(min, max);
- } else {
- min = this.rageMin || 0;
- max = this.rageMax || 1000;
- this.setRange(this.rageMin, this.rageMax);
- }
- if (this.avg != avg) {
- this.avgChanged = true;
- this.rtChart.UpdateDataPan((this.avg == null || avg == null) ? true : false);
- this.avg = avg;
- this.rtChart._updateList(this.rowId, "平均值", this.getAVGList());
- if (!this.preventTooltipUpdate && this.showTolltip && this.toolTipAt == "avg" && !(this.requestLogin === true))
- this.rtChart.UpdateTooltip(this.getAVGTooltip());
- }
- if (this.minVqt != minVqt) {
- this.minChanged = true;
- this.rtChart.UpdateDataPan((this.minVqt == null || minVqt == null) ? true : false);
- this.minVqt = minVqt;
- if (!this.preventTooltipUpdate && this.showTolltip && this.toolTipAt == "minVQT" && !(this.requestLogin === true))
- this.rtChart.UpdateTooltip(this.getMinVQTTooltip());
- this.rtChart._updateList(this.rowId, "最小值", this.getMinVQTList());
- }
- if (this.maxVqt != maxVqt) {
- this.maxChanged = true;
- this.rtChart.UpdateDataPan((this.maxVqt == null || maxVqt == null) ? true : false);
- this.maxVqt = maxVqt;
- if (!this.preventTooltipUpdate && this.showTolltip && this.toolTipAt == "maxVQT" && !(this.requestLogin === true))
- this.rtChart.UpdateTooltip(this.getMaxVQTTooltip());
- this.rtChart._updateList(this.rowId, "最大值", this.getMaxVQTList());
- }
- if (this.maxVqt == null && this.minVqt == null)
- this.setHisStatus("nodata", "查询不到有效的历史数据");
- this.updateDataReader();
- }
- },
- drawTrendLine: function (ctx, begTime, endTime, gw, gh, timeScale, shadowOffset) {
- if (!this.hisData || !this.hisData.length || !this.options.drawLine || this.rageMax == null || this.rageMin == null || this.rageMin == this.rageMax)
- return;
- var bStep = this.options.stepLine === true;
- if (bStep)
- ctx.lineJoin = 'miter';
- else
- ctx.lineJoin = 'round';
- if (shadowOffset == null)
- shadowOffset = 0;
- ctx.beginPath();
- if (!shadowOffset) {
- ctx.lineWidth = (this.options.penWidth || 1);
- ctx.strokeStyle = this.options.penColor;
- } else
- ctx.lineWidth = (this.options.penWidth || 1) + 3;
- var yScale = -gh / (this.rageMax - this.rageMin);
- var yBase = gh;
- var bPrev = false;
- var x, y, px, py;
- var len = this.hisData.length;
- for (var i = 0; i < len; i++) {
- var vqt = this.hisData[i];
- if (vqt != null && vqt.Value != null) {
- x = Math.floor((vqt.StampTime - begTime) * timeScale);
- py = y;
- y = Math.floor(yBase + (this.GetNumber(vqt) - this.rageMin) * yScale) + shadowOffset;
- if (bPrev) {
- if (!bStep)
- ctx.lineTo(x, y);
- else {
- ctx.lineTo(x + shadowOffset / 2, py);
- ctx.lineTo(x + shadowOffset / 2, y);
- }
- } else
- ctx.moveTo(x, y);
- if (this.options.drawTag) {
- ctx.arc(x, y, 4, 0, 2 * Math.PI, false);
- ctx.moveTo(x - 4, y);
- ctx.lineTo(x + 4, y);
- ctx.moveTo(x, y - 4);
- ctx.lineTo(x, y + 4);
- ctx.moveTo(x, y);
- }
- bPrev = true;
- } else {
- if (this.options.drawTag) {
- x = Math.floor((vqt.StampTime - begTime) * timeScale);
- y = Math.floor(yBase + 0, 5 * (this.rageMax - this.rageMin) * yScale) + shadowOffset;
- ctx.moveTo(x - 4, y - 4);
- ctx.lineTo(x + 4, y + 4);
- ctx.moveTo(x - 4, y + 4);
- ctx.lineTo(x + 4, y - 4);
- ctx.arc(x, y, 6, 0, 2 * Math.PI, false);
- ctx.moveTo(x, y);
- }
- bPrev = false;
- }
- if (vqt.StampTime > endTime)
- break;
- }
- ctx.stroke();
- },
- drawThumbsTrendLine: function (ctx, begTime, endTime, gh, gt, h, timeScale) {
- if (!this.hisData || !this.hisData.length || !this.options.drawLine || this.rageMax == null || this.rageMin == null || this.rageMin == this.rageMax)
- return;
- ctx.strokeStyle = this.options.penColor;
- var bStep = this.options.stepLine === true;
- if (bStep)
- ctx.lineJoin = 'miter';
- else
- ctx.lineJoin = 'round';
- ctx.beginPath();
- var scale = h / gh;
- var yScale = -gh * scale / (this.rageMax - this.rageMin);
- var yBase = gt + h;
- var bPrev = false;
- var x, y, py;
- var len = this.hisData.length;
- for (var i = 0; i < len; i++) {
- var vqt = this.hisData[i];
- if (vqt != null && vqt.value != null) {
- x = Math.floor((vqt.StampTime - begTime) * timeScale);
- py = y;
- y = Math.floor(yBase + (this.GetNumber(vqt) - this.rageMin) * yScale);
- if (bPrev) {
- if (!bStep)
- ctx.lineTo(x, y);
- else {
- ctx.lineTo(x, py);
- ctx.lineTo(x, y);
- }
- } else
- ctx.moveTo(x, y);
- bPrev = true;
- } else
- bPrev = false;
- }
- ctx.stroke();
- }
- };
- TrendColor.prototype = {
- scale: function (rf, gf, bf, af) {
- var x = 4;
- while (-1 < --x) {
- if (!(arguments[x] === void 0)) this[this.rgba[x]] *= arguments[x];
- }
- return this.normalize();
- },
- alpha: function (alpha) {
- if (!(alpha === void 0) && !(alpha === null)) {
- this.a = alpha;
- }
- return this.normalize();
- },
- clone: function () {
- return new TrendColor(this.r, this.b, this.g, this.a);
- },
- limit: function (val, minVal, maxVal) {
- return Math.max(Math.min(val, maxVal), minVal);
- },
- normalize: function () {
- var limit = this.limit;
- this.r = limit(parseInt(this.r, 10), 0, 255);
- this.g = limit(parseInt(this.g, 10), 0, 255);
- this.b = limit(parseInt(this.b, 10), 0, 255);
- this.a = limit(this.a, 0, 1);
- return this;
- },
- distance: function (color) {
- if (!color) return;
- color = new TrendColor.parse(color);
- var dist = 0,
- x = 3;
- while (-1 < --x) {
- dist += Math.abs(this[this.rgba[x]] - color[this.rgba[x]]);
- }
- return dist;
- },
- toString: function () {
- return (this.a >= 1.0) ? 'rgb(' + [this.r, this.g, this.b].join(',') + ')' : 'rgba(' + [this.r, this.g, this.b, this.a].join(',') + ')';
- },
- toRGBAString: function () {
- return 'rgba(' + [this.r, this.g, this.b, this.a].join(',') + ')';
- },
- contrast: function () {
- var
- test = 1 - (0.299 * this.r + 0.587 * this.g + 0.114 * this.b) / 255;
- return (test < 0.5 ? '#000000' : '#ffffff');
- }
- };
- })(jQuery);
|