trendChartSmallWindow.js 339 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240
  1. (function ($) {
  2. /*constant*/
  3. var MINPANWIDTH = 110;
  4. var SLIDEHEIGHT = 30;
  5. var PANMAG = 5;
  6. var PANHEAD = 10;
  7. var INDICTWIDTH = 12;
  8. var PERMSEC = 10000;
  9. var PERSEC = 10000000;
  10. var PERMINUTE = (PERSEC * 60);
  11. var PERHOUR = (PERMINUTE * 60);
  12. var PERDAY = (PERHOUR * 24);
  13. var SPANPAD = 6;
  14. var SPANLINEHEIGHT = 16;
  15. var BOTTOMBUTTONLEFT = 80;
  16. var SHOWTHUMBSHEIGHT = 32;
  17. var SLIDHLIMIT = 160;
  18. var SHOWTHUMBSHLIMT = 200;
  19. var SHOWTOOLBARHLIMIT = 232;
  20. var SHOWLISTHLIMT = 250;
  21. var TOOLBARHEIGHT = 32;
  22. var TIMELABELHEIGHT = 32;
  23. var MINLISTHEIGHT = 80;
  24. var HSPLITHEIGHT = 10;
  25. var ButtonImage = $(new Image()).attr('src', 'htm/rtchart/chartbuttons.png');
  26. var penColors = ['#00A8F0', '#5DB75D', '#FFFF00', '#FFA62F', '#E41B17', '#000066', '#A0D2FF', '#FF96FF',
  27. '#E0FFFF', '#388E8E', '#00EE00', '#CD3700', '#EEAD0E', '#6600CC', '#ADFF2F', '#663300'
  28. ];
  29. var COLOR_NAMES = {
  30. aqua: [0, 255, 255],
  31. azure: [240, 255, 255],
  32. beige: [245, 245, 220],
  33. black: [0, 0, 0],
  34. blue: [0, 0, 255],
  35. brown: [165, 42, 42],
  36. cyan: [0, 255, 255],
  37. darkblue: [0, 0, 139],
  38. darkcyan: [0, 139, 139],
  39. darkgrey: [169, 169, 169],
  40. darkgreen: [0, 100, 0],
  41. darkkhaki: [189, 183, 107],
  42. darkmagenta: [139, 0, 139],
  43. darkolivegreen: [85, 107, 47],
  44. darkorange: [255, 140, 0],
  45. darkorchid: [153, 50, 204],
  46. darkred: [139, 0, 0],
  47. darksalmon: [233, 150, 122],
  48. darkviolet: [148, 0, 211],
  49. fuchsia: [255, 0, 255],
  50. gold: [255, 215, 0],
  51. green: [0, 128, 0],
  52. indigo: [75, 0, 130],
  53. khaki: [240, 230, 140],
  54. lightblue: [173, 216, 230],
  55. lightcyan: [224, 255, 255],
  56. lightgreen: [144, 238, 144],
  57. lightgrey: [211, 211, 211],
  58. lightpink: [255, 182, 193],
  59. lightyellow: [255, 255, 224],
  60. lime: [0, 255, 0],
  61. magenta: [255, 0, 255],
  62. maroon: [128, 0, 0],
  63. navy: [0, 0, 128],
  64. olive: [128, 128, 0],
  65. orange: [255, 165, 0],
  66. pink: [255, 192, 203],
  67. purple: [128, 0, 128],
  68. violet: [128, 0, 128],
  69. red: [255, 0, 0],
  70. silver: [192, 192, 192],
  71. white: [255, 255, 255],
  72. yellow: [255, 255, 0]
  73. };
  74. dhtmlXCalendarObject.prototype.langData["cn"] = {
  75. dateformat: '%Y-%m-%d %H:%i:%s',
  76. monthesFNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
  77. monthesSNames: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
  78. daysFNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
  79. daysSNames: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
  80. weekstart: 1,
  81. weekname: "d"
  82. };
  83. var WebLink = function (weburl) {
  84. this.weburl = weburl;
  85. };
  86. var TrendPen = function (rtchart, options) {
  87. this.rtChart = rtchart;
  88. this.options = $.extend({
  89. URI: null,
  90. Num: 2,
  91. penColor: rtchart.getNextPenColor(),
  92. penWidth: 2,
  93. linkReTryTime: 1000,
  94. hisReTryTime: 20000,
  95. lockRange: false,
  96. expandAll: false,
  97. stepLine: null, //true|false
  98. drawTag: false,
  99. drawLine: true,
  100. webURL: GoldenRtWeb.getWebURL()
  101. }, options || {});
  102. this.hisRequestSeed = 1;
  103. if (this.options.rageMax != null)
  104. this.rageMax = this.options.rageMax;
  105. if (this.options.rageMin != null)
  106. this.rageMin = this.options.rageMin;
  107. var r = Math.abs(this.rageMax - this.rageMin);
  108. if (r < 1) {
  109. if (r > 0.1) {
  110. if (this.options.Num < 3)
  111. this.options.Num = 3;
  112. } else if (r > 0.01) {
  113. if (this.options.Num < 4)
  114. this.options.Num = 4;
  115. } else if (r > 0.001) {
  116. if (this.options.Num < 5)
  117. this.options.Num = 5;
  118. } else if (this.options.Num < 6)
  119. this.options.Num = 6;
  120. }
  121. };
  122. var TrendColor = function (r, g, b, a) {
  123. this.rgba = ['r', 'g', 'b', 'a'];
  124. var x = 4;
  125. while (-1 < --x) {
  126. this[this.rgba[x]] = arguments[x] || ((x == 3) ? 1.0 : 0);
  127. }
  128. this.normalize();
  129. }
  130. TrendColor.parse = function (color) {
  131. if (color instanceof TrendColor) return color;
  132. var result;
  133. // #a0b1c2
  134. if ((result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color)))
  135. return new TrendColor(parseInt(result[1], 16), parseInt(result[2], 16), parseInt(result[3], 16));
  136. // rgb(num,num,num)
  137. if ((result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color)))
  138. return new TrendColor(parseInt(result[1], 10), parseInt(result[2], 10), parseInt(result[3], 10));
  139. // #fff
  140. if ((result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color)))
  141. return new TrendColor(parseInt(result[1] + result[1], 16), parseInt(result[2] + result[2], 16), parseInt(result[3] + result[3], 16));
  142. // rgba(num,num,num,num)
  143. 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)))
  144. return new TrendColor(parseInt(result[1], 10), parseInt(result[2], 10), parseInt(result[3], 10), parseFloat(result[4]));
  145. // rgb(num%,num%,num%)
  146. if ((result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color)))
  147. return new TrendColor(parseFloat(result[1]) * 2.55, parseFloat(result[2]) * 2.55, parseFloat(result[3]) * 2.55);
  148. // rgba(num%,num%,num%,num)
  149. 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)))
  150. return new TrendColor(parseFloat(result[1]) * 2.55, parseFloat(result[2]) * 2.55, parseFloat(result[3]) * 2.55, parseFloat(result[4]));
  151. // Otherwise, we're most likely dealing with a named color.
  152. var name = (color + '').replace(/^\s*([\S\s]*?)\s*$/, '$1').toLowerCase();
  153. if (name == 'transparent') {
  154. return new TrendColor(255, 255, 255, 0);
  155. }
  156. return (result = COLOR_NAMES[name]) ? new TrendColor(result[0], result[1], result[2]) : new TrendColor(0, 0, 0, 0);
  157. };
  158. TrendColor.processColor = function (color, options) {
  159. var opacity = options.opacity;
  160. if (!color) return 'rgba(0, 0, 0, 0)';
  161. if (color instanceof TrendColor) return color.alpha(opacity).toString();
  162. if (_.isString(color)) return TrendColor.parse(color).alpha(opacity).toString();
  163. var grad = color.colors ? color : {
  164. colors: color
  165. };
  166. if (!options.ctx) {
  167. if (!_.isArray(grad.colors)) return 'rgba(0, 0, 0, 0)';
  168. return TrendColor.parse(_.isArray(grad.colors[0]) ? grad.colors[0][1] : grad.colors[0]).alpha(opacity).toString();
  169. }
  170. grad = _.extend({
  171. start: 'top',
  172. end: 'bottom'
  173. }, grad);
  174. if (/top/i.test(grad.start)) options.x1 = 0;
  175. if (/left/i.test(grad.start)) options.y1 = 0;
  176. if (/bottom/i.test(grad.end)) options.x2 = 0;
  177. if (/right/i.test(grad.end)) options.y2 = 0;
  178. var i, c, stop, gradient = options.ctx.createLinearGradient(options.x1, options.y1, options.x2, options.y2);
  179. for (i = 0; i < grad.colors.length; i++) {
  180. c = grad.colors[i];
  181. if (_.isArray(c)) {
  182. stop = c[0];
  183. c = c[1];
  184. } else stop = i / (grad.colors.length - 1);
  185. gradient.addColorStop(stop, TrendColor.parse(c).alpha(opacity));
  186. }
  187. return gradient;
  188. };
  189. $.widget("rtinfo.trendChart", {
  190. options: {
  191. rtRefresh: true,
  192. showAxis: true,
  193. showGrid: true,
  194. showThumbs: true,
  195. showList: true,
  196. panShow: true,
  197. listExpand: true,
  198. reservePrevData: 10,
  199. spanSec: 10 * 60, //200s
  200. pointGroupName: null,
  201. freeRange: true, // 自由量程
  202. panWidth: MINPANWIDTH + 50,
  203. listHeight: MINLISTHEIGHT + 50,
  204. activeShadowSize: 4,
  205. tooltipDelay: 1000,
  206. gridColor: 'rgba(91,91,91,1.0)',
  207. borderColor: 'rgba(120,120,120,1.0)',
  208. timeLabelColor: 'rgba(214,214,214,1.0)',
  209. indicatorColor: 'rgba(210,210,210,0.5)',
  210. bkColor: 'rgba(0,0,0,1.0)',
  211. buttonImage: ButtonImage,
  212. resolution: 1 // => resolution of the graph, to have printer-friendly graphs !
  213. },
  214. btipShow: false,
  215. tipShowPen: null,
  216. vIndicator: null,
  217. hIndicator: null,
  218. chartWidth: 0,
  219. chartHeight: 0,
  220. ftBeginTime: 0,
  221. ftTimeLabelBeg: null,
  222. ctx: null,
  223. canvas: null,
  224. buttonsDrawed: false,
  225. trendPens: null,
  226. webLinks: null,
  227. _create: function () {
  228. console.log('_create');
  229. //判断测点组
  230. var configs = localStorage.getItem("goldenTrendConfig");
  231. if (configs) {
  232. try {
  233. configs = JSON.parse(configs);
  234. } catch (ex) {
  235. localStorage.removeItem("goldenTrendConfig");
  236. configs = null;
  237. }
  238. var config = configs[groupName];
  239. if (config != null && typeof (config) != "undefined") {
  240. // groupName = Object.keys(configs)[0];
  241. // config = configs[groupName];
  242. this.options.bDeafult = config.bDeafult;
  243. this.options.bkColor = config.bkColor;
  244. this.options.borderColor = config.borderColor;
  245. this.options.gridColor = config.gridColor;
  246. this.options.indicatorColor = config.indicatorColor;
  247. this.options.listExpand = config.listExpand;
  248. this.options.listHeight = config.listHeight;
  249. this.options.panShow = config.panShow;
  250. this.options.panWidth = config.panWidth;
  251. this.options.rtRefresh = config.rtRefresh;
  252. this.options.showAxis = config.showAxis;
  253. this.options.showGrid = config.showGrid;
  254. this.options.showList = config.showList;
  255. this.options.showThumbs = config.showThumbs;
  256. this.options.spanSec = config.spanSec;
  257. this.options.timeLabelColor = config.timeLabelColor;
  258. this.options.tooltipDelay = config.tooltipDelay;
  259. this.options.freeRange = config.freeRange;
  260. }
  261. }
  262. this.options.spanSec = this.options.spanSec || 1;
  263. if (!this.options.spanSec || this.options.spanSec < 1)
  264. this.options.spanSec = 1;
  265. var date = new Date();
  266. date.setMilliseconds(0);
  267. date = this.DateToFileTime(date);
  268. date += PERSEC;
  269. date -= this.options.spanSec * PERSEC;
  270. this.setBeginTime(date);
  271. this._buildChart();
  272. this.element.uniqueId();
  273. $(window).resize(this, function (e) {
  274. e.data._onResize();
  275. });
  276. this.yScroll = 0;
  277. var rtchart = this;
  278. var X, Y;
  279. $(document).bind('mousemove.rtChart_' + this.element.attr('id'), function (e) {
  280. if (X === e.clientX && Y === e.clientY)
  281. return;
  282. X = e.clientX;
  283. Y = e.clientY;
  284. if (rtchart.mouseTimer) {
  285. window.clearTimeout(rtchart.mouseTimer);
  286. rtchart.mouseTimer = null;
  287. }
  288. if (rtchart.tooltipTimer && e.target != rtchart.vIndicator[0] && e.target != rtchart.hIndicator[0]) {
  289. window.clearTimeout(rtchart.tooltipTimer);
  290. rtchart.tooltipTimer = null;
  291. }
  292. if (e.target == rtchart.canvas[0]) {
  293. rtchart.mouseTimer = window.setTimeout(function () {
  294. window.clearTimeout(rtchart.mouseTimer);
  295. rtchart.mouseTimer = null;
  296. rtchart._onMouseMove(e);
  297. }, 200);
  298. }
  299. });
  300. $(window).bind('keydown.rtChart_' + this.element.attr('id'), function (e) {
  301. rtchart._onKeyDown(e);
  302. });
  303. var url = location.href;
  304. var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
  305. var paraObj = {}
  306. for (i = 0; j = paraString[i]; i++) {
  307. paraObj[decodeURIComponent(j.substring(0, j.indexOf("=")))] = decodeURIComponent(j.substring(j.indexOf("=") + 1, j.length));
  308. }
  309. if (paraObj.pointGroupName != null)
  310. this.options.pointGroupName = paraObj.pointGroupName;
  311. if (this.options.pointGroupName == null) {
  312. if (paraObj.pointGroupName != null)
  313. this.options.pointGroupName = paraObj.pointGroupName;
  314. else if (paraObj.newPointGroup != null) {
  315. this.isNewPage = true;
  316. var d = dialog({
  317. content: "可以在新打开的页中进行点组的设置操作,然后保存点组,<br>从而创建新的点组。",
  318. quickClose: true
  319. });
  320. d.show();
  321. window.setTimeout(function () {
  322. d.close().remove();
  323. d = null;
  324. }, 2000);
  325. }
  326. }
  327. if (typeof (Flag) != "undefined" && Flag != null || Flag != "") {
  328. if (Flag == "tagName") {
  329. if (typeof (tagName) != "undefined" && tagName != null || tagName != "") {
  330. var that = this;
  331. (function () {
  332. tagName = decodeURIComponent(tagName);
  333. var tagNameArr = tagName.split(',');
  334. for (var i = 0, len = tagNameArr.length; i < len; i++) {
  335. tagName = tagNameArr[i];
  336. var itemDef = new GoldenRtWeb.RtItemDefine(0, 0, 0);
  337. that.AddPen({
  338. URI: tagName,
  339. itemDef: itemDef
  340. });
  341. that.requestHisData({
  342. URI: tagName,
  343. itemDef: itemDef
  344. }, 100);
  345. }
  346. })();
  347. }
  348. } else {
  349. if (typeof (groupName) != "undefined" && groupName != null || groupName != "") {
  350. if (Flag == "pointGroupName") {
  351. var that = this;
  352. (function () {
  353. groupName = decodeURIComponent(groupName);
  354. var pointGroups = JSON.parse(localStorage.getItem("goldenTrendConfig"));
  355. //console.log(pointGroups);
  356. for (var key in pointGroups) {
  357. if (groupName == key) {
  358. for (var i = 0; i < pointGroups[key].trendPens.length; i++) {
  359. // tagName=pointGroups[key].trendPens[i].URI;
  360. that.AddPen(pointGroups[key].trendPens[i]);
  361. }
  362. }
  363. }
  364. })();
  365. }
  366. }
  367. }
  368. }
  369. //if(!this.isNewPage)
  370. //this._loadPointGroup();
  371. },
  372. _loadPointGroup: function () {
  373. var groupName = "";
  374. if (this.options.pointGroupName != null)
  375. groupName = this.options.pointGroupName;
  376. var rtchart = this;
  377. var configs = localStorage.getItem("goldenTrendConfig");
  378. if (configs == null)
  379. return;
  380. if (configs) {
  381. try {
  382. configs = JSON.parse(configs);
  383. } catch (ex) {
  384. localStorage.removeItem("goldenTrendConfig");
  385. configs = null;
  386. }
  387. }
  388. var config = configs[groupName];
  389. if (config == null) {
  390. groupName = Object.keys(configs)[0];
  391. config = configs[groupName];
  392. }
  393. this.loadConfig(groupName, config);
  394. },
  395. _init: function () {
  396. console.log('_init');
  397. },
  398. _destroy: function () {
  399. console.log('_destroy');
  400. $(document).unbind('mousemove.rtChart_' + this.element.attr('id'));
  401. $(document).unbind('keydown.rtChart_' + this.element.attr('id'));
  402. this._clear();
  403. if (this.webLinks) {
  404. for (i in this.webLinks) {
  405. var link = this.webLinks[i];
  406. link.destroy();
  407. delete link;
  408. }
  409. delete this.webLinks;
  410. }
  411. if (this.trendPens) {
  412. for (i in this.trendPens) {
  413. var pen = this.trendPens[i];
  414. pen.destroy();
  415. delete pen;
  416. }
  417. delete this.trendPens;
  418. }
  419. },
  420. _isTouch: function () {
  421. return document.ontouchstart !== undefined;
  422. },
  423. _buildChart: function () {
  424. this._clear();
  425. this._bulidCanvas();
  426. console.log('chartBuided');
  427. },
  428. _clear: function () {
  429. this.btipShow = false;
  430. if (this.artTooltip)
  431. this.artTooltip.close().remove();
  432. if (this.tooltipTimer) {
  433. window.clearTimeout(this.tooltipTimer);
  434. this.tooltipTimer = null;
  435. }
  436. if (this.updateDataTimer) {
  437. window.clearTimeout(this.updateDataTimer);
  438. this.updateDataTimer = null;
  439. }
  440. if (this.updatePanTimer) {
  441. window.clearTimeout(this.updatePanTimer);
  442. this.updatePanTimer = null;
  443. }
  444. if (this.prepareTimer) {
  445. window.clearTimeout(this.prepareTimer);
  446. this.prepareTimer = null;
  447. }
  448. if (this.mouseTimer) {
  449. window.clearTimeout(this.mouseTimer);
  450. this.mouseTimer = null;
  451. }
  452. if (this.options.buttonImage)
  453. this.options.buttonImage.unbind();
  454. if (this.tipShowPen) {
  455. this.tipShowPen.onTooltipHided();
  456. this.tipShowPen = null;
  457. }
  458. if (this.activePen) {
  459. this.activePen.setActive(false);
  460. this.activePen = null;
  461. if (this.toolBar)
  462. this.toolBar.disableItem("deletePoint");
  463. }
  464. if (this.colorPicker) {
  465. $('.colorpicker-ind', this.colorPicker).colorpicker('destroy');
  466. this.colorPicker.draggable("destroy");
  467. this.colorPicker.empty();
  468. delete this.colorPicker;
  469. }
  470. if (this.vSplite) {
  471. if (this.vSplite.data('drag') === true)
  472. this.vSplite.draggable("destroy");
  473. this.vSplite.unbind();
  474. this.vSplite = null;
  475. }
  476. if (this.hSplite) {
  477. if (this.hSplite.data('drag') === true)
  478. this.hSplite.draggable("destroy");
  479. this.hSplite.unbind();
  480. this.hSplite = null;
  481. }
  482. if (this.vIndicator) {
  483. this.vIndicator.unbind();
  484. this.vIndicator.draggable("destroy");
  485. this.vIndicator = null;
  486. }
  487. if (this.hIndicator) {
  488. this.hIndicator.unbind();
  489. this.hIndicator.draggable("destroy");
  490. this.hIndicator = null;
  491. }
  492. if (this.ctx)
  493. delete this.ctx;
  494. if (this.canvas) {
  495. this.canvas.unbind();
  496. delete this.canvas;
  497. }
  498. if (this.toolCalendar) {
  499. this.toolCalendar.unload();
  500. delete this.toolCalendar;
  501. }
  502. if (this.toolBar) {
  503. this.toolBar.unload();
  504. this.toolBar = null;
  505. }
  506. if (this.toolBarContainer) {
  507. this.toolBarContainer.remove();
  508. this.toolBarContainer = null;
  509. }
  510. if (this.artTooltip) {
  511. this.artTooltip.remove();
  512. delete this.artTooltip;
  513. }
  514. if (this.positionDiv) {
  515. this.positionDiv.unbind();
  516. this.positionDiv.draggable("destroy");
  517. this.positionDiv.remove();
  518. this.positionDiv = null;
  519. }
  520. if (this.thumbBegDiv) {
  521. this.thumbBegDiv.unbind();
  522. this.thumbBegDiv.draggable("destroy");
  523. this.thumbBegDiv.remove();
  524. this.thumbBegDiv = null;
  525. }
  526. if (this.thumbEndDiv) {
  527. this.thumbEndDiv.unbind();
  528. this.thumbEndDiv.draggable("destroy");
  529. this.thumbEndDiv.remove();
  530. this.thumbEndDiv = null;
  531. }
  532. this.buttonsDrawed = false;
  533. if (this.listGrid) {
  534. this.listGrid.clearAll(true);
  535. this.listGrid.destructor();
  536. delete this.listGrid;
  537. }
  538. if (this.listContainer) {
  539. this.listContainer.remove();
  540. this.listContainer = null;
  541. }
  542. this.element.empty();
  543. },
  544. _bulidCanvas: function () {
  545. this.chartWidth = this.element.width();
  546. this.chartHeight = this.element.height();
  547. if (!this.chartWidth || !this.chartHeight)
  548. throw 'container not visable\'t exist';
  549. var gw = this.getGridWidth();
  550. var gh = this.getGridHeight();
  551. var gt = this.toolBarCanShow() ? TOOLBARHEIGHT : 0;
  552. var cavansHight = gh;
  553. if (this.slidCanShow())
  554. cavansHight += SLIDEHEIGHT;
  555. if (this.thumbsCanshow())
  556. cavansHight += SHOWTHUMBSHEIGHT;
  557. if (this.listCanshow())
  558. if (this.chartWidth < 100 + this.options.panWidth || this.options.panWidth < MINPANWIDTH)
  559. this.options.panShow = false;
  560. var rtchart = this;
  561. if (!this.canvas) {
  562. this.canvas = $(document.createElement('canvas'));
  563. this.element.append(this.canvas);
  564. this.canvas.bind('click', function (e) {
  565. rtchart._onClick(e);
  566. });
  567. this.canvas.bind('dblclick', function (e) {
  568. rtchart._ondbClick(e);
  569. });
  570. this.canvas.bind('mousedown', function (e) {
  571. rtchart._onMouseDown(e);
  572. });
  573. this.canvas.bind('mousewheel', function (e) {
  574. e.preventDefault();
  575. rtchart._onMouseWheel(e);
  576. });
  577. this.canvas.bind('mousemove', function (e) {
  578. rtchart._onRtchartMouseMove(e);
  579. });
  580. if (this._isTouch()) {
  581. this.canvas.bind('touchstart', function (e) {
  582. rtchart._onTouchStart(e);
  583. });
  584. }
  585. }
  586. this.canvas.css("position", "absolute")
  587. .css("left", 0)
  588. .css("top", gt)
  589. .css("right", 0)
  590. .css("height", cavansHight);
  591. if (this.options.bkColor != null)
  592. this.canvas.css('background-color', this.options.bkColor);
  593. this.canvas.attr("width", this.chartWidth * this.options.resolution);
  594. this.canvas.attr("height", cavansHight * this.options.resolution);
  595. var node = this.canvas.get(0);
  596. if (window.G_vmlCanvasManager)
  597. window.G_vmlCanvasManager.initElement(node); // For ExCanvas
  598. this.ctx = node.getContext('2d');
  599. if (!window.G_vmlCanvasManager)
  600. this.ctx.scale(this.options.resolution, this.options.resolution);
  601. if (this.positionDiv) {
  602. this.positionDiv.draggable("destroy");
  603. this.positionDiv.unbind();
  604. this.positionDiv.remove();
  605. this.positionDiv = null;
  606. }
  607. if (this.thumbBegDiv) {
  608. this.thumbBegDiv.draggable("destroy");
  609. this.thumbBegDiv.unbind();
  610. this.thumbBegDiv.remove();
  611. this.thumbBegDiv = null;
  612. }
  613. if (this.thumbEndDiv) {
  614. this.thumbEndDiv.draggable("destroy");
  615. this.thumbEndDiv.unbind();
  616. this.thumbEndDiv.remove();
  617. this.thumbEndDiv = null;
  618. }
  619. if (this.toolBarContainer == null) {
  620. this.toolBarContainer = $(document.createElement('div'));
  621. this.element.append(this.toolBarContainer);
  622. }
  623. this.toolBarContainer.css("position", "absolute")
  624. .css("left", 0)
  625. .css("top", -2)
  626. .css("right", 0)
  627. .css("height", TOOLBARHEIGHT)
  628. .addClass('unselectable');
  629. this.calendarShowed = false;
  630. this.timerFocus = false;
  631. if (this.toolBar == null) {
  632. this.toolBar = new dhtmlXToolbarObject(this.toolBarContainer.get(0), "dhx_web");
  633. this.toolBar.setIconsPath("htm/codebase/dhtmlxToolbar/codebase/icon/");
  634. this.toolBar.addButton("addPoint", 0, null, "plus.png", "plus_dis.png");
  635. this.toolBar.setItemToolTip("addPoint", "添加新点");
  636. this.toolBar.addButton("deletePoint", 1, null, "deletepen.png", "deletepen_dis.png");
  637. this.toolBar.setItemToolTip("deletePoint", "移除当前选定点");
  638. this.toolBar.disableItem("deletePoint");
  639. if (this.options.showAxis) {
  640. this.toolBar.addButtonTwoState("showAxis", 2, null, "axis.png", "axis_dis.png");
  641. this.toolBar.setItemState("showAxis", true);
  642. this.toolBar.setItemToolTip("showAxis", "当前为值轴显示模式,单击转变为数据板显示模式");
  643. } else {
  644. this.toolBar.addButtonTwoState("showAxis", 2, null, "datapan.png", "datapan_dis.png");
  645. this.toolBar.setItemState("showAxis", false);
  646. this.toolBar.setItemToolTip("showAxis", "当前为数据板显示模式,单击转变为值轴显示模式");
  647. }
  648. if (this.options.freeRange) {
  649. this.toolBar.addButtonTwoState("toggleRange", 3, null, "view_type_free.png", "view_type_free.png");
  650. this.toolBar.setItemState("toggleRange", true);
  651. this.toolBar.setItemToolTip("toggleRange", "当前量程为自由量程,点击切换到固定量程");
  652. } else {
  653. this.toolBar.addButtonTwoState("toggleRange", 3, null, "view_type.png", "view_type.png");
  654. this.toolBar.setItemState("toggleRange", false);
  655. this.toolBar.setItemToolTip("toggleRange", "当前量程为固定量程,点击切换到自由量程");
  656. }
  657. this.toolBar.addButton("colorPicker", 4, null, "colorpicker.png", "colorpicker_dis.png");
  658. this.toolBar.setItemToolTip("colorPicker", "设置颜色");
  659. this.toolBar.addButton("saveConfig", 4, null, "save.png", "save.png");
  660. this.toolBar.setItemToolTip("saveConfig", "保存设置(如改变点组名称,可另存新建点组)");
  661. var opts =
  662. [
  663. ['newPiointGroup', 'obj', '新建点组', 'window_new.png'],
  664. ['editorPointGroup', 'obj', '编辑点组...', 'tag_blue_edit.png'],
  665. ['refreshPointGroup', 'obj', '刷新点组列表', 'reload.png'],
  666. ['idsep', 'sep']
  667. ];
  668. this.toolBar.addButtonSelect("pointGroup", 5, "点组", opts, "tag.png");
  669. this.toolBar.addSeparator("rtSep", 6);
  670. //this.toolBar.addButtonTwoState("fullScreen", 7, null, "fullscreen.png", "fullscreen_dis.png");
  671. //this.toolBar.setItemState("fullScreen", false);
  672. //this.toolBar.setItemToolTip("fullScreen", "单击进入全屏显示模式(F11)");
  673. this.toolBar.addButton("zoomToool", 8, null, "zoom.png", "zoom_dis.png");
  674. this.toolBar.setItemToolTip("zoomToool", "趋势缩放");
  675. this.toolBar.addButton("zoomResume", 9, null, "zoom_resume.png", "zoom_resume_dis.png");
  676. this.toolBar.setItemToolTip("zoomResume", "恢复缩放");
  677. this.toolBar.disableItem("zoomResume");
  678. this.toolBar.addSeparator("rtSep4", 10);
  679. if (this.options.rtRefresh) {
  680. this.toolBar.addButtonTwoState("reRefresh", 11, null, "refresh.png", "refresh_dis.png");
  681. this.toolBar.setItemState("reRefresh", true);
  682. this.toolBar.setItemToolTip("reRefresh", "当前为实时刷新模式,单击转变为静态查询模式");
  683. } else {
  684. this.toolBar.addButtonTwoState("reRefresh", 11, null, "query.png", "query_dis.png");
  685. this.toolBar.setItemState("reRefresh", false);
  686. this.toolBar.setItemToolTip("reRefresh", "当前为静态查询模式,单击转变为实时刷新模式");
  687. }
  688. this.toolBar.addSeparator("rtSep1", 12);
  689. this.toolBar.addButton("timePrev", 13, null, "previous.png", "previous_dis.png");
  690. this.toolBar.setItemToolTip("timePrev", "前翻半个时间跨度");
  691. var spanopts = [
  692. ['b1m', 'obj', '当前时间 10分钟前', "left.png"],
  693. ['b3m', 'obj', '当前时间 30分钟前', "left.png"],
  694. ['b1h', 'obj', '当前时间 1小时前', "left.png"],
  695. ['b2h', 'obj', '当前时间 2小时前', "left.png"],
  696. ['b8h', 'obj', '当前时间 8小时前', "left.png"],
  697. ['b12h', 'obj', '当前时间 12小时前', "left.png"],
  698. ['spansep', 'sep'],
  699. ['b1d', 'obj', '当前时间 1天 前', "left.png"],
  700. ['b2d', 'obj', '当前时间 2天 前', "left.png"],
  701. ['b7d', 'obj', '当前时间 7天 前', "left.png"],
  702. //
  703. //['a1m', 'obj', '当前查询起始时间 10分钟后', "right.png"],
  704. //['a1h', 'obj', '当前查询起始时间 1小时后', "right.png"],
  705. //['a2h', 'obj', '当前查询起始时间 2小时后', "right.png"],
  706. //['a8h', 'obj', '当前查询起始时间 8小时后', "right.png"],
  707. //['a1d', 'obj', '当前查询起始时间 1天 后', "right.png"],
  708. //['a2d', 'obj', '当前查询起始时间 2天 后', "right.png"],
  709. //['a7d', 'obj', '当前查询起始时间 7天 后', "right.png"],
  710. ];
  711. this.toolBar.addButtonSelect("timeSpan", 14, this.getTimeSpanString(), spanopts, null);
  712. this.toolBar.addButton("timeNext", 15, null, "next.png", "next_dis.png");
  713. this.toolBar.setItemToolTip("timeNext", "后翻半个时间跨度");
  714. this.toolBar.addSeparator("rtSep2", 16);
  715. this.toolBar.addInput("date_from", 17, "", 128);
  716. this.toolBar.addInput("date_to", 18, "", 128);
  717. this._updateTimeDisplay();
  718. this.toolBar.addButton("goDate", 19, null, "find.png", "find_dis.png");
  719. this.toolBar.setItemToolTip("goDate", "点击执行查询");
  720. var from = this.toolBar.getInput("date_from");
  721. var to = this.toolBar.getInput("date_to");
  722. $(from).focusin(function () {
  723. rtchart.timerFocus = true;
  724. });
  725. $(to).focusin(function () {
  726. rtchart.timerFocus = true;
  727. });
  728. $(from).focusout(function () {
  729. rtchart.timerFocus = false;
  730. });
  731. $(to).focusout(function () {
  732. rtchart.timerFocus = false;
  733. });
  734. this.toolCalendar = new dhtmlXCalendarObject([from, to]);
  735. this.toolCalendar.setDateFormat("%Y-%m-%d %H:%i:%s"); //.%u
  736. this.toolCalendar.setMinutesInterval(1);
  737. this.toolCalendar.loadUserLanguage("cn");
  738. this._updateTimeDisplay();
  739. this.toolCalendar.attachEvent("onShow", function () {
  740. rtchart.calendarShowed = true;
  741. });
  742. this.toolCalendar.attachEvent("onHide", function () {
  743. rtchart.calendarShowed = false;
  744. });
  745. this.toolCalendar.attachEvent("onClick", function (date) {
  746. if (document.activeElement == $(from)[0]) {
  747. var button = document.activeElement.parentElement.nextElementSibling.nextElementSibling;
  748. var d = dialog({
  749. content: "点击按钮进行查询操作或进行其他查询设置,\n点击工具条空白处取消文本框编辑状态。",
  750. quickClose: true
  751. });
  752. d.show(button);
  753. window.setTimeout(function () {
  754. d.close().remove();
  755. d = null;
  756. }, 2000);
  757. } else if (document.activeElement == $(to)[0]) {
  758. var button = document.activeElement.parentElement.nextElementSibling;
  759. var d = dialog({
  760. content: "点击按钮进行查询操作或进行其他查询设置,\n点击工具条空白处取消文本框编辑状态。",
  761. quickClose: true
  762. });
  763. d.show(button);
  764. window.setTimeout(function () {
  765. d.close().remove();
  766. d = null;
  767. }, 2000);
  768. }
  769. });
  770. var excelopts = [
  771. ['exportToExcelInterpo', 'obj', '导出统一时间坐标的内插值', null],
  772. ['exportExcel', 'obj', '导出时间坐标不同的归档值', null]
  773. // ['exportImg', 'obj', '导出图片', null]
  774. ];
  775. this.toolBar.addButtonSelect("exportExceltool", 20, null, excelopts, "excel.png", "excel_dis.png");
  776. this.toolBar.setItemToolTip("exportExceltool", "导出");
  777. // this.toolBar.addButton("addGroup", 21, null, "tag_blue.png", "tag_blue.png");
  778. // this.toolBar.setItemToolTip("addGroup", "新建组");
  779. // this.toolBar.addButton("saveGroup", 22, null, "save.png", "save_dis.png");
  780. // this.toolBar.setItemToolTip("saveGroup", "保存组");
  781. // this.toolBar.addButton("queryGroup", 23, null, "tags.png", "tags.png");
  782. // this.toolBar.setItemToolTip("queryGroup", "测点组");
  783. this.toolBar.addButton("exportPng", 21, null, "mime_png.png", "mime_png.png");
  784. this.toolBar.setItemToolTip("exportPng", "导出打印位图");
  785. this.toolBar.addSeparator("rtSep3", 22);
  786. /*Button Command*/
  787. this.toolBar.attachEvent("onClick", function (id) {
  788. rtchart.timerFocus = false;
  789. rtchart.calendarShowed = false;
  790. $(from).blur();
  791. $(to).blur();
  792. switch (id) {
  793. case "addPoint":
  794. rtchart._onAddPoint();
  795. break;
  796. case "addGroup":
  797. if (rtchart.listGrid.getRowsNum()) {
  798. var pens = rtchart.listGrid.getRowsNum();
  799. for (var i = 1; i <= pens; i++) {
  800. var rowid = i;
  801. var pen = rtchart.getPenByRowId(rowid);
  802. if (pen)
  803. rtchart.removePen(pen);
  804. }
  805. }
  806. if (rtchart.artTooltip)
  807. rtchart.artTooltip.close().remove();
  808. break;
  809. case "saveGroup":
  810. rtchart._onSaveGroup();
  811. break;
  812. case "deletePoint":
  813. if (rtchart.listGrid.getSelectedRowId()) {
  814. var pens = rtchart.listGrid.getSelectedRowId();
  815. pens = pens.split(',');
  816. if (pens) {
  817. for (var i = 0; i < pens.length; i++) {
  818. var rowid = pens[i];
  819. var pen = rtchart.getPenByRowId(rowid);
  820. if (pen)
  821. rtchart.removePen(pen);
  822. }
  823. }
  824. }
  825. break;
  826. case "editorPointGroup":
  827. rtchart._onEditorPointGroup();
  828. break;
  829. case "colorPicker":
  830. rtchart._onSetColors();
  831. break;
  832. case "saveConfig":
  833. rtchart._onSaveConfig();
  834. break;
  835. case "exportExcel":
  836. rtchart._onExportExcel();
  837. break;
  838. case "exportToExcelInterpo":
  839. rtchart._onExportToExcelInterpo();
  840. break;
  841. case "exportPng":
  842. rtchart._onExportPng();
  843. break;
  844. case "mpass":
  845. rtchart._onModifyPassWord();
  846. break;
  847. case "accmag":
  848. rtchart._onUserMagement();
  849. break;
  850. case "login":
  851. rtchart.requestLogin("_login", true);
  852. break;
  853. case "logout":
  854. rtchart.logout();
  855. break;
  856. case "goDate":
  857. rtchart._queryHisData($(from), $(to));
  858. break;
  859. case "refreshPointGroup":
  860. rtchart._loadPointGroupNames();
  861. break;
  862. case "newPiointGroup":
  863. var url = location.href;
  864. if (url.indexOf("?") > 0)
  865. url = url.substr(0, url.indexOf("?"));
  866. url += "?webServiceIP=" + webServiceIP + "&webServicePort=" + webServicePort + "";
  867. url += "&newPointGroup=1";
  868. window.open(url, "_blank");
  869. break;
  870. case "zoomToool":
  871. rtchart._toggleZoom();
  872. break;
  873. case "zoomResume":
  874. rtchart._onReZoom();
  875. break;
  876. case "timePrev":
  877. rtchart.updateBeginTime(rtchart.getBegTime() - 0.5 * rtchart.options.spanSec * PERSEC);
  878. break;
  879. case "timeNext":
  880. rtchart.updateBeginTime(rtchart.getBegTime() + 0.5 * rtchart.options.spanSec * PERSEC);
  881. break;
  882. case 'b1m':
  883. var date = new Date();
  884. date.setMilliseconds(0);
  885. date = rtchart.DateToFileTime(date);
  886. date += PERSEC;
  887. date -= 600 * PERSEC;
  888. rtchart.setBegTimeAndSpan(date, 600);
  889. break;
  890. case 'b3m':
  891. var date = new Date();
  892. date.setMilliseconds(0);
  893. date = rtchart.DateToFileTime(date);
  894. date += PERSEC;
  895. date -= 1800 * PERSEC;
  896. rtchart.setBegTimeAndSpan(date, 1800);
  897. break;
  898. case 'b1h':
  899. var date = new Date();
  900. date.setMilliseconds(0);
  901. date = rtchart.DateToFileTime(date);
  902. date += PERSEC;
  903. date -= 3600 * PERSEC;
  904. rtchart.setBegTimeAndSpan(date, 3600);
  905. break;
  906. case 'b2h':
  907. var date = new Date();
  908. date.setMilliseconds(0);
  909. date = rtchart.DateToFileTime(date);
  910. date += PERSEC;
  911. date -= 2 * 3600 * PERSEC;
  912. rtchart.setBegTimeAndSpan(date, 2 * 3600);
  913. break;
  914. case 'b8h':
  915. var date = new Date();
  916. date.setMilliseconds(0);
  917. date = rtchart.DateToFileTime(date);
  918. date += PERSEC;
  919. date -= 8 * 3600 * PERSEC;
  920. rtchart.setBegTimeAndSpan(date, 8 * 3600);
  921. break;
  922. case 'b12h':
  923. var date = new Date();
  924. date.setMilliseconds(0);
  925. date = rtchart.DateToFileTime(date);
  926. date += PERSEC;
  927. date -= 12 * 3600 * PERSEC;
  928. rtchart.setBegTimeAndSpan(date, 12 * 3600);
  929. break;
  930. case 'b1d':
  931. var date = new Date();
  932. date.setMilliseconds(0);
  933. date = rtchart.DateToFileTime(date);
  934. date += PERSEC;
  935. date -= 24 * 3600 * PERSEC;
  936. rtchart.setBegTimeAndSpan(date, 24 * 3600);
  937. break;
  938. case 'b2d':
  939. var date = new Date();
  940. date.setMilliseconds(0);
  941. date = rtchart.DateToFileTime(date);
  942. date += PERSEC;
  943. date -= 2 * 24 * 3600 * PERSEC;
  944. rtchart.setBegTimeAndSpan(date, 2 * 24 * 3600);
  945. break;
  946. case 'b7d':
  947. var date = new Date();
  948. date.setMilliseconds(0);
  949. date = rtchart.DateToFileTime(date);
  950. date += PERSEC;
  951. date -= 7 * 24 * 3600 * PERSEC;
  952. rtchart.setBegTimeAndSpan(date, 7 * 24 * 3600);
  953. break;
  954. case 'a1m':
  955. rtchart.setTimeSpan(600, false);
  956. break;
  957. case 'a1h':
  958. rtchart.setTimeSpan(3600, false);
  959. break;
  960. case 'a2h':
  961. rtchart.setTimeSpan(2 * 3600, false);
  962. break;
  963. case 'a8h':
  964. rtchart.setTimeSpan(8 * 3600, false);
  965. break;
  966. case 'a1d':
  967. rtchart.setTimeSpan(24 * 3600, false);
  968. break;
  969. case 'a2d':
  970. rtchart.setTimeSpan(2 * 24 * 3600, false);
  971. break;
  972. case 'a7d':
  973. rtchart.setTimeSpan(7 * 24 * 3600, false);
  974. break;
  975. default:
  976. if (rtchart.pointGroups) {
  977. for (var n in rtchart.pointGroups) {
  978. var config = rtchart.pointGroups[n];
  979. if (id == config.Id) {
  980. var gName = n;
  981. if (gName && gName.length) {
  982. var url = location.href;
  983. if (url.indexOf("?") > 0)
  984. url = url.substr(0, url.indexOf("?"));
  985. url += "?webServiceIP=" + webServiceIP + "&webServicePort=" + webServicePort + "";
  986. url += "&pointGroupName=" + encodeURI(gName);
  987. if (rtchart.isFullScreen() === true)
  988. window.location.href = url;
  989. else
  990. window.open(url, "_blank");
  991. }
  992. break;
  993. }
  994. }
  995. break;
  996. }
  997. }
  998. });
  999. this.toolBar.attachEvent("onStateChange", function (id) {
  1000. switch (id) {
  1001. case "reRefresh":
  1002. if (rtchart.toolBar.getItemState("reRefresh"))
  1003. rtchart.setRtrefresh(true);
  1004. else
  1005. rtchart.setRtrefresh(false);
  1006. break;
  1007. case "showAxis":
  1008. if (rtchart.toolBar.getItemState("showAxis"))
  1009. rtchart.setShowAxis(true);
  1010. else
  1011. rtchart.setShowAxis(false);
  1012. break;
  1013. case "fullScreen":
  1014. rtchart.onFullScreenSet();
  1015. break;
  1016. case "toggleRange":
  1017. rtchart.toggleRangeMode();
  1018. break;
  1019. }
  1020. });
  1021. this._loadPointGroupNames();
  1022. var elem = document.documentElement;
  1023. if (elem.requestFullscreen) {
  1024. this.requestFullScreen = function () {
  1025. var docElm = document.documentElement;
  1026. docElm.requestFullscreen();
  1027. }
  1028. this.isFullScreen = function () {
  1029. return document.fullscreen;
  1030. }
  1031. } else if (elem.mozRequestFullScreen) {
  1032. this.requestFullScreen = function () {
  1033. var docElm = document.documentElement;
  1034. docElm.mozRequestFullScreen();
  1035. }
  1036. this.isFullScreen = function () {
  1037. return document.mozFullScreen;
  1038. }
  1039. } else if (elem.webkitRequestFullScreen) {
  1040. this.requestFullScreen = function () {
  1041. var docElm = document.documentElement;
  1042. docElm.webkitRequestFullScreen();
  1043. }
  1044. this.isFullScreen = function () {
  1045. return document.webkitIsFullScreen;
  1046. }
  1047. } else if (elem.msRequestFullscreen) {
  1048. this.requestFullScreen = function () {
  1049. var docElm = document.documentElement;
  1050. docElm.msRequestFullscreen();
  1051. }
  1052. this.isFullScreen = function () {
  1053. return document.msFullscreenElement;
  1054. }
  1055. }
  1056. if (document.exitFullscreen) {
  1057. this.cancelFullScreen = function () {
  1058. document.exitFullscreen();
  1059. }
  1060. } else if (document.mozCancelFullScreen) {
  1061. this.cancelFullScreen = function () {
  1062. document.mozCancelFullScreen();
  1063. }
  1064. } else if (document.webkitCancelFullScreen) {
  1065. this.cancelFullScreen = function () {
  1066. document.webkitCancelFullScreen();
  1067. }
  1068. } else if (document.msExitFullscreen) {
  1069. this.cancelFullScreen = function () {
  1070. document.msExitFullscreen();
  1071. }
  1072. }
  1073. }
  1074. this.positionDiv = $(document.createElement('div'));
  1075. this.element.append(this.positionDiv);
  1076. this.positionDiv.css("position", "absolute")
  1077. .css("left", 0)
  1078. .css("top", gt)
  1079. .css("width", 6)
  1080. .css("height", 6)
  1081. .css(" z-index", 200)
  1082. .addClass('unselectable')
  1083. .draggable({
  1084. disabled: true,
  1085. scroll: false,
  1086. containment: [
  1087. this.canvas.offset().left - 2,
  1088. this.canvas.offset().top + gt,
  1089. this.canvas.offset().left + this.canvas.width() - 5,
  1090. this.canvas.offset().top + gt + this.canvas.height()
  1091. ]
  1092. });
  1093. if (this.thumbsCanshow()) {
  1094. gt += gh + TIMELABELHEIGHT;
  1095. var h = SHOWTHUMBSHEIGHT + 3;
  1096. this.thumbBegDiv = $(document.createElement('div'));
  1097. this.element.append(this.thumbBegDiv);
  1098. this.thumbBegDiv.css("position", "absolute")
  1099. .css("left", -3)
  1100. .css("top", gt)
  1101. .css("width", 7)
  1102. .css("height", h)
  1103. .css("cursor", "e-resize")
  1104. .css(" z-index", 200)
  1105. .addClass('unselectable')
  1106. .addClass('hspelit')
  1107. .draggable({
  1108. containment: [this.canvas.offset().left - 3, 0, this.canvas.offset().left + this.chartWidth - 18, gh],
  1109. axis: "x",
  1110. scroll: false,
  1111. drag: function (event, ui) {
  1112. rtchart._onThumbsChanged();
  1113. }
  1114. });
  1115. this.thumbEndDiv = $(document.createElement('div'));
  1116. this.element.append(this.thumbEndDiv);
  1117. this.thumbEndDiv.css("position", "absolute")
  1118. .css("left", this.chartWidth - 3)
  1119. .css("top", gt)
  1120. .css("width", 7)
  1121. .css("height", h)
  1122. .css("cursor", "e-resize")
  1123. .css(" z-index", 200)
  1124. .addClass('unselectable')
  1125. .addClass('hspelit')
  1126. .draggable({
  1127. containment: [this.canvas.offset().left + 18, 0, this.canvas.offset().left + this.chartWidth - 3, gh],
  1128. axis: "x",
  1129. scroll: false,
  1130. drag: function (event, ui) {
  1131. rtchart._onThumbsChanged();
  1132. }
  1133. });
  1134. gt += h;
  1135. }
  1136. if (this.listContainer) {
  1137. this.listContainer.remove();
  1138. this.listContainer = null;
  1139. }
  1140. if (this.listCanshow() && this.options.listExpand) {
  1141. gt += 4;
  1142. this.listContainer = $(document.createElement('div'));
  1143. this.element.append(this.listContainer);
  1144. this.listContainer.css("position", "absolute")
  1145. .css("left", 0)
  1146. .css("right", 0)
  1147. .css("top", gt)
  1148. .css("bottom", 0)
  1149. .css("border", "1px solid rgb(60,60,60)")
  1150. .addClass('unselectable');
  1151. this.listGrid = new dhtmlXGridObject(this.listContainer.get(0));
  1152. this.listGrid.setImagePath("htm/codebase/dhtmlxGrid/codebase/imgs/"); //the path to images required by grid
  1153. this.listGrid.setHeader("点名称,线宽,描述,显示,数据时间,数据值,量程下限,量程上限,量程锁定,阶跃,标记,实时值,最大值,最小值,平均值"); //the headers of columns
  1154. this.listGrid.setColAlign("left,center,left,center,right,right,right,right,center,center,right,right,center,right,right"); //the alignment of columns
  1155. this.listGrid.setInitWidths("160,50,180,45,140,120,100,100,65,45,45,110,110,110,110"); //the widths of columns
  1156. this.listGrid.setColTypes("clrlabel,combo,ro,ch,ro,ro,edn,edn,ch,ch,ch,vqtcell,vqtcellclick,vqtcellclick,unitval"); //the types of columns
  1157. this.listGrid.setColSorting("str,str,str,na,na,na,na,na,na,na,na,na,na,na,na"); //the sorting types
  1158. this.listGrid.enableColumnMove(true);
  1159. this.listGrid.enableDragAndDrop(true);
  1160. this.listGrid.setSkin("dhx_web"); //dhx_terrace
  1161. this.listGrid.enableColumnAutoSize(true);
  1162. this.listGrid.enableMultiselect(true);
  1163. this.listGrid.init();
  1164. var combo = this.listGrid.getColumnCombo(1);
  1165. combo.addOption("1", "1");
  1166. combo.addOption("2", "2");
  1167. combo.addOption("3", "3");
  1168. combo.addOption("4", "4");
  1169. combo.addOption("5", "5");
  1170. combo.addOption("6", "6");
  1171. combo.addOption("7", "7");
  1172. combo.addOption("8", "8");
  1173. this.listGrid.onSetLabelColor = function (e, rowid) {
  1174. (e || event).cancelBubble = true;
  1175. var pen = rtchart.getPenByRowId(rowid);
  1176. if (pen) {
  1177. rtchart.setPenColor(pen, e);
  1178. }
  1179. };
  1180. this.listGrid.onPosVQT = function (e, rowid, tip) {
  1181. (e || event).cancelBubble = true;
  1182. var pen = rtchart.getPenByRowId(rowid);
  1183. if (pen) {
  1184. pen.posVQT(tip);
  1185. }
  1186. };
  1187. this.listGrid.attachEvent("onSelectStateChanged", function (rowid) {
  1188. if (rowid && rowid != "") {
  1189. var pens = rowid.split(",");
  1190. if (pens && pens.length) {
  1191. var pen = rtchart.getPenByRowId(pens[0]);
  1192. if (pen != rtchart.activePen)
  1193. rtchart.requestActive(pen);
  1194. } else
  1195. rtchart.requestActive(null);
  1196. } else
  1197. rtchart.requestActive(null);
  1198. });
  1199. this.listGrid.attachEvent("onAfterSorting", function (index, type, direction) {
  1200. rtchart._onListSorted();
  1201. });
  1202. this.listGrid.attachEvent("onCheck", function (rowid, cInd, state) {
  1203. var pen = rtchart.getPenByRowId(rowid);
  1204. if (pen != null) {
  1205. var col = rtchart.listGrid.getColumnLabel(cInd);
  1206. switch (col) {
  1207. case "显示":
  1208. pen.setDisplay(state, false);
  1209. break;
  1210. case "阶跃":
  1211. pen.setStepLine(state, false);
  1212. break;
  1213. case "标记":
  1214. pen.setDrawTag(state, false);
  1215. break;
  1216. case "插值":
  1217. pen.setInterpolate(state, false);
  1218. break;
  1219. case "量程锁定":
  1220. pen.setRangeLock(state, false);
  1221. break;
  1222. }
  1223. }
  1224. });
  1225. this.listGrid.attachEvent("onDrop", function (sId, tId, dId, sObj, tObj, sCol, tCol) {
  1226. rtchart._onListSorted();
  1227. });
  1228. this.listGrid.attachEvent("onCellChanged", function (rId, cInd, nValue) {
  1229. var pen = rtchart.getPenByRowId(rId);
  1230. if (pen != null) {
  1231. var col = rtchart.listGrid.getColumnLabel(cInd);
  1232. switch (col) {
  1233. case "量程下限":
  1234. pen.onSetMinRange(nValue);
  1235. break;
  1236. case "量程上限":
  1237. pen.onSetMaxRange(nValue);
  1238. break;
  1239. case "线宽":
  1240. pen.onSetLineWidth(nValue, true);
  1241. break;
  1242. }
  1243. }
  1244. });
  1245. this._synList();
  1246. }
  1247. this._reDrawAll();
  1248. },
  1249. onFullScreenSet: function () {
  1250. if (this.isFullScreen()) {
  1251. this.cancelFullScreen();
  1252. this.toolBar.setItemState("fullScreen", false);
  1253. this.toolBar.setItemToolTip("fullScreen", "单击进入全屏显示模式(F11)");
  1254. this.toolBar.setItemImage("fullScreen", "fullscreen.png");
  1255. } else {
  1256. this.requestFullScreen();
  1257. this.toolBar.setItemState("fullScreen", true);
  1258. //this.toolBar.setItemToolTip("fullScreen", "单击退出全屏显示模式(F11)");
  1259. this.toolBar.setItemImage("fullScreen", "leave_fullscreen.png");
  1260. }
  1261. },
  1262. logout: function () {
  1263. var xhr = $.ajax({
  1264. url: GoldenRtWeb.getWebURL() + '/Logout',
  1265. type: "GET",
  1266. processData: false,
  1267. complete: function (xhr, ts) {
  1268. var url = window.location.href;
  1269. var index = url.lastIndexOf('?');
  1270. if (index > 0)
  1271. url = url.substr(0, index);
  1272. window.location = url;
  1273. }
  1274. });
  1275. },
  1276. _onExportPng: function () {
  1277. // var image = new Image();
  1278. // image.setAttribute('crossOrigin', 'anonymous');
  1279. // // image.crossOrigin = "";
  1280. // image.name = "ddd.jpg";
  1281. // image.id = "ddd.jpg";
  1282. // image = this.canvas[0].toDataURL("image/jpeg").replace("image/jpeg", "image/octet-stream");
  1283. // window.location.href = image;
  1284. this. _downloadFile('趋势图.png', this.canvas[0].toDataURL("image/png"));
  1285. },
  1286. _downloadFile: function (fileName, content) {
  1287. var aLink = document.createElement('a');
  1288. var blob =this._base64Img2Blob(content); //new Blob([content]);
  1289. var evt = document.createEvent("HTMLEvents");
  1290. evt.initEvent("click", false, false);//initEvent 不加后两个参数在FF下会报错
  1291. aLink.download = fileName;
  1292. aLink.href = URL.createObjectURL(blob);
  1293. aLink.dispatchEvent(evt);
  1294. aLink.click();
  1295. },
  1296. _base64Img2Blob: function (code) {
  1297. var parts = code.split(';base64,');
  1298. var contentType = parts[0].split(':')[1];
  1299. var raw = window.atob(parts[1]);
  1300. var rawLength = raw.length;
  1301. var uInt8Array = new Uint8Array(rawLength);
  1302. for (var i = 0; i < rawLength; ++i) {
  1303. uInt8Array[i] = raw.charCodeAt(i);
  1304. }
  1305. return new Blob([uInt8Array], { type: contentType });
  1306. },
  1307. _onExportToExcelInterpo: function () {
  1308. if (!this.trendPens || !this.trendPens.length) {
  1309. var d = dialog({
  1310. content: "目前尚未加载点信息,因此无法进行导出操作。",
  1311. quickClose: true
  1312. });
  1313. d.show();
  1314. window.setTimeout(function () {
  1315. d.close();
  1316. d.remove();
  1317. d = null;
  1318. }, 2000);
  1319. return;
  1320. }
  1321. var pens = [];
  1322. for (var i = 0; i < this.trendPens.length; i++) {
  1323. var pen = this.trendPens[i];
  1324. pens.push(pen.getURI());
  1325. }
  1326. pens = pens.join(';');
  1327. var uri = "beginTime=" + this.getBegTime();
  1328. uri += "&endTime=" + this.getEndTime();
  1329. uri += "&point=" + pens;
  1330. var link = document.createElement("a");
  1331. link.download = "exportExcel";
  1332. link.href = this.getWebURL() + "ExportToExcelInterpo?" + encodeURI(uri);
  1333. link.click();
  1334. },
  1335. _onExportExcel: function () {
  1336. if (!this.trendPens || !this.trendPens.length) {
  1337. var d = dialog({
  1338. content: "目前尚未加载点信息,因此无法进行导出操作。",
  1339. quickClose: true
  1340. });
  1341. d.show();
  1342. window.setTimeout(function () {
  1343. d.close();
  1344. d.remove();
  1345. d = null;
  1346. }, 2000);
  1347. return;
  1348. }
  1349. var pens = [];
  1350. for (var i = 0; i < this.trendPens.length; i++) {
  1351. var pen = this.trendPens[i];
  1352. pens.push(pen.getURI());
  1353. }
  1354. pens = pens.join(';');
  1355. var uri = "beginTime=" + this.getBegTime();
  1356. uri += "&endTime=" + this.getEndTime();
  1357. uri += "&point=" + pens;
  1358. var link = document.createElement("a");
  1359. link.download = "exportExcel";
  1360. link.href = this.getWebURL() + "ExportToExcel?" + encodeURI(uri);
  1361. link.click();
  1362. },
  1363. _queryHisData: function (from, to) {
  1364. var beg = from.val();
  1365. beg = this.parseDate(beg);
  1366. if (beg == null) {
  1367. from.focus();
  1368. var d = dialog({
  1369. content: "查询起始时间设置有误,请重新设置。",
  1370. quickClose: true
  1371. });
  1372. window.setTimeout(function () {
  1373. d.close().remove();
  1374. d = null;
  1375. from.focus();
  1376. }, 2000);
  1377. d.show(from[0]);
  1378. return;
  1379. }
  1380. beg = this.DateToFileTime(beg);
  1381. var end = to.val();
  1382. end = this.parseDate(end);
  1383. if (end == null) {
  1384. to.focus();
  1385. var d = dialog({
  1386. content: "查询截止时间设置有误,请重新设置。",
  1387. quickClose: true
  1388. });
  1389. window.setTimeout(function () {
  1390. d.close().remove();
  1391. d = null;
  1392. to.focus();
  1393. }, 2000);
  1394. d.show(to[0]);
  1395. return;
  1396. }
  1397. end = this.DateToFileTime(end);
  1398. if (end <= beg) {
  1399. to.focus();
  1400. var d = dialog({
  1401. content: "查询截止时间不能小于等于查询起始时间,请重新设置。",
  1402. quickClose: true
  1403. });
  1404. window.setTimeout(function () {
  1405. d.close().remove();
  1406. d = null;
  1407. to.focus();
  1408. }, 2000);
  1409. d.show(to[0]);
  1410. return;
  1411. }
  1412. this.setBegTimeAndSpan(beg, (end - beg) / PERSEC);
  1413. },
  1414. getPenByRowId: function (rowId) {
  1415. if (this.trendPens) {
  1416. for (var k in this.trendPens) {
  1417. var pen = this.trendPens[k];
  1418. if (pen.rowId == rowId)
  1419. return pen;
  1420. }
  1421. }
  1422. return null;
  1423. },
  1424. _bindPenList: function (pen) {
  1425. if (this.listGrid) {
  1426. var rowId = this.listRowSeed++;
  1427. this.listGrid.addRow(rowId, "");
  1428. pen._setListRowId(rowId);
  1429. }
  1430. },
  1431. _synList: function () {
  1432. this.listGrid.clearAll();
  1433. this.listRowSeed = 1;
  1434. if (this.trendPens && this.trendPens.length) {
  1435. for (i in this.trendPens)
  1436. this._bindPenList(this.trendPens[i]);
  1437. }
  1438. },
  1439. _updateList: function (rowId, colName, val) {
  1440. if (this.listGrid && rowId && colName) {
  1441. var num = this.listGrid.getColumnsNum();
  1442. for (var i = 0; i < num; i++) {
  1443. if (this.listGrid.getColumnLabel(i) == colName) {
  1444. var cell = this.listGrid.cells(rowId, i);
  1445. if (cell)
  1446. cell.setValue(val);
  1447. break;
  1448. }
  1449. }
  1450. }
  1451. },
  1452. getWebURL: function () {
  1453. return GoldenRtWeb.getWebURL();
  1454. },
  1455. _reDrawAll: function () {
  1456. var node = this.canvas.get(0);
  1457. this.ctx.clearRect(0, 0, node.width, node.height);
  1458. this.buttonsDrawed = false;
  1459. this.updateDataArea();
  1460. this.UpdatePan(true);
  1461. this._drawIndicator();
  1462. this._drawButtons();
  1463. },
  1464. _onResize: function () {
  1465. if (this.artTooltip)
  1466. this.artTooltip.close().reset().remove();
  1467. if (this.element.width() != this.chartWidth ||
  1468. this.element.height() != this.chartHeight)
  1469. this._bulidCanvas();
  1470. },
  1471. _onListSorted: function () {
  1472. var ids = this.listGrid.getAllRowIds();
  1473. var arry = ids.split(",");
  1474. if (arry && arry.length) {
  1475. var newPens = [];
  1476. for (var i = 0; i < arry.length; i++) {
  1477. var pen = this.getPenByRowId(arry[i]);
  1478. if (pen)
  1479. newPens.push(pen);
  1480. }
  1481. if (newPens.length) {
  1482. this.trendPens = newPens;
  1483. this.updateDataArea();
  1484. this.UpdatePan();
  1485. }
  1486. }
  1487. },
  1488. _drawIndicator: function () {
  1489. var gw = this.getGridWidth();
  1490. var gh = this.getGridHeight();
  1491. var gt = this.toolBarCanShow() ? TOOLBARHEIGHT : 0;
  1492. var rtchart = this;
  1493. var hw;
  1494. if (this.options.showAxis)
  1495. hw = this.chartWidth;
  1496. else
  1497. hw = gw + 12;
  1498. if (!this.hIndicator) {
  1499. this.hIndicator = $(document.createElement('canvas'));
  1500. this.element.append(this.hIndicator);
  1501. bNew = true;
  1502. }
  1503. this.hIndicator.css("position", "absolute")
  1504. .css("left", 0)
  1505. .css("top", 25)
  1506. .css("width", hw)
  1507. .css("height", INDICTWIDTH)
  1508. .css("cursor", "n-resize");
  1509. this.hIndicator.attr("width", (hw) * this.options.resolution);
  1510. this.hIndicator.attr("height", INDICTWIDTH * this.options.resolution);
  1511. var node = this.hIndicator.get(0);
  1512. if (window.G_vmlCanvasManager)
  1513. window.G_vmlCanvasManager.initElement(node); // For ExCanvas
  1514. var hctx = node.getContext('2d');
  1515. if (!window.G_vmlCanvasManager)
  1516. hctx.scale(this.options.resolution, this.options.resolution);
  1517. hctx.save();
  1518. hctx.translate(0.5, 0.5);
  1519. hctx.clearRect(0, 0, (hw), INDICTWIDTH);
  1520. hctx.lineWidth = 3.0;
  1521. hctx.strokeStyle = this.options.indicatorColor;
  1522. hctx.beginPath();
  1523. hctx.moveTo(1, 5);
  1524. hctx.lineTo(hw, 5);
  1525. hctx.stroke();
  1526. hctx.restore();
  1527. if (bNew)
  1528. this.hIndicator.draggable({
  1529. containment: [0, this.canvas.offset().top - 5, hw, this.canvas.offset().top + gh - 5],
  1530. scroll: false,
  1531. axis: "y",
  1532. drag: function (event, ui) {
  1533. rtchart._onhIndicatorMove(event);
  1534. },
  1535. stop: function (event, ui) {
  1536. rtchart._onhIndicatorMoveEnd(event);
  1537. }
  1538. });
  1539. else
  1540. this.hIndicator.draggable('option', 'containment', [0, this.canvas.offset().top - 5, gw, this.canvas.offset().top + gh - 5]);
  1541. this.hIndicator.hover(
  1542. function (e) {
  1543. rtchart.hIndicator.focus();
  1544. rtchart._onhIndicatorHover(e);
  1545. });
  1546. if (this.vSplite) {
  1547. if (this.vSplite.data('drag') === true)
  1548. this.vSplite.draggable("destroy");
  1549. this.vSplite.unbind();
  1550. this.vSplite.remove();
  1551. this.vSplite = null;
  1552. }
  1553. if (this.hSplite) {
  1554. if (this.hSplite.data('drag') === true)
  1555. this.hSplite.draggable("destroy");
  1556. this.hSplite.unbind();
  1557. this.hSplite.remove();
  1558. this.hSplite = null;
  1559. }
  1560. bNew = false;
  1561. if (!this.vIndicator) {
  1562. this.vIndicator = $(document.createElement('canvas'));
  1563. this.element.append(this.vIndicator);
  1564. bNew = true;
  1565. }
  1566. this.vIndicator.css("position", "absolute")
  1567. .css("left", 20)
  1568. .css("top", gt)
  1569. .css("width", INDICTWIDTH)
  1570. .css("height", (gh + 16))
  1571. .css("pointer-events", 'none');
  1572. // .css("cursor", "e-resize");
  1573. this.vIndicator.attr("width", INDICTWIDTH * this.options.resolution);
  1574. this.vIndicator.attr("height", (gh + 16) * this.options.resolution);
  1575. node = this.vIndicator.get(0);
  1576. if (window.G_vmlCanvasManager)
  1577. window.G_vmlCanvasManager.initElement(node); // For ExCanvas
  1578. var vctx = node.getContext('2d');
  1579. if (!window.G_vmlCanvasManager)
  1580. vctx.scale(this.options.resolution, this.options.resolution);
  1581. vctx.save();
  1582. vctx.translate(0.5, 0.5);
  1583. vctx.clearRect(0, 0, INDICTWIDTH, node.height);
  1584. vctx.lineWidth = 1.0;
  1585. vctx.setLineDash([3, 6]);
  1586. vctx.strokeStyle = this.options.indicatorColor;
  1587. vctx.beginPath();
  1588. vctx.moveTo(5, 1);
  1589. vctx.lineTo(5, gh + 10);
  1590. vctx.stroke();
  1591. vctx.restore();
  1592. if (bNew)
  1593. this.vIndicator.draggable({
  1594. containment: [this.canvas.offset().left - 5, 0, this.canvas.offset().left + gw - 5, gh],
  1595. axis: "x",
  1596. scroll: false,
  1597. drag: function (event, ui) {
  1598. rtchart._onvIndicatorMove(event);
  1599. },
  1600. stop: function (event, ui) {
  1601. rtchart._onvIndicatorMoveEnd(event);
  1602. }
  1603. });
  1604. else
  1605. this.vIndicator.draggable('option', 'containment', [this.canvas.offset().left - 5, 0, this.canvas.offset().left + gw - 5, gh]);
  1606. this.vIndicator.hover(
  1607. function (e) {
  1608. rtchart.vIndicator.focus();
  1609. rtchart._onvIndicatorHover(e);
  1610. });
  1611. if (this.options.panShow) {
  1612. this.vSplite = $(document.createElement('canvas'));
  1613. this.hIndicator.before(this.vSplite);
  1614. this.vSplite.css("position", "absolute")
  1615. .css("left", gw)
  1616. .css("top", gt)
  1617. .css("width", PANMAG * 2)
  1618. .css("height", (gh + 1))
  1619. .css("cursor", "e-resize")
  1620. .addClass('unselectable');
  1621. this.vSplite.attr("width", PANMAG * 2 * this.options.resolution);
  1622. this.vSplite.attr("height", (gh + 1) * this.options.resolution);
  1623. node = this.vSplite.get(0);
  1624. if (window.G_vmlCanvasManager)
  1625. window.G_vmlCanvasManager.initElement(node); // For ExCanvas
  1626. var spctx = node.getContext('2d');
  1627. if (!window.G_vmlCanvasManager)
  1628. spctx.scale(this.options.resolution, this.options.resolution);
  1629. spctx.clearRect(0, 0, node.width, node.height);
  1630. this.vSplite.draggable({
  1631. containment: [this.canvas.offset().left + 200, 0, this.chartWidth - 5, gh],
  1632. axis: "x",
  1633. scroll: false,
  1634. start: function (event, ui) {
  1635. var ctx = this.getContext('2d');
  1636. ctx.clearRect(0, 0, this.width, this.height);
  1637. var gradient = ctx.createLinearGradient(0, 0, this.width, 0);
  1638. gradient.addColorStop("0", "rgba(120,120,120,0.5)");
  1639. gradient.addColorStop(".50", "rgba(180,180,180,0.7)");
  1640. gradient.addColorStop("1.0", "rgba(120,120,120,0.5)");
  1641. ctx.fillStyle = gradient;
  1642. ctx.fillRect(0, 0, this.width, this.height);
  1643. ctx.beginPath();
  1644. ctx.lineWidth = "1";
  1645. ctx.strokeStyle = "rgb(30,30,30)";
  1646. ctx.rect(.5, .5, this.width - 1, this.height - 1);
  1647. ctx.stroke();
  1648. },
  1649. stop: function (event, ui) {
  1650. var ctx = this.getContext('2d');
  1651. ctx.clearRect(0, 0, this.width, this.height);
  1652. var l = $(this).position().left;
  1653. rtchart.setPanWidth(rtchart.chartWidth - l);
  1654. }
  1655. });
  1656. this.vSplite.data('drag', true);
  1657. this.vSplite.hover(
  1658. function (e) {
  1659. var o = $(this).offset();
  1660. var x = e.pageX - o.left;
  1661. var y = e.pageY - o.top;
  1662. if (y > this.height / 2 - 18 && y < this.height / 2 - 18 + 35) {
  1663. $(this).attr('title', '收回数据板');
  1664. $(this).css('cursor', 'pointer');
  1665. } else {
  1666. $(this).attr('title', null);
  1667. $(this).css('cursor', "e-resize");
  1668. }
  1669. },
  1670. function (e) {
  1671. $(this).css("cursor", "e-resize");
  1672. });
  1673. this.vSplite.click(function (e) {
  1674. var o = $(this).offset();
  1675. var x = e.pageX - o.left;
  1676. var y = e.pageY - o.top;
  1677. if (y > this.height / 2 - 18 && y < this.height / 2 - 18 + 35)
  1678. rtchart.setPanShow(false);
  1679. });
  1680. } else if (this.panCanShow()) {
  1681. this.vSplite = $(document.createElement('canvas'));
  1682. this.hIndicator.before(this.vSplite);
  1683. this.vSplite.css("position", "absolute")
  1684. .css("left", this.chartWidth - 5)
  1685. .css("top", gh / 2 + 15)
  1686. .css("width", 5)
  1687. .css("height", 35)
  1688. .css("cursor", "pointer")
  1689. .attr("title", "展开数据板");
  1690. this.vSplite.attr("width", 5 * this.options.resolution);
  1691. this.vSplite.attr("height", 35 * this.options.resolution);
  1692. node = this.vSplite.get(0);
  1693. if (window.G_vmlCanvasManager)
  1694. window.G_vmlCanvasManager.initElement(node); // For ExCanvas
  1695. var spctx = node.getContext('2d');
  1696. if (!window.G_vmlCanvasManager)
  1697. spctx.scale(this.options.resolution, this.options.resolution);
  1698. spctx.clearRect(0, 0, node.width, node.height);
  1699. this.vSplite.click(function (e) {
  1700. rtchart.setPanShow(true);
  1701. });
  1702. }
  1703. if (this.listCanshow()) {
  1704. this.hSplite = $(document.createElement('canvas'));
  1705. this.element.append(this.hSplite);
  1706. var t;
  1707. if (this.listCanshow() && this.options.listExpand)
  1708. t = this.chartHeight - this.options.listHeight;
  1709. else
  1710. t = this.chartHeight - 11;
  1711. this.hSplite.css("position", "absolute")
  1712. .css("left", 0)
  1713. .css("top", t)
  1714. .css("right", 0)
  1715. .css("height", 10)
  1716. .css("cursor", "n-resize")
  1717. .css("z-index", 1000)
  1718. .addClass('unselectable');
  1719. this.hSplite.attr("width", this.chartWidth * this.options.resolution);
  1720. this.hSplite.attr("height", 10 * this.options.resolution);
  1721. node = this.hSplite.get(0);
  1722. if (window.G_vmlCanvasManager)
  1723. window.G_vmlCanvasManager.initElement(node); // For ExCanvas
  1724. var hpctx = node.getContext('2d');
  1725. if (!window.G_vmlCanvasManager)
  1726. hpctx.scale(this.options.resolution, this.options.resolution);
  1727. hpctx.clearRect(0, 0, node.width, node.height);
  1728. this.hSplite.draggable({
  1729. containment: [0, this.element.offset().top + 210, 0, this.element.offset().top + this.element.height() - 30],
  1730. axis: "y",
  1731. scroll: false,
  1732. start: function (event, ui) {
  1733. var ctx = this.getContext('2d');
  1734. ctx.clearRect(0, 0, this.width, this.height);
  1735. var gradient = ctx.createLinearGradient(0, 0, 0, this.height);
  1736. gradient.addColorStop("0", "rgba(120,120,120,0.5)");
  1737. gradient.addColorStop(".50", "rgba(200,200,200,0.7)");
  1738. gradient.addColorStop("1.0", "rgba(120,120,120,0.5)");
  1739. ctx.fillStyle = gradient;
  1740. ctx.fillRect(0, 0, this.width - 3, this.height);
  1741. ctx.beginPath();
  1742. ctx.lineWidth = "1";
  1743. ctx.strokeStyle = "rgb(30,30,30)";
  1744. ctx.rect(.5, .5, this.width - 3, this.height - 1);
  1745. ctx.stroke();
  1746. },
  1747. stop: function (event, ui) {
  1748. var ctx = this.getContext('2d');
  1749. ctx.clearRect(0, 0, this.width, this.height);
  1750. var t = rtchart.chartHeight - $(this).offset().top + rtchart.element.offset().top;
  1751. rtchart.setListHeight(t);
  1752. }
  1753. });
  1754. this.hSplite.data('drag', true);
  1755. this.hSplite.hover(
  1756. function (e) {
  1757. var o = $(this).offset();
  1758. var x = e.pageX - o.left;
  1759. var y = e.pageY - o.top;
  1760. if (x > this.width / 2 - 18 && x < this.width / 2 + 18) {
  1761. if (rtchart.options.listExpand)
  1762. $(this).attr('title', '收回数据列表');
  1763. else
  1764. $(this).attr('title', '展开数据列表');
  1765. $(this).css('cursor', 'pointer');
  1766. } else {
  1767. $(this).attr('title', null);
  1768. $(this).css('cursor', "n-resize");
  1769. }
  1770. },
  1771. function (e) {
  1772. $(this).css("cursor", "n-resize");
  1773. }
  1774. );
  1775. this.hSplite.click(function (e) {
  1776. var o = $(this).offset();
  1777. var x = e.pageX - o.left;
  1778. var y = e.pageY - o.top;
  1779. if (x > this.width / 2 - 18 && x < this.width / 2 + 18) {
  1780. if (rtchart.options.listExpand)
  1781. rtchart.setListExpand(false);
  1782. else
  1783. rtchart.setListExpand(true);
  1784. }
  1785. });
  1786. }
  1787. },
  1788. _drawButtons: function () {
  1789. if (this.buttonsDrawed === true || !this.options.buttonImage)
  1790. return;
  1791. if (this.options.buttonImage.get(0).complete === true) {
  1792. var img = this.options.buttonImage.get(0);
  1793. var gw = this.getGridWidth();
  1794. var gh = this.getGridHeight();
  1795. this.buttonsDrawed = true;
  1796. var canvas = this.vIndicator.get(0);
  1797. var ctx = canvas.getContext("2d");
  1798. ctx.drawImage(img, 0, 0, 11, 11, 0, gh - 3, 11, 11);
  1799. canvas = this.hIndicator.get(0);
  1800. ctx = canvas.getContext("2d");
  1801. ctx.drawImage(img, 11, 0, 11, 11, gw - 3, 0, 11, 11);
  1802. if (this.vSplite) {
  1803. canvas = this.vSplite.get(0);
  1804. ctx = canvas.getContext("2d");
  1805. if (this.options.panShow)
  1806. ctx.drawImage(img, 0, 11, 5, 35, 0, canvas.height / 2 - 18, 5, 35);
  1807. else
  1808. ctx.drawImage(img, 5, 11, 5, 35, 0, 0, 5, 35);
  1809. }
  1810. if (this.hSplite) {
  1811. canvas = this.hSplite.get(0);
  1812. ctx = canvas.getContext("2d");
  1813. if (this.options.listExpand)
  1814. ctx.drawImage(img, 10, 11, 35, 5, canvas.width / 2 - 18, 0, 35, 5);
  1815. else
  1816. ctx.drawImage(img, 10, 15, 35, 5, canvas.width / 2 - 18, 0, 35, 5);
  1817. }
  1818. } else {
  1819. var me = this;
  1820. this.options.buttonImage.load(function () {
  1821. if (me) {
  1822. me._drawButtons();
  1823. me.UpdateDataPan(true);
  1824. me = null;
  1825. }
  1826. });
  1827. }
  1828. },
  1829. updateDataArea: function () {
  1830. if (this.updateDataAreaTimer == null) {
  1831. var self = this;
  1832. this.updateDataAreaTimer = window.setTimeout(function () {
  1833. window.clearTimeout(self.updateDataAreaTimer)
  1834. self.updateDataAreaTimer = null;
  1835. self._drawDataArea();
  1836. self = null;
  1837. }, 20);
  1838. }
  1839. },
  1840. _drawDataArea: function () {
  1841. if (this.thumbsCanshow())
  1842. this._drawThumbs();
  1843. this._drawTimeLabel();
  1844. this._drawTrendLines();
  1845. },
  1846. _drawTrendLines: function () {
  1847. var gw = this.getGridWidth();
  1848. var gh = this.getGridHeight();
  1849. var ctx = this.ctx;
  1850. ctx.save();
  1851. ctx.clearRect(0, 0, gw, gh);
  1852. ctx.translate(0.5, 0.5);
  1853. var begTime = this.getDrawBegTime();
  1854. var endTime = this.getDrawEndTime();
  1855. var timeScale = gw / (endTime - begTime);
  1856. if (this.options.showGrid) {
  1857. var y = gh / 20.0;
  1858. ctx.beginPath();
  1859. ctx.lineWidth = 1;
  1860. ctx.strokeStyle = this.options.gridColor;
  1861. for (var i = 0; i < 19; i++) {
  1862. var iy = Math.floor(y);
  1863. ctx.moveTo(0, iy);
  1864. ctx.lineTo(gw, iy);
  1865. y += gh / 20.0;
  1866. }
  1867. var t = this.ftTimeLabelBeg;
  1868. var x = (t - begTime) * timeScale;
  1869. for (var i = 0; i < 4; i++) {
  1870. var ix = Math.floor(x);
  1871. ctx.moveTo(ix, 0);
  1872. ctx.lineTo(ix, gh);
  1873. t += (endTime - begTime) / 4;
  1874. x = (t - begTime) * timeScale;
  1875. }
  1876. ctx.stroke();
  1877. }
  1878. if (this.trendPens && this.trendPens.length) {
  1879. ctx.rect(1, 1, gw - 1, gh - 1);
  1880. ctx.clip();
  1881. ctx.lineWidth = 1;
  1882. for (k in this.trendPens) {
  1883. var pen = this.trendPens[k];
  1884. if (pen != this.activePen)
  1885. pen.drawTrendLine(ctx, begTime, endTime, gw, gh, timeScale);
  1886. }
  1887. if (this.activePen) {
  1888. var shadowSize = this.options.activeShadowSize;
  1889. var lineWidth = 2;
  1890. ctx.lineWidth = shadowSize / 2;
  1891. var offset = lineWidth / 2 + ctx.lineWidth / 2;
  1892. ctx.strokeStyle = "rgba(0,0,0,0.4)";
  1893. this.activePen.drawTrendLine(ctx, begTime, endTime, gw, gh, timeScale, offset + shadowSize / 2);
  1894. ctx.strokeStyle = "rgba(0,0,0,0.5)";
  1895. this.activePen.drawTrendLine(ctx, begTime, endTime, gw, gh, timeScale, offset);
  1896. ctx.lineWidth = lineWidth;
  1897. this.activePen.drawTrendLine(ctx, begTime, endTime, gw, gh, timeScale);
  1898. }
  1899. }
  1900. if (this.zoomRect) {
  1901. ctx.lineWidth = 1;
  1902. ctx.strokeStyle = "rgb(180,180,180)";
  1903. ctx.fillStyle = "rgba(10,10,10,0.2)";
  1904. ctx.beginPath();
  1905. ctx.rect(this.zoomRect.x, this.zoomRect.y, this.zoomRect.w, this.zoomRect.h);
  1906. ctx.fill();
  1907. ctx.stroke();
  1908. }
  1909. ctx.restore();
  1910. if (this.options.borderColor != null) {
  1911. ctx.lineWidth = 1;
  1912. ctx.beginPath();
  1913. ctx.strokeStyle = this.options.borderColor;
  1914. ctx.rect(0.5, 0.5, gw, gh);
  1915. ctx.stroke();
  1916. }
  1917. },
  1918. _onThumbsChanged: function () {
  1919. this.thumbBegDiv.draggable("option", "containment", [this.canvas.offset().left - 3, 0, this.canvas.offset().left + this.thumbEndDiv.position().left - 20, 0]);
  1920. this.thumbEndDiv.draggable("option", "containment", [this.canvas.offset().left + this.thumbBegDiv.position().left + 20, 0, this.canvas.offset().left + this.chartWidth - 3, 0]);
  1921. this._drawThumbs();
  1922. this._drawTimeLabel();
  1923. this._drawTrendLines();
  1924. },
  1925. _resetTumbs: function () {
  1926. if (this.thumbBegDiv) {
  1927. this.thumbBegDiv
  1928. .css("left", -3)
  1929. .draggable("option", "containment", [this.canvas.offset().left - 3, 0, this.canvas.offset().left + this.chartWidth - 18, 0]);
  1930. }
  1931. if (this.thumbEndDiv) {
  1932. this.thumbEndDiv
  1933. .css("left", this.chartWidth - 3)
  1934. .draggable("option", "containment", [this.canvas.offset().left + 18, 0, this.canvas.offset().left + this.chartWidth - 18, 0]);
  1935. }
  1936. },
  1937. _drawThumbs: function () {
  1938. var thw = this.chartWidth;
  1939. var gh = this.getGridHeight();
  1940. var gt = gh + TIMELABELHEIGHT;
  1941. var h = SHOWTHUMBSHEIGHT - 3;
  1942. var ctx = this.ctx;
  1943. ctx.save();
  1944. ctx.clearRect(0, gt, thw, h);
  1945. ctx.translate(0.5, 0.5);
  1946. if (this.trendPens && this.trendPens.length) {
  1947. var begTime = this.getBegTime();
  1948. var endTime = this.getEndTime();
  1949. var timeScale = thw / this.options.spanSec / PERSEC;
  1950. ctx.rect(1, gt, thw - 1, h - 1);
  1951. ctx.clip();
  1952. ctx.lineWidth = 1;
  1953. for (k in this.trendPens) {
  1954. var pen = this.trendPens[k];
  1955. pen.drawThumbsTrendLine(ctx, begTime, endTime, gh, gt, h, timeScale);
  1956. }
  1957. }
  1958. ctx.fillStyle = "rgba(100,100,100,0.7)";
  1959. var ix = this.thumbBegDiv.position().left + 6;
  1960. ctx.fillRect(0, gt, ix, h);
  1961. ix = this.thumbEndDiv.position().left;
  1962. ctx.fillRect(ix, gt, thw - ix, h);
  1963. ctx.restore();
  1964. if (this.options.borderColor != null) {
  1965. ctx.lineWidth = 1;
  1966. ctx.beginPath();
  1967. ctx.strokeStyle = this.options.borderColor;
  1968. ctx.rect(0.5, 0.5 + gt, thw - 1, h);
  1969. ctx.stroke();
  1970. }
  1971. },
  1972. _drawTimeLabel: function () {
  1973. if (!this.ctx || !this.slidCanShow())
  1974. return;
  1975. var begTime = this.getDrawBegTime();
  1976. var endTime = this.getDrawEndTime();
  1977. var timeSpan = (endTime - begTime);
  1978. var span = timeSpan / 4;
  1979. var changed = false;
  1980. if (this.ftTimeLabelBeg == null ||
  1981. Math.abs(this.ftTimeLabelBeg - this.ftBeginTime) > this.options.spanSec * PERSEC) {
  1982. if (span >= PERDAY) {
  1983. var ft = begTime + PERDAY;
  1984. ft = this.FileTimeToDate(ft);
  1985. ft.setHours(0);
  1986. ft.setMinutes(0);
  1987. ft.setSeconds(0);
  1988. ft.setMilliseconds(0);
  1989. this.ftTimeLabelBeg = this.DateToFileTime(ft);
  1990. } else if (span > PERHOUR) {
  1991. var ft = begTime + PERHOUR;
  1992. ft = this.FileTimeToDate(ft);
  1993. ft.setMinutes(0);
  1994. ft.setSeconds(0);
  1995. ft.setMilliseconds(0);
  1996. this.ftTimeLabelBeg = this.DateToFileTime(ft);
  1997. } else if (span > PERMINUTE) {
  1998. var ft = begTime + PERMINUTE;
  1999. ft = this.FileTimeToDate(ft);
  2000. ft.setSeconds(0);
  2001. ft.setMilliseconds(0);
  2002. this.ftTimeLabelBeg = this.DateToFileTime(ft);
  2003. } else if (span > PERSEC) {
  2004. var ft = begTime + PERSEC;
  2005. ft = this.FileTimeToDate(ft);
  2006. ft.setMilliseconds(0);
  2007. this.ftTimeLabelBeg = this.DateToFileTime(ft);
  2008. } else
  2009. this.ftTimeLabelBeg = begTime + span;
  2010. changed = true;
  2011. }
  2012. while (begTime < this.ftTimeLabelBeg + span) {
  2013. this.ftTimeLabelBeg -= span;
  2014. changed = true;
  2015. }
  2016. while (begTime > this.ftTimeLabelBeg) {
  2017. this.ftTimeLabelBeg += span;
  2018. changed = true;
  2019. }
  2020. if (changed)
  2021. this._updatevIndicatorTooltip();
  2022. var ctx = this.ctx;
  2023. ctx.save();
  2024. ctx.translate(0.5, 0.5);
  2025. ctx.fillStyle = this.options.timeLabelColor;
  2026. ctx.textBaseline = "top";
  2027. ctx.textAlign = "left";
  2028. ctx.font = "12px sans-serif";
  2029. var gw = this.getGridWidth();
  2030. var gh = this.getGridHeight();
  2031. ctx.clearRect(0, gh + 0.5, gw, 13);
  2032. var len = 60;
  2033. var str;
  2034. if (timeSpan / PERSEC > 10)
  2035. str = this.FileTimeToTimeString(begTime, false);
  2036. else {
  2037. str = this.FileTimeToTimeString(begTime, true);
  2038. len = 80;
  2039. }
  2040. ctx.fillText(str, 0, gh);
  2041. str = this.FileTimeToDateString(begTime);
  2042. ctx.clearRect(0, gh + 14, 70, 16);
  2043. ctx.fillText(str, 0, gh + 16);
  2044. var time = this.ftTimeLabelBeg;
  2045. var x = (time - begTime) * gw / timeSpan;
  2046. var px = 0;
  2047. for (var i = 1; i < 5; i++) {
  2048. var ix = Math.floor(x);
  2049. if ((ix > px + len) && (ix + len < gw - len)) {
  2050. if (this.options.spanSec > 10)
  2051. str = this.FileTimeToTimeString(time, false);
  2052. else
  2053. str = this.FileTimeToTimeString(time, true);
  2054. ctx.fillText(str, ix, gh);
  2055. px = x;
  2056. }
  2057. time += timeSpan / 4;
  2058. x += gw / 4;
  2059. }
  2060. if (timeSpan / PERSEC > 10)
  2061. str = this.FileTimeToTimeString(endTime, false);
  2062. else
  2063. str = this.FileTimeToTimeString(endTime, true);
  2064. ctx.textAlign = "right";
  2065. ctx.fillText(str, gw, gh);
  2066. str = this.FileTimeToDateString(endTime);
  2067. ctx.clearRect(gw - 70, gh + 14, 72, 16);
  2068. ctx.fillText(str, gw, gh + 16);
  2069. ctx.restore();
  2070. },
  2071. UpdatePan: function (bReDraw) {
  2072. if (bReDraw)
  2073. this.panReDraw = bReDraw;
  2074. if (this.updatePanTimer == null) {
  2075. var self = this;
  2076. this.updatePanTimer = window.setTimeout(function () {
  2077. window.clearTimeout(self.updatePanTimer)
  2078. self.updatePanTimer = null;
  2079. self._drawPan();
  2080. self = null;
  2081. }, 100);
  2082. }
  2083. },
  2084. UpdateDataPan: function (bReDraw) {
  2085. if (this.options.showAxis || !this.options.panShow)
  2086. return;
  2087. this.UpdatePan(bReDraw);
  2088. },
  2089. UpdateAxisPan: function (bReDraw) {
  2090. if (!this.options.showAxis || !this.options.panShow)
  2091. return;
  2092. this.UpdatePan(bReDraw);
  2093. },
  2094. _drawPan: function (bReDraw) {
  2095. this.options
  2096. if (this.options.panShow) {
  2097. var l = this.getGridWidth() + PANMAG;
  2098. var w = this.options.panWidth - PANMAG;
  2099. if (this.options.showAxis) {
  2100. var h = this.getGridHeight() + TIMELABELHEIGHT;
  2101. var ctx = this.ctx;
  2102. ctx.save();
  2103. ctx.font = "12px sans-serif";
  2104. ctx.textBaseline = "top";
  2105. ctx.lineWidth = 1.0;
  2106. ctx.lineJoin = 'miter';
  2107. ctx.clearRect(l, 0, w + 1, h);
  2108. ctx.rect(l, 0, w + 1, h - 2);
  2109. ctx.clip();
  2110. ctx.translate(0.5, 0.5);
  2111. if (this.trendPens) {
  2112. for (var i = 0; i < this.trendPens.length; i++)
  2113. this.trendPens[i].resetAxisDrawed();
  2114. var pl = this.getGridWidth() + PANMAG;
  2115. var ph = this.getGridHeight();
  2116. var pw = this.options.panWidth - PANMAG;
  2117. var begX = pl + 1;
  2118. for (var i = 0; i < this.trendPens.length; i++) {
  2119. ctx.strokeStyle = this.options.borderColor;
  2120. ctx.fillStyle = this.options.timeLabelColor;
  2121. var drawPen = this.trendPens[i];
  2122. var x = drawPen.drawAxis(begX, ph, ctx);
  2123. if (isNaN(x))
  2124. x = 0;
  2125. begX += x + 2;
  2126. if (begX >= this.chartWidth)
  2127. break;
  2128. }
  2129. }
  2130. ctx.restore();
  2131. } else {
  2132. var h = this.getGridHeight();
  2133. if (this.yScroll == null || this.yScroll < 0)
  2134. this.yScroll = 0;
  2135. else if (!this.trendPens || h > PANHEAD + this._getPanTotalHeight())
  2136. this.yScroll = 0;
  2137. else if (this.yScroll + (h - PANHEAD) > this._getPanTotalHeight())
  2138. this.yScroll = this._getPanTotalHeight() - h + PANHEAD;
  2139. var ctx = this.ctx;
  2140. ctx.save();
  2141. ctx.font = "14px sans-serif";
  2142. ctx.textBaseline = "top";
  2143. bReDraw = this.panReDraw || bReDraw;
  2144. this.panReDraw = false;
  2145. if (bReDraw)
  2146. ctx.clearRect(l + 0.5, 0.5, w, h + TIMELABELHEIGHT);
  2147. ctx.rect(l, 0, w + 1, h - 2);
  2148. ctx.clip();
  2149. if (this.trendPens) {
  2150. var t = PANHEAD - this.yScroll;
  2151. var pl = this.getGridWidth() + PANMAG;
  2152. var ph = this.getGridHeight();
  2153. var pw = this.options.panWidth - PANMAG;
  2154. for (var i = 0; i < this.trendPens.length; i++) {
  2155. ctx.save();
  2156. ctx.translate(pl, t);
  2157. if (this.newPenPos == i) {
  2158. ctx.lineWidth = 4.0;
  2159. ctx.lineJoin = 'round';
  2160. ctx.strokeStyle = "rgb(0,210,210)";
  2161. ctx.beginPath();
  2162. ctx.moveTo(0, 0);
  2163. ctx.lineTo(pw, 0);
  2164. ctx.stroke();
  2165. }
  2166. var drawPen = this.trendPens[i];
  2167. drawPen.drawPan(bReDraw, ctx, t, pw);
  2168. ctx.restore();
  2169. t += drawPen.getPanHeight();
  2170. if (t > ph)
  2171. break;
  2172. }
  2173. }
  2174. if (this._showAxisToggle === true) {
  2175. this._showAxisToggle = false;
  2176. ctx.clearRect(l + 0.5, h, w, TIMELABELHEIGHT);
  2177. }
  2178. ctx.restore();
  2179. ctx.beginPath();
  2180. ctx.lineWidth = 1;
  2181. ctx.strokeStyle = this.options.borderColor;
  2182. ctx.rect(l + 0.5, 0.5, w, h);
  2183. ctx.stroke();
  2184. }
  2185. }
  2186. },
  2187. _setOption: function (key, value) {
  2188. switch (key) {
  2189. case "rtRefresh":
  2190. this.setRtrefresh(value);
  2191. break;
  2192. }
  2193. this._super(key, value);
  2194. },
  2195. toggleRtRefresh: function () {
  2196. this.setRtrefresh(!this.options.rtRefresh);
  2197. },
  2198. setRtrefresh: function (brtRefresh) {
  2199. if (this.options.rtRefresh == brtRefresh)
  2200. return;
  2201. this.options.rtRefresh = brtRefresh;
  2202. if (this.options.rtRefresh) {
  2203. this.toolBar.setItemImage("reRefresh", "refresh.png");
  2204. this.toolBar.setItemState("reRefresh", true);
  2205. this.toolBar.setItemToolTip("reRefresh", "当前为实时刷新模式,单击转变为静态查询模式");
  2206. } else {
  2207. this.toolBar.setItemImage("reRefresh", "query.png");
  2208. this.toolBar.setItemState("reRefresh", false);
  2209. this.toolBar.setItemToolTip("reRefresh", "当前为静态查询模式,单击转变为实时刷新模式");
  2210. }
  2211. if (this.options.rtRefresh) {
  2212. if (Math.abs(this.DateToFileTime(new Date()) - this.getEndTime()) > this.options.spanSec * PERSEC) {
  2213. var begTime = new Date();
  2214. begTime.setMilliseconds(0);
  2215. begTime = this.DateToFileTime(begTime);
  2216. begTime += PERSEC;
  2217. begTime -= this.options.spanSec * PERSEC;
  2218. this.ftTimeLabelBeg = null;
  2219. if (this.ftBeginTime == begTime)
  2220. this.ftBeginTime = 0;
  2221. this.setBeginTime(begTime);
  2222. } else if (this.webLinks) {
  2223. for (var i in this.webLinks)
  2224. this.webLinks[i].requestHisData();
  2225. }
  2226. }
  2227. },
  2228. toggleShowAxis: function () {
  2229. this.setShowAxis(!this.options.showAxis);
  2230. },
  2231. setShowAxis: function (bShowAxis) {
  2232. if (this.options.showAxis == bShowAxis)
  2233. return;
  2234. this.options.showAxis = bShowAxis;
  2235. if (this.options.showAxis) {
  2236. this.toolBar.setItemImage("showAxis", "axis.png");
  2237. this.toolBar.setItemState("showAxis", true);
  2238. this.toolBar.setItemToolTip("showAxis", "当前为值轴显示模式,单击转变为数据板显示模式");
  2239. } else {
  2240. this.toolBar.setItemImage("showAxis", "datapan.png");
  2241. this.toolBar.setItemState("showAxis", false);
  2242. this.toolBar.setItemToolTip("showAxis", "当前为数据板显示模式,单击转变为值轴显示模式");
  2243. }
  2244. this._showAxisToggle = true;
  2245. var gw = this.getGridWidth();
  2246. var hw;
  2247. if (this.options.showAxis)
  2248. hw = this.chartWidth;
  2249. else
  2250. hw = gw + 12;
  2251. this.hIndicator.css("width", hw);
  2252. this.hIndicator.attr("width", (hw) * this.options.resolution);
  2253. var node = this.hIndicator.get(0);
  2254. if (window.G_vmlCanvasManager)
  2255. window.G_vmlCanvasManager.initElement(node); // For ExCanvas
  2256. var hctx = node.getContext('2d');
  2257. if (!window.G_vmlCanvasManager)
  2258. hctx.scale(this.options.resolution, this.options.resolution);
  2259. hctx.save();
  2260. hctx.translate(0.5, 0.5);
  2261. hctx.clearRect(0, 0, (hw), INDICTWIDTH);
  2262. hctx.lineWidth = 3.0;
  2263. hctx.strokeStyle = this.options.indicatorColor;
  2264. hctx.beginPath();
  2265. hctx.moveTo(1, 5);
  2266. hctx.lineTo(hw, 5);
  2267. hctx.stroke();
  2268. if (this.options.buttonImage && this.options.buttonImage.get(0).complete === true) {
  2269. var img = this.options.buttonImage.get(0);
  2270. hctx.drawImage(img, 11, 0, 11, 11, gw - 3, -0.5, 11, 11);
  2271. }
  2272. hctx.restore();
  2273. this.UpdatePan(true);
  2274. },
  2275. toggleRangeMode: function () {
  2276. this.setRangeMode(!this.options.freeRange);
  2277. },
  2278. setRangeMode: function (rangeMode) {
  2279. if (this.options.freeRange === rangeMode) return;
  2280. this.options.freeRange = rangeMode;
  2281. if (this.options.freeRange) {
  2282. this.toolBar.setItemImage("toggleRange", "view_type_free.png");
  2283. this.toolBar.setItemState("toggleRange", true);
  2284. this.toolBar.setItemToolTip("toggleRange", "当前量程为自由量程,点击切换到固定量程");
  2285. } else {
  2286. this.toolBar.setItemImage("toggleRange", "view_type.png");
  2287. this.toolBar.setItemState("toggleRange", false);
  2288. this.toolBar.setItemToolTip("toggleRange", "当前量程为固定量程,点击切换到自由量程");
  2289. }
  2290. // 如果是固定量程
  2291. var pen
  2292. if (!rangeMode) {
  2293. for (var i = 0, len = this.trendPens.length; i < len; i++) {
  2294. pen = this.trendPens[i];
  2295. pen.setRange(0, 1000, null);
  2296. }
  2297. }
  2298. },
  2299. setCursor: function (cursor) {
  2300. this.canvas.css("cursor", cursor);
  2301. },
  2302. showTooltip: function (opt, pen) {
  2303. if (this.artTooltip)
  2304. this.artTooltip.close().remove();
  2305. if (this.tipShowPen)
  2306. this.tipShowPen.onTooltipHided();
  2307. if (this.tooltipTimer) {
  2308. window.clearTimeout(this.tooltipTimer);
  2309. this.tooltipTimer = null;
  2310. }
  2311. var rtChart = this;
  2312. this.tooltipTimer = window.setTimeout(
  2313. function () {
  2314. var o = rtChart.getOffset();
  2315. if (opt.x == null || opt.x < 0)
  2316. opt.x = 0;
  2317. else if (opt.x + rtChart.positionDiv.width() + 2 > o.left + rtChart.chartWidth)
  2318. opt.x = o.left + rtChart.chartWidth - rtChart.positionDiv.width() - 2;
  2319. if (opt.y == null || opt.y < 0)
  2320. opt.y = 0;
  2321. else if (opt.y + rtChart.positionDiv.height() + 2 > o.top + rtChart.chartHeight)
  2322. opt.y = o.top + rtChart.chartHeight - rtChart.positionDiv.height() - 2;
  2323. rtChart.positionDiv.offset({
  2324. left: opt.x,
  2325. top: opt.y
  2326. });
  2327. $.extend(opt, {
  2328. padding: 10,
  2329. onremove: function () {
  2330. rtChart._onTootipHided();
  2331. rtChart = null;
  2332. }
  2333. });
  2334. rtChart.artTooltip = dialog(opt);
  2335. rtChart.artTooltip.show(rtChart.positionDiv.get(0));
  2336. rtChart.btipShow = true;
  2337. rtChart.tipShowPen = pen;
  2338. if (rtChart.tipShowPen)
  2339. rtChart.tipShowPen.onTooltipShowed();
  2340. }, this.options.tooltipDelay || 200);
  2341. },
  2342. UpdateTooltip: function (content) {
  2343. if (this.artTooltip)
  2344. this.artTooltip.content(content)
  2345. },
  2346. _onTootipHided: function () {
  2347. this.btipShow = false;
  2348. if (this.tipShowPen) {
  2349. this.tipShowPen.onTooltipHided();
  2350. this.tipShowPen = null;
  2351. }
  2352. this.tootipAt = null;
  2353. if (this.artTooltip)
  2354. delete this.artTooltip;
  2355. this.positionDiv.offset({
  2356. left: this.canvas.offset().left,
  2357. top: this.canvas.offset().top
  2358. });
  2359. },
  2360. getTooltipPen: function () {
  2361. return this.tipShowPen;
  2362. },
  2363. _onhIndicatorHover: function (e) {
  2364. if (this.loginning === true)
  2365. return;
  2366. if (this.artTooltip && this.tootipAt == "HI" && this.artTooltip.__popup)
  2367. return;
  2368. if (this.artTooltip)
  2369. this.artTooltip.close().remove();
  2370. if (this.tooltipTimer) {
  2371. window.clearTimeout(this.tooltipTimer);
  2372. this.tooltipTimer = null;
  2373. }
  2374. var rtChart = this;
  2375. this.tooltipTimer = window.setTimeout(
  2376. function () {
  2377. if (rtChart.tooltipTimer) {
  2378. window.clearTimeout(rtChart.tooltipTimer);
  2379. rtChart.tooltipTimer = null;
  2380. }
  2381. var gh = rtChart.getGridHeight();
  2382. var o = rtChart.canvas.offset();
  2383. var y = e.pageY - o.top;
  2384. var ta = (y > gh / 2) ? 'bottom' : 'top';
  2385. var opt = {
  2386. title: "值线",
  2387. content: rtChart._gethIndicatorTooltipContent(),
  2388. align: ta,
  2389. padding: 10,
  2390. width: 300,
  2391. skin: 'tooltipTans'
  2392. };
  2393. rtChart.artTooltip = dialog(opt);
  2394. rtChart.artTooltip.show(rtChart.hIndicator.get(0));
  2395. rtChart.btipShow = true;
  2396. rtChart.tootipAt = "HI";
  2397. rtChart = null;
  2398. }, this.options.tooltipDelay || 1000);
  2399. },
  2400. _onhIndicatorMove: function (event) {
  2401. if (this.artTooltip && this.tootipAt == "HI" && this.artTooltip.__popup)
  2402. this.artTooltip.content(this._gethIndicatorTooltipContent());
  2403. },
  2404. _onhIndicatorMoveEnd: function (event) {
  2405. if (this.artTooltip && this.tootipAt == "HI" && this.artTooltip.__popup)
  2406. this.artTooltip.content(this._gethIndicatorTooltipContent());
  2407. },
  2408. _gethIndicatorTooltipContent: function () {
  2409. var gh = this.getGridHeight();
  2410. var iy = this.hIndicator.offset().top - this.canvas.offset().top + 5;
  2411. var content = null;
  2412. if (this.trendPens) {
  2413. var arr = [];
  2414. for (var i in this.trendPens)
  2415. arr.push(this.trendPens[i].getValueLine(iy));
  2416. if (arr.length)
  2417. content = arr.join("");
  2418. }
  2419. return content;
  2420. },
  2421. _onvIndicatorHover: function (e) {
  2422. if (this.loginning === true)
  2423. return;
  2424. if (this.artTooltip && this.tootipAt == "VI" && this.artTooltip.__popup)
  2425. return;
  2426. if (this.tooltipTimer) {
  2427. window.clearTimeout(this.tooltipTimer);
  2428. this.tooltipTimer = null;
  2429. }
  2430. var rtChart = this;
  2431. var gw = rtChart.getGridWidth();
  2432. var o = rtChart.canvas.offset();
  2433. var x = e.pageX - o.left;
  2434. var ta = (x > gw / 2) ? 'left top' : 'left top';
  2435. var currentTime = {};
  2436. var opt = {
  2437. title: rtChart._getvIndicatorTooltipTitle(currentTime),
  2438. content: rtChart._getvIndicatorTooltipContent(currentTime),
  2439. align: ta,
  2440. padding: 10,
  2441. width: 320,
  2442. skin: 'tooltipTans'
  2443. };
  2444. if (opt.content != null) {
  2445. rtChart.artTooltip = dialog(opt);
  2446. rtChart.artTooltip.show(rtChart.vIndicator.get(0));
  2447. rtChart.btipShow = true;
  2448. rtChart.tootipAt = "VI";
  2449. }
  2450. rtChart = null;
  2451. },
  2452. _onvIndicatorMove: function (e) {
  2453. if (this.artTooltip && this.tootipAt == "VI" && this.artTooltip.__popup) {
  2454. this.artTooltip.reset();
  2455. this._updatevIndicatorTooltip();
  2456. }
  2457. },
  2458. _onvIndicatorMoveEnd: function (e) {
  2459. this._updatevIndicatorTooltip();
  2460. },
  2461. _updatevIndicatorTooltip: function () {
  2462. if (this.artTooltip && this.tootipAt == "VI" && this.artTooltip.__popup) {
  2463. if (this.vTooltipTimer == null) {
  2464. var rtChart = this;
  2465. this.vTooltipTimer = window.setTimeout(function () {
  2466. window.clearTimeout(rtChart.vTooltipTimer);
  2467. rtChart.vTooltipTimer = null;
  2468. var currTime = {};
  2469. rtChart.artTooltip.title(rtChart._getvIndicatorTooltipTitle(currTime));
  2470. rtChart.artTooltip.content(rtChart._getvIndicatorTooltipContent(currTime));
  2471. rtChart = null;
  2472. }, 100);
  2473. }
  2474. }
  2475. if (this.trendPens) {
  2476. for (var i in this.trendPens)
  2477. this.trendPens[i].updateDataReader();
  2478. }
  2479. },
  2480. _getvIndicatorTooltipTitle: function (currTime) {
  2481. var gw = this.getGridWidth();
  2482. var ix = this.vIndicator.position().left + 5;
  2483. var begTime = this.getDrawBegTime();
  2484. var endTime = this.getDrawEndTime();
  2485. var span = endTime - begTime;
  2486. var timeScale = span / gw;
  2487. var ft = begTime + ix * timeScale;
  2488. var title = "";
  2489. var date = this.FileTimeToDate(ft);
  2490. if (span > 28 * PERDAY)
  2491. title += date.getFullYear() + "年";
  2492. if (span > PERDAY)
  2493. title += (date.getMonth() + 1) + "月";
  2494. if (span > PERHOUR)
  2495. title += date.getDate() + "日";
  2496. title += this.FileTimeToTimeString(ft, true);
  2497. title += " 附近的值";
  2498. currTime.ft = ft;
  2499. return title;
  2500. },
  2501. _getvIndicatorTooltipContent: function (currentTime) {
  2502. var ft = currentTime.ft;
  2503. if (this.trendPens) {
  2504. var content = [];
  2505. for (var i in this.trendPens)
  2506. content.push(this.trendPens[i].getValueTooltipAtTime(ft));
  2507. if (content.length)
  2508. return content.join("");
  2509. else
  2510. return null;
  2511. } else
  2512. return null;
  2513. },
  2514. posvIndicator: function (ft) {
  2515. if (ft >= this.getBegTime() && ft <= this.getEndTime()) {
  2516. if (this.options.rtRefresh)
  2517. this.setRtrefresh(false);
  2518. if (ft <= this.getDrawBegTime() || ft >= this.getDrawEndTime()) {
  2519. this._resetTumbs();
  2520. this.updateDataArea();
  2521. }
  2522. var begTime = this.getDrawBegTime();
  2523. var endTime = this.getDrawEndTime();
  2524. var gw = this.getGridWidth();
  2525. var span = endTime - begTime;
  2526. var timeScale = span / gw;
  2527. var posX = Math.floor((ft - this.getDrawBegTime()) / timeScale) - 6;
  2528. while (1) {
  2529. this.vIndicator.css("left", posX - 5);
  2530. var ix = this.vIndicator.position().left + 5;
  2531. if (begTime + ix * timeScale >= ft)
  2532. break;
  2533. posX++;
  2534. }
  2535. }
  2536. },
  2537. getReaderTimer: function () {
  2538. var gw = this.getGridWidth();
  2539. var ix = this.vIndicator.position().left + 5;
  2540. var begTime = this.getDrawBegTime();
  2541. var endTime = this.getDrawEndTime();
  2542. var span = endTime - begTime;
  2543. var timeScale = span / gw;
  2544. var ft = begTime + ix * timeScale;
  2545. return ft;
  2546. },
  2547. getHisRefreshing: function () {
  2548. return this.options.rtRefresh;
  2549. },
  2550. panCanShow: function () {
  2551. if (!this.options.panWidth || this.options.panWidth < MINPANWIDTH)
  2552. this.options.panWidth = MINPANWIDTH;
  2553. if (this.chartWidth < 100 + this.options.panWidth)
  2554. return false;
  2555. else
  2556. return true;
  2557. },
  2558. thumbsCanshow: function () {
  2559. if (this.options.showThumbs && this.chartHeight > SHOWTHUMBSHLIMT)
  2560. return true;
  2561. else
  2562. return false;
  2563. },
  2564. thumbsShow: function () {
  2565. if (this.options.showThumbs && this.chartHeight > SHOWTHUMBSHLIMT) {
  2566. var beg = this.thumbBegDiv.position().left + 3;
  2567. var end = this.thumbEndDiv.position().left + 3;
  2568. if (beg > 0 || end < this.chartWidth)
  2569. return true;
  2570. else
  2571. return false;
  2572. } else
  2573. return false;
  2574. },
  2575. _tumbsCanDrag: function (x) {
  2576. var beg = this.thumbBegDiv.position().left + 3;
  2577. var end = this.thumbEndDiv.position().left + 3;
  2578. if ((x > beg && x < end) && (beg > 0 || end < this.chartWidth))
  2579. return true;
  2580. else
  2581. return false;
  2582. },
  2583. listCanshow: function () {
  2584. if (this.options.showList && (this.chartHeight - this.options.listHeight) > 200)
  2585. return true;
  2586. else
  2587. return false;
  2588. },
  2589. toolBarCanShow: function () {
  2590. if (this.chartHeight > SHOWTOOLBARHLIMIT)
  2591. return true;
  2592. else
  2593. return false;
  2594. },
  2595. slidCanShow: function () {
  2596. if (this.chartHeight > SLIDHLIMIT)
  2597. return true;
  2598. else
  2599. return false;
  2600. },
  2601. setListHeight: function (h) {
  2602. if (this.options.listHeight == h) {
  2603. if (this.hSplite) {
  2604. var canvas = this.hSplite.get(0);
  2605. var ctx = canvas.getContext("2d");
  2606. if (this.options.buttonImage && this.options.buttonImage.get(0).complete === true) {
  2607. var img = this.options.buttonImage.get(0);
  2608. if (this.options.listExpand)
  2609. ctx.drawImage(img, 10, 11, 35, 5, canvas.width / 2 - 18, 0, 35, 5);
  2610. else
  2611. ctx.drawImage(img, 10, 15, 35, 5, canvas.width / 2 - 18, 0, 35, 5);
  2612. }
  2613. }
  2614. return;
  2615. }
  2616. this.options.listHeight = h;
  2617. if (this.options.listHeight < 30)
  2618. this.options.listExpand = false;
  2619. else
  2620. this.options.listExpand = true;
  2621. if (this.artTooltip)
  2622. this.artTooltip.close().reset().remove();
  2623. this._bulidCanvas();
  2624. },
  2625. setListExpand: function (bExpand) {
  2626. if (this.options.listExpand == bExpand)
  2627. return;
  2628. if (bExpand) {
  2629. if (!this.listCanshow())
  2630. return;
  2631. }
  2632. this.options.listExpand = bExpand;
  2633. if (this.artTooltip)
  2634. this.artTooltip.close().reset().remove();
  2635. this._bulidCanvas();
  2636. },
  2637. getPanShow: function () {
  2638. return this.options.panShow;
  2639. },
  2640. setPanShow: function (bShow) {
  2641. if (this.options.panShow == bShow)
  2642. return;
  2643. if (bShow) {
  2644. if (!this.panCanShow())
  2645. return;
  2646. }
  2647. this.options.panShow = bShow;
  2648. this._reDrawAll();
  2649. },
  2650. setPanWidth: function (w) {
  2651. if (this.options.panWidth == w)
  2652. return;
  2653. this.options.panWidth = w;
  2654. if (this.chartWidth < 100 + this.options.panWidth || this.options.panWidth < MINPANWIDTH)
  2655. this.options.panShow = false;
  2656. this._reDrawAll();
  2657. },
  2658. getPanWidth: function () {
  2659. return this.options.panWidth - PANMAG;
  2660. },
  2661. getOffset: function () {
  2662. return this.canvas.offset();
  2663. },
  2664. getGridWidth: function () {
  2665. return this.chartWidth - (this.options.panShow ? this.options.panWidth : 0) - 1;
  2666. },
  2667. getGridHeight: function () {
  2668. var h = this.chartHeight;
  2669. if (this.toolBarCanShow())
  2670. h -= TOOLBARHEIGHT;
  2671. if (this.listCanshow()) {
  2672. if (this.options.listExpand)
  2673. h -= this.options.listHeight;
  2674. else
  2675. h -= HSPLITHEIGHT;
  2676. }
  2677. if (this.slidCanShow())
  2678. h -= SLIDEHEIGHT;
  2679. if (this.thumbsCanshow())
  2680. h -= SHOWTHUMBSHEIGHT;
  2681. h--;
  2682. return h;
  2683. },
  2684. getNextPenColor: function () {
  2685. var i = 0;
  2686. if (this.trendPens) {
  2687. if (this.trendPens.length < penColors.length) {
  2688. i = this.trendPens.length;
  2689. return penColors[i];
  2690. } else {
  2691. i = this.trendPens.length % penColors.length;
  2692. var c = TrendColor.parse(penColors[i]);
  2693. var sign = (this.trendPens.length % 2 == 1 ? -1 : 1);
  2694. var factor = 1 + sign * Math.ceil(this.trendPens.length / 2) * 0.2;
  2695. c.scale(factor, factor, factor);
  2696. return c.toString();
  2697. }
  2698. } else
  2699. return penColors[i];
  2700. },
  2701. getButtonImage: function () {
  2702. if (this.options.buttonImage)
  2703. return this.options.buttonImage.get(0);
  2704. else
  2705. return null;
  2706. },
  2707. _updateTimeDisplay: function () {
  2708. if (!this.toolBar || this.calendarShowed === true || this.timerFocus === true)
  2709. return;
  2710. this.toolBar.setValue("date_from", this.FileTimeToDateString(this.getBegTime()) + " " + this.FileTimeToTimeString(this.getBegTime(), this.options.spanSec < 10));
  2711. this.toolBar.setValue("date_to", this.FileTimeToDateString(this.getEndTime()) + " " + this.FileTimeToTimeString(this.getEndTime(), this.options.spanSec < 10));
  2712. },
  2713. getTimeSpanString: function () {
  2714. var spanStr = "时间跨度:";
  2715. var span = this.options.spanSec * PERSEC;
  2716. if (this.options.spanSec > PERDAY) {
  2717. var d = Math.floor(span / PERDAY);
  2718. span -= d * PERDAY;
  2719. spanStr += d + "天";
  2720. }
  2721. if (this.options.spanSec * PERSEC > PERHOUR) {
  2722. var h = Math.floor(span / PERHOUR);
  2723. span -= h * PERHOUR;
  2724. spanStr += h + "时";
  2725. }
  2726. if (this.options.spanSec * PERSEC > PERMINUTE) {
  2727. var m = Math.floor(span / PERMINUTE);
  2728. span -= m * PERMINUTE;
  2729. spanStr += m + "分";
  2730. }
  2731. var s = Math.floor(span / PERSEC);
  2732. span -= s * PERSEC;
  2733. spanStr += s + "秒";
  2734. if (this.options.spanSec <= 10) {
  2735. var ms = (span / PERMSEC).toFixed(2);
  2736. spanStr += ms + "毫秒";
  2737. }
  2738. return spanStr;
  2739. },
  2740. setBegTimeAndSpan: function (begTime, span) {
  2741. span = span || 1;
  2742. if (this.options.spanSec == span && this.ftBeginTime == begTime)
  2743. return;
  2744. this.ftTimeLabelBeg = null;
  2745. this.options.spanSec = span;
  2746. if (this.ftBeginTime == begTime)
  2747. this.ftBeginTime = 0;
  2748. this.updateBeginTime(begTime);
  2749. if (this.toolBar)
  2750. this.toolBar.setItemText("timeSpan", this.getTimeSpanString());
  2751. this._updateTimeDisplay();
  2752. },
  2753. setTimeSpan: function (span, fixEnd) {
  2754. span = span || 1;
  2755. if (this.options.spanSec == span)
  2756. return;
  2757. var newBeginTime;
  2758. if (fixEnd)
  2759. newBeginTime = this.getEndTime() - span * PERSEC;
  2760. else
  2761. newBeginTime = this.getBegTime();
  2762. this.ftTimeLabelBeg = null;
  2763. this.options.spanSec = span;
  2764. if (this.ftBeginTime == newBeginTime)
  2765. this.ftBeginTime = 0;
  2766. this.updateBeginTime(newBeginTime);
  2767. if (this.toolBar)
  2768. this.toolBar.setItemText("timeSpan", this.getTimeSpanString());
  2769. this._updateTimeDisplay();
  2770. },
  2771. updateBeginTime: function (ft) {
  2772. this.setBeginTime(ft);
  2773. if (this.dataLoadTimer) {
  2774. window.clearTimeout(this.dataLoadTimer);
  2775. this.dataLoadTimer = null;
  2776. }
  2777. var rtchart = this;
  2778. this.dataLoadTimer = window.setTimeout(function () {
  2779. window.clearTimeout(rtchart.dataLoadTimer);
  2780. rtchart.dataLoadTimer = null;
  2781. if (rtchart.trendPens) {
  2782. for (i in rtchart.trendPens) {
  2783. var pen = rtchart.trendPens[i];
  2784. pen.refreshHisData(true);
  2785. }
  2786. }
  2787. rtchart = null;
  2788. }, 500);
  2789. this.updateDataArea();
  2790. this._updatevIndicatorTooltip();
  2791. },
  2792. setBeginTime: function (ft) {
  2793. if (this.ftBeginTime == ft)
  2794. return;
  2795. var old = this.ftBeginTime;
  2796. this.ftBeginTime = ft;
  2797. if (this.getHisRefreshing()) {
  2798. if (ft < old) {
  2799. this.autoRefresh = true;
  2800. this.setRtrefresh(false);
  2801. }
  2802. }
  2803. this._updateTimeDisplay();
  2804. },
  2805. setBegTime: function (begTime, fixEnd) {
  2806. var ft = this.DateToFileTime(begTime);
  2807. if (fixEnd) {
  2808. if (this.getEndTime() > ft) {
  2809. var span = this.getEndTime() - ft;
  2810. span /= PERSEC;
  2811. this.setBegTimeAndSpan(ft, span);
  2812. } else {
  2813. var d = dialog({
  2814. content: '设置的起始时间不能大于截至时间'
  2815. });
  2816. d.show();
  2817. setTimeout(function () {
  2818. d.close().remove();
  2819. d = null;
  2820. }, 2000);
  2821. }
  2822. } else {
  2823. this.ftTimeLabelBeg = null;
  2824. if (this.ftBeginTime == ft)
  2825. this.ftBeginTime = 0;
  2826. this.updateBeginTime(ft);
  2827. }
  2828. },
  2829. setEndTime: function (endTime, fixBeg) {
  2830. var ft = this.DateToFileTime(endTime);
  2831. if (fixBeg) {
  2832. if (ft > this.getBegTime()) {
  2833. var span = ft - this.getBegTime();
  2834. span /= PERSEC;
  2835. ft -= this.options.spanSec * PERSEC;
  2836. this.setBegTimeAndSpan(ft, span);
  2837. } else {
  2838. var d = dialog({
  2839. content: '设置的截至时间不能大于起始时间'
  2840. });
  2841. d.show();
  2842. setTimeout(function () {
  2843. d.close().remove();
  2844. d = null;
  2845. }, 2000);
  2846. }
  2847. } else {
  2848. ft -= this.options.spanSec * PERSEC;
  2849. this.ftTimeLabelBeg = null;
  2850. if (this.ftBeginTime == ft)
  2851. this.ftBeginTime = 0;
  2852. this.updateBeginTime(ft);
  2853. }
  2854. },
  2855. getBegTime: function () {
  2856. return this.ftBeginTime;
  2857. },
  2858. getEndTime: function () {
  2859. return this.ftBeginTime + (this.options.spanSec * PERSEC);
  2860. },
  2861. getTimeSlot: function () {
  2862. var slotTime = this.options.spanSec * PERSEC;
  2863. slotTime /= this.getGridWidth();
  2864. return slotTime;
  2865. },
  2866. getTimeSpan: function () {
  2867. return this.options.spanSec * PERSEC;
  2868. },
  2869. getDrawBegTime: function () {
  2870. var begTime = this.getBegTime();
  2871. if (this.thumbsShow()) {
  2872. var beg = this.thumbBegDiv.position().left + 3;
  2873. if (beg > 0) {
  2874. var w = this.chartWidth - 1;
  2875. begTime += beg * this.options.spanSec * PERSEC / w;
  2876. }
  2877. }
  2878. return begTime;
  2879. },
  2880. getDrawEndTime: function () {
  2881. var endTime = this.getEndTime();
  2882. if (this.thumbsShow()) {
  2883. var end = this.thumbEndDiv.position().left + 3;
  2884. var w = this.chartWidth - 1;
  2885. if (end < w) {
  2886. endTime -= (w - end) * this.options.spanSec * PERSEC / w;
  2887. }
  2888. }
  2889. return endTime;
  2890. },
  2891. _setNewLastTime: function (lastft) {
  2892. if (lastft <= this.getEndTime())
  2893. return;
  2894. var newTimeBegin = lastft - (this.options.spanSec * PERSEC);
  2895. if (!this.newTimeBegin || this.newTimeBegin < newTimeBegin)
  2896. this.newTimeBegin = newTimeBegin;
  2897. },
  2898. _onNewHisData: function () {
  2899. if (!this.prepareTimer) {
  2900. var me = this;
  2901. this.prepareTimer = window.setTimeout(function () {
  2902. window.clearTimeout(me.prepareTimer);
  2903. me.prepareTimer = null;
  2904. me._prepareHisData();
  2905. me = null;
  2906. }, 10);
  2907. }
  2908. },
  2909. _prepareHisData: function () {
  2910. if (!this.trendPens || !this.trendPens.length)
  2911. return;
  2912. var begTime, endTime;
  2913. var baseChanged = false;
  2914. var newTimeBeg = this.newTimeBegin;
  2915. if (newTimeBeg > this.getBegTime()) {
  2916. baseChanged = true;
  2917. begTime = this.newTimeBegin;
  2918. endTime = begTime + (this.options.spanSec * PERSEC);
  2919. this.newTimeBegin = null;
  2920. }
  2921. if (!baseChanged) {
  2922. begTime = this.getBegTime();
  2923. endTime = this.getEndTime();
  2924. }
  2925. for (k in this.trendPens) {
  2926. var pen = this.trendPens[k];
  2927. pen.prepareHisData(begTime, endTime);
  2928. }
  2929. if (baseChanged) {
  2930. this.setBeginTime(begTime);
  2931. if (!this.getHisRefreshing())
  2932. this.setRtrefresh(true);
  2933. this._drawTimeLabel();
  2934. } else if (!this.getHisRefreshing()) {
  2935. if (newTimeBeg >= this.getBegTime() - (this.options.spanSec * PERSEC) * 20 / this.getGridWidth())
  2936. this.setRtrefresh(true);
  2937. }
  2938. this.updateDataArea();
  2939. },
  2940. _getPanTotalHeight: function () {
  2941. if (!this.trendPens || !this.trendPens.length)
  2942. return 0;
  2943. var t = 0;
  2944. for (var i = 0; i < this.trendPens.length; i++) {
  2945. var pen = this.trendPens[i];
  2946. t += pen.getPanHeight();
  2947. }
  2948. return t;
  2949. },
  2950. _findDragThing: function (e) {
  2951. this.dargWho = null;
  2952. var gw = this.getGridWidth();
  2953. var gh = this.getGridHeight();
  2954. var o = this.getOffset();
  2955. var dragEvent = e;
  2956. if (e.originalEvent &&
  2957. e.originalEvent.changedTouches &&
  2958. e.originalEvent.changedTouches[0])
  2959. dragEvent = e.originalEvent.changedTouches[0];
  2960. var x = dragEvent.pageX - o.left;
  2961. var y = dragEvent.pageY - o.top;
  2962. if (this.options.panShow && !this.options.showAxis && x > gw + PANMAG && y < gh) //@pan
  2963. {
  2964. var t = PANHEAD;
  2965. x -= (gw + PANMAG);
  2966. if (y < t) { } else if (this.trendPens) {
  2967. y -= t;
  2968. y += this.yScroll;
  2969. t = 0;
  2970. var dargPen = null;
  2971. for (var i = 0; i < this.trendPens.length; i++) {
  2972. var pen = this.trendPens[i];
  2973. if (y >= t && y <= t + pen.getPanHeight() &&
  2974. pen == this.activePen) {
  2975. dargPen = pen;
  2976. break;
  2977. } else
  2978. t += pen.getPanHeight();
  2979. }
  2980. if (dargPen) {
  2981. this.dargWho = "penPan";
  2982. this.origVal = this.getPenIndex(dargPen);
  2983. } else if (t > gh - PANHEAD) {
  2984. this.dargWho = "pan";
  2985. this.origVal = this.yScroll;
  2986. }
  2987. }
  2988. } else if (x > 0) {
  2989. var activeDrag = false;
  2990. if (y >= 0 && y <= gh) {
  2991. if (this.trendPens) {
  2992. var ft = this._getXTime(x);
  2993. for (var i in this.trendPens) {
  2994. var pen = this.trendPens[i];
  2995. if (pen == this.activePen && pen.hasDataAtTime(ft, y)) {
  2996. activeDrag = true;
  2997. break;
  2998. }
  2999. }
  3000. }
  3001. if (this.zooming === true) {
  3002. this.dargWho = "dataArea";
  3003. this.origVal = this.getBegTime();
  3004. } else if (activeDrag) {
  3005. this.origSecVal = dragEvent.pageY;
  3006. this.dargWho = "activePen";
  3007. this.origVal = this.getBegTime();
  3008. } else {
  3009. this.dargWho = "dataArea";
  3010. this.origVal = this.getBegTime();
  3011. }
  3012. } else if (y > gh && y < gh + TIMELABELHEIGHT) {
  3013. this.dargWho = "timeLabel";
  3014. this.origVal = this.getBegTime();
  3015. } else if (y > gh + TIMELABELHEIGHT && this.thumbsCanshow(x)) {
  3016. if (this._tumbsCanDrag(x)) {
  3017. this.dargWho = "tumbsDrag";
  3018. }
  3019. }
  3020. }
  3021. },
  3022. _getPanPenAtMouse: function (e) {
  3023. if (this.options.panShow) {
  3024. if (this.trendPens) {
  3025. var gw = this.getGridWidth();
  3026. var gh = this.getGridHeight();
  3027. var o = this.getOffset();
  3028. var dragEvent = e;
  3029. if (e.originalEvent &&
  3030. e.originalEvent.changedTouches &&
  3031. e.originalEvent.changedTouches[0])
  3032. dragEvent = e.originalEvent.changedTouches[0];
  3033. var x = dragEvent.pageX - o.left;
  3034. var y = dragEvent.pageY - o.top;
  3035. if (this.options.panShow && x > gw + PANMAG && y < gh) //@pan
  3036. {
  3037. var t = PANHEAD;
  3038. x -= (gw + PANMAG);
  3039. if (y < t) { } else {
  3040. y -= t;
  3041. y += this.yScroll;
  3042. t = 0;
  3043. for (var i = 0; i < this.trendPens.length; i++) {
  3044. var pen = this.trendPens[i];
  3045. if (y >= t && y <= t + pen.getPanHeight())
  3046. return pen;
  3047. else
  3048. t += pen.getPanHeight();
  3049. }
  3050. }
  3051. }
  3052. }
  3053. }
  3054. return null;
  3055. },
  3056. _getXTime: function (x) {
  3057. return this.getDrawBegTime() + (this.getDrawEndTime() - this.getDrawBegTime()) * x / this.getGridWidth();
  3058. },
  3059. _onMouseWheel: function (e) {
  3060. var gw = this.getGridWidth();
  3061. var gh = this.getGridHeight();
  3062. var o = this.getOffset();
  3063. var x = e.pageX - o.left;
  3064. var y = e.pageY - o.top;
  3065. if (this.options.panShow && x > gw + PANMAG && y < gh) //@pan
  3066. {
  3067. if (gh < PANHEAD + this._getPanTotalHeight()) {
  3068. this.yScroll += ((e.deltaY * 10) * -1);
  3069. this.UpdateDataPan(true);
  3070. }
  3071. } else if (x > 0 && x < gw) {
  3072. if (y >= 0 && y <= gh) {
  3073. if (this.trendPens) {
  3074. var ft = this._getXTime(x);
  3075. for (var i in this.trendPens) {
  3076. var pen = this.trendPens[i];
  3077. if (pen == this.activePen) {
  3078. pen.expendY(e.deltaY * -2);
  3079. break;
  3080. }
  3081. }
  3082. }
  3083. }
  3084. }
  3085. },
  3086. _onRtchartMouseMove: function (e) {
  3087. if (this._isTouch())
  3088. return;
  3089. var rtchart = this
  3090. var vSplite = this.vSplite,
  3091. vsLeft = parseInt(vSplite.css('left')) - 10;
  3092. this.vIndicator.offset({ // 不超过分割线
  3093. left: e.pageX > vsLeft ? vsLeft : e.pageX
  3094. });
  3095. // this._updatevIndicatorTooltip();
  3096. // 节流
  3097. this.__timer__ && clearTimeout(this.__timer__);
  3098. (function (e) {
  3099. if (e.pageX > vsLeft) return;
  3100. this.__timer__ = setTimeout(function () {
  3101. rtchart._onvIndicatorHover(e);
  3102. }, 300)
  3103. })(e);
  3104. // this.vIndicator.trigger(e);
  3105. // }
  3106. },
  3107. _onMouseDown: function (e) {
  3108. if (this._isTouch())
  3109. return;
  3110. if (this.artTooltip)
  3111. this.artTooltip.close().remove();
  3112. if (this.tooltipTimer) {
  3113. window.clearTimeout(this.tooltipTimer);
  3114. this.tooltipTimer = null;
  3115. }
  3116. var rtchart = this
  3117. this._findDragThing(e);
  3118. if (this.dargWho) {
  3119. this.dragStartEvent = e;
  3120. this.positionDiv.draggable("option", "disabled", false);
  3121. this.positionDiv.bind("drag", function (event, ui) {
  3122. rtchart._dragMove(event);
  3123. });
  3124. this.positionDiv.bind("dragstop", function (event, ui) {
  3125. rtchart._unDarg();
  3126. rtchart = null;
  3127. });
  3128. this.positionDiv.offset({
  3129. left: e.pageX - 2,
  3130. top: e.pageY - 2
  3131. });
  3132. this.positionDiv.trigger(e);
  3133. if (this.dargWho == 'dataArea' && this.zooming)
  3134. this.positionDiv.addClass('zoomcur');
  3135. this.dragTimer = window.setTimeout(function () {
  3136. var dargWho = rtchart.dargWho;
  3137. window.clearTimeout(rtchart.dragTimer);
  3138. rtchart.dragTimer = null;
  3139. rtchart._unDarg();
  3140. if (dargWho == "tumbsDrag")
  3141. rtchart._ondbClick(e);
  3142. else
  3143. rtchart._onClick(e);
  3144. rtchart = null;
  3145. }, 200);
  3146. }
  3147. },
  3148. _dragMove: function (e) {
  3149. if (this.dragTimer) {
  3150. window.clearTimeout(this.dragTimer);
  3151. this.dragTimer = null;
  3152. }
  3153. if (this.dragStartEvent && this.dargWho) {
  3154. var gw = this.getGridWidth();
  3155. var gh = this.getGridHeight();
  3156. var startEvent = this.dragStartEvent;
  3157. var detX = e.clientX - startEvent.clientX;
  3158. var detY = e.clientY - startEvent.clientY;
  3159. switch (this.dargWho) {
  3160. case 'pan':
  3161. this.yScroll = this.origVal - detY;
  3162. this.UpdateDataPan(true);
  3163. break;
  3164. case 'penPan':
  3165. var pen = this._getPanPenAtMouse(e);
  3166. if (pen) {
  3167. var newPos = this.getPenIndex(pen)
  3168. if (newPos != this.origVal && newPos != this.newPenPos) {
  3169. this.newPenPos = newPos;
  3170. this.UpdateDataPan(true);
  3171. } else if (this.trendPens && this.getGridHeight() < PANHEAD + this._getPanTotalHeight()) {
  3172. var gh = this.getGridHeight();
  3173. var o = this.getOffset();
  3174. var y = e.pageY - o.top;
  3175. if (y < 20) {
  3176. if (this.yScroll > 0) {
  3177. this.yScroll -= pen.getPanHeight();
  3178. this.UpdateDataPan(true);
  3179. }
  3180. } else if (y > gh - 10) {
  3181. this.yScroll += pen.getPanHeight();
  3182. this.UpdateDataPan(true);
  3183. }
  3184. }
  3185. }
  3186. break;
  3187. case 'timeLabel':
  3188. this.setBeginTime(this.origVal - detX * (this.getDrawEndTime() - this.getDrawBegTime()) / gw);
  3189. this.updateDataArea();
  3190. break;
  3191. case 'activePen':
  3192. if (this.activePen && this.origSecVal) {
  3193. var dY = e.pageY - this.origSecVal;
  3194. if (Math.abs(detY) > 5) {
  3195. this.activePen.moveY(dY);
  3196. this.origSecVal = e.pageY;
  3197. }
  3198. }
  3199. if (Math.abs(detX) > 30) {
  3200. this.acvtimePenTimeOffset = true;
  3201. this.setBeginTime(this.origVal - detX * (this.getDrawEndTime() - this.getDrawBegTime()) / gw);
  3202. this.updateDataArea();
  3203. }
  3204. break;
  3205. case 'dataArea':
  3206. if (this.zooming) {
  3207. var o = this.canvas.offset();
  3208. var x = startEvent.pageX - o.left;
  3209. var y = startEvent.pageY - o.top;
  3210. var gw = this.getGridWidth();
  3211. var gh = this.getGridHeight();
  3212. if (x > 0 && x < gw &&
  3213. y > 0 && y < gh) {
  3214. this.zoomRect = {
  3215. x: x,
  3216. y: y,
  3217. w: detX,
  3218. h: detY
  3219. };
  3220. var x = this.zoomRect.x;
  3221. if (this.zoomRect.w < 0)
  3222. x += this.zoomRect.w;
  3223. this.zoomRect.begTime = this._getXTime(x);
  3224. this.updateDataArea();
  3225. }
  3226. } else {
  3227. this.setBeginTime(this.origVal - detX * (this.getDrawEndTime() - this.getDrawBegTime()) / gw);
  3228. this.updateDataArea();
  3229. }
  3230. break;
  3231. case 'tumbsDrag':
  3232. if (detX > 0) {
  3233. var end = this.thumbEndDiv.position().left + 3;
  3234. if (end < this.chartWidth - 3) {
  3235. var l = parseInt(this.thumbEndDiv.css('left')) + detX;
  3236. if (l > this.chartWidth - 3)
  3237. l = this.chartWidth - 3;
  3238. this.thumbEndDiv.css('left', l);
  3239. l = parseInt(this.thumbBegDiv.css('left')) + detX;
  3240. this.thumbBegDiv.css('left', l);
  3241. this._onThumbsChanged();
  3242. }
  3243. } else if (detX < 0) {
  3244. var beg = this.thumbBegDiv.position().left + 3;
  3245. if (beg > 0) {
  3246. var l = parseInt(this.thumbBegDiv.css('left')) + detX;
  3247. if (l < -3)
  3248. l = -3;
  3249. this.thumbBegDiv.css('left', l);
  3250. l = parseInt(this.thumbEndDiv.css('left')) + detX;
  3251. this.thumbEndDiv.css('left', l);
  3252. this._onThumbsChanged();
  3253. }
  3254. }
  3255. this.dragStartEvent = e;
  3256. break;
  3257. }
  3258. } else
  3259. this._unDarg();
  3260. },
  3261. _unDarg: function () {
  3262. if (this.dragTimer) {
  3263. window.clearTimeout(this.dragTimer);
  3264. this.dragTimer = null;
  3265. }
  3266. switch (this.dargWho) {
  3267. case 'penPan':
  3268. if (this.newPenPos != null) {
  3269. var pen = this.trendPens[this.newPenPos];
  3270. this.trendPens[this.newPenPos] = this.getPenByIndex(this.origVal);
  3271. this.trendPens[this.origVal] = pen;
  3272. this.newPenPos = null;
  3273. this.UpdateDataPan(true);
  3274. this._synList();
  3275. }
  3276. break;
  3277. case 'timeLabel':
  3278. if (this.trendPens) {
  3279. for (i in this.trendPens) {
  3280. var pen = this.trendPens[i];
  3281. pen.refreshHisData();
  3282. }
  3283. }
  3284. break;
  3285. case 'dataArea':
  3286. if (this.zooming) {
  3287. this._toggleZoom();
  3288. this.positionDiv.removeClass('zoomcur');
  3289. if (this.zoomRect) {
  3290. if (this.zoomRect.w < 0) {
  3291. this.zoomRect.x += this.zoomRect.w;
  3292. this.zoomRect.w *= -1;
  3293. }
  3294. if (this.zoomRect.h < 0) {
  3295. this.zoomRect.y += this.zoomRect.h;
  3296. this.zoomRect.h *= -1;
  3297. }
  3298. if (this.zoomStack == null)
  3299. this.zoomStack = [];
  3300. var zoomItem = {};
  3301. zoomItem.begTime = this.getBegTime();
  3302. zoomItem.spanTime = this.options.spanSec;
  3303. this.zoomStack.push(zoomItem);
  3304. this._updateReZoom();
  3305. var begTime = this.zoomRect.begTime;
  3306. var span = (this.getDrawEndTime() - this.getDrawBegTime()) * this.zoomRect.w / this.getGridWidth();
  3307. if (span < 1)
  3308. span = 1;
  3309. var endTime = begTime + span;
  3310. if (this.trendPens) {
  3311. for (i in this.trendPens) {
  3312. var pen = this.trendPens[i];
  3313. if (pen.hasDataBetweenTime(begTime, endTime)) {
  3314. if (zoomItem.pens == null)
  3315. zoomItem.pens = [];
  3316. zoomItem.pens.pushpen
  3317. }
  3318. }
  3319. }
  3320. this.zoomRect = null;
  3321. this._resetTumbs();
  3322. this.setBegTimeAndSpan(begTime, span / PERSEC);
  3323. }
  3324. } else if (this.trendPens) {
  3325. for (i in this.trendPens) {
  3326. var pen = this.trendPens[i];
  3327. pen.refreshHisData();
  3328. }
  3329. }
  3330. break;
  3331. case 'activePen':
  3332. if (this.acvtimePenTimeOffset && this.trendPens) {
  3333. for (i in this.trendPens) {
  3334. var pen = this.trendPens[i];
  3335. pen.refreshHisData();
  3336. }
  3337. }
  3338. break;
  3339. }
  3340. this.origSecVal = null;
  3341. this.dargWho = null;
  3342. this.origVal = null;
  3343. this.dragStartEvent = null;
  3344. this.positionDiv.draggable("option", "disabled", true);
  3345. this.positionDiv.unbind("drag");
  3346. this.positionDiv.unbind("dragstop");
  3347. this.positionDiv.offset({
  3348. left: this.canvas.offset().left,
  3349. top: this.canvas.offset().top
  3350. });
  3351. },
  3352. _onTouchStart: function (e) {
  3353. if (this.artTooltip)
  3354. this.artTooltip.close().remove();
  3355. if (this.tooltipTimer) {
  3356. window.clearTimeout(this.tooltipTimer);
  3357. this.tooltipTimer = null;
  3358. }
  3359. this._findDragThing(e);
  3360. if (this.dargWho) {
  3361. this.dragStartEvent = e;
  3362. var rtchart = this;
  3363. this.canvas.bind('touchmove', function (e) {
  3364. rtchart._onTouchMove(e);
  3365. });
  3366. this.canvas.bind('touchend', function (e) {
  3367. rtchart._onTouchEnd(e);
  3368. rtchart = null;
  3369. });
  3370. this.dragTimer = window.setTimeout(function () {
  3371. window.clearTimeout(rtchart.dragTimer);
  3372. rtchart.dragTimer = null;
  3373. if (rtchart.tooltipTimer) {
  3374. window.clearTimeout(rtchart.tooltipTimer);
  3375. rtchart.tooltipTimer = null;
  3376. }
  3377. rtchart._onTouchEnd();
  3378. rtchart = null;
  3379. }, 800);
  3380. }
  3381. },
  3382. _onTouchMove: function (e) {
  3383. if (this.dragTimer) {
  3384. window.clearTimeout(this.dragTimer);
  3385. this.dragTimer = null;
  3386. }
  3387. if (this.dragStartEvent && this.dargWho) {
  3388. var startEvent = this.dragStartEvent.originalEvent.changedTouches[0];
  3389. var currEvent = e.originalEvent.changedTouches[0];
  3390. var detX = currEvent.clientX - startEvent.clientX;
  3391. var detY = currEvent.clientY - startEvent.clientY;
  3392. switch (this.dargWho) {
  3393. case 'pan':
  3394. this.yScroll = this.origVal - detY;
  3395. this.UpdateDataPan(true);
  3396. break;
  3397. case 'penPan':
  3398. var pen = this._getPanPenAtMouse(e);
  3399. if (pen) {
  3400. var newPos = this.getPenIndex(pen)
  3401. if (newPos != this.origVal && newPos != this.newPenPos) {
  3402. this.newPenPos = newPos;
  3403. this.UpdateDataPan(true);
  3404. } else if (this.trendPens && this.getGridHeight() < PANHEAD + this._getPanTotalHeight()) {
  3405. var gh = this.getGridHeight();
  3406. var o = this.getOffset();
  3407. var y = currEvent.pageY - o.top;
  3408. if (y < 20) {
  3409. if (this.yScroll > 0) {
  3410. this.yScroll -= pen.getPanHeight();
  3411. this.UpdateDataPan(true);
  3412. }
  3413. } else if (y > gh - 10) {
  3414. this.yScroll += pen.getPanHeight();
  3415. this.UpdateDataPan(true);
  3416. }
  3417. }
  3418. }
  3419. break;
  3420. default:
  3421. this._onTouchEnd();
  3422. return;
  3423. }
  3424. } else
  3425. this._onTouchEnd();
  3426. },
  3427. _onTouchEnd: function (e) {
  3428. if (this.dragTimer) {
  3429. window.clearTimeout(this.dragTimer);
  3430. this.dragTimer = null;
  3431. }
  3432. if (this.newPenPos != null) {
  3433. var pen = this.trendPens[this.newPenPos];
  3434. this.trendPens[this.newPenPos] = this.getPenByIndex(this.origVal);
  3435. this.trendPens[this.origVal] = pen;
  3436. this.newPenPos = null;
  3437. this.UpdateDataPan(true);
  3438. }
  3439. this.canvas.unbind('touchmove');
  3440. this.canvas.unbind('touchend');
  3441. this.dargWho = null;
  3442. this.origVal = null;
  3443. this.dragStartEvent = null;
  3444. },
  3445. _onKeyDown: function (e) {
  3446. switch (e.which) {
  3447. case 39: //right
  3448. if (this.artTooltip && this.tootipAt == "VI" && this.artTooltip.__popup) {
  3449. if (this.thumbsShow()) {
  3450. var x = this.vIndicator.position().left + 5;
  3451. var endTime = this._getXTime(x + 2);
  3452. var limit = this.getDrawEndTime();
  3453. if (endTime >= limit) {
  3454. var l = parseInt(this.thumbEndDiv.css('left'));
  3455. var s = l + 10;
  3456. if (s > this.chartWidth - 3)
  3457. s = this.chartWidth - 3;
  3458. if (s > l) {
  3459. this.thumbEndDiv.css('left', s);
  3460. s = parseInt(this.thumbBegDiv.css('left')) + s - l;
  3461. if (s > this.chartWidth - 13)
  3462. s = this.chartWidth - 13;
  3463. this.thumbBegDiv.css('left', s);
  3464. this._onThumbsChanged();
  3465. }
  3466. }
  3467. }
  3468. var gw = this.getGridWidth();
  3469. var off = this.vIndicator.offset();
  3470. if (off.left + 1 <= this.canvas.offset().left + gw - 5) {
  3471. this.vIndicator.offset({
  3472. left: off.left + 1,
  3473. top: off.top
  3474. });
  3475. this.artTooltip.reset();
  3476. this._updatevIndicatorTooltip();
  3477. }
  3478. } else {
  3479. var gw = this.getGridWidth();
  3480. var begTime = this.getDrawBegTime();
  3481. var endTime = this.getDrawEndTime();
  3482. var det = (endTime - begTime) / gw;
  3483. this.updateBeginTime(this.getBegTime() - det);
  3484. }
  3485. break;
  3486. case 37: //left
  3487. if (this.artTooltip && this.tootipAt == "VI" && this.artTooltip.__popup) {
  3488. if (this.thumbsShow()) {
  3489. var x = this.vIndicator.position().left + 5;
  3490. var begTime = this._getXTime(x - 2);
  3491. var limit = this.getDrawBegTime();
  3492. if (begTime <= limit) {
  3493. var l = parseInt(this.thumbBegDiv.css('left'));
  3494. var s = l - 10;
  3495. if (s < -3)
  3496. s = -3;
  3497. if (s < l) {
  3498. this.thumbBegDiv.css('left', s);
  3499. s = parseInt(this.thumbEndDiv.css('left')) - (l - s);
  3500. if (s < 13)
  3501. s = 13;
  3502. this.thumbEndDiv.css('left', s);
  3503. this._onThumbsChanged();
  3504. }
  3505. }
  3506. }
  3507. var gw = this.getGridWidth();
  3508. var off = this.vIndicator.offset();
  3509. if (off.left - 1 >= this.canvas.offset().left - 5) {
  3510. this.vIndicator.offset({
  3511. left: off.left - 1,
  3512. top: off.top
  3513. });
  3514. this.artTooltip.reset();
  3515. this._updatevIndicatorTooltip();
  3516. }
  3517. } else {
  3518. var gw = this.getGridWidth();
  3519. var begTime = this.getDrawBegTime();
  3520. var endTime = this.getDrawEndTime();
  3521. var det = (endTime - begTime) / gw;
  3522. this.updateBeginTime(this.getBegTime() + det);
  3523. }
  3524. break;
  3525. case 38: //up
  3526. if (this.artTooltip && this.tootipAt == "HI" && this.artTooltip.__popup) {
  3527. var gh = this.getGridHeight();
  3528. var off = this.hIndicator.offset();
  3529. if (off.top - 1 >= this.canvas.offset().top - 5) {
  3530. this.hIndicator.offset({
  3531. left: off.left,
  3532. top: off.top - 1
  3533. });
  3534. this.artTooltip.content(this._gethIndicatorTooltipContent());
  3535. this.artTooltip.reset();
  3536. }
  3537. } else if (this.activePen)
  3538. this.activePen.moveY(-1);
  3539. break;
  3540. case 40: //down
  3541. if (this.artTooltip && this.tootipAt == "HI" && this.artTooltip.__popup) {
  3542. var gh = this.getGridHeight();
  3543. var off = this.hIndicator.offset();
  3544. if (off.top + 1 <= this.canvas.offset().top + gh - 5) {
  3545. this.hIndicator.offset({
  3546. left: off.left,
  3547. top: off.top + 1
  3548. });
  3549. this.artTooltip.content(this._gethIndicatorTooltipContent());
  3550. this.artTooltip.reset();
  3551. }
  3552. } else if (this.activePen)
  3553. this.activePen.moveY(1);
  3554. break;
  3555. }
  3556. },
  3557. _ondbClick: function (e) {
  3558. var gw = this.getGridWidth();
  3559. var gh = this.getGridHeight();
  3560. var o = this.getOffset();
  3561. var x = e.pageX - o.left;
  3562. var y = e.pageY - o.top;
  3563. if (y > gh + TIMELABELHEIGHT && this.thumbsCanshow()) {
  3564. this._resetTumbs();
  3565. this.updateDataArea();
  3566. }
  3567. },
  3568. _onClick: function (e) {
  3569. this.canvas.attr("title", null);
  3570. this.canvas.css("cursor", "default");
  3571. if (this.btipShow === true &&
  3572. this.tipShowPen &&
  3573. this.tipShowPen.getpreventTooltipUpdate() === true) {
  3574. if (this.artTooltip)
  3575. this.artTooltip.close().remove();
  3576. return;
  3577. }
  3578. if (!this.trendPens || !this.trendPens.length)
  3579. return;
  3580. if (this.zooming)
  3581. this._toggleZoom(e);
  3582. var gw = this.getGridWidth();
  3583. var gh = this.getGridHeight();
  3584. var o = this.getOffset();
  3585. var x = e.pageX - o.left;
  3586. var y = e.pageY - o.top;
  3587. var clientx = x;
  3588. var clienty = y
  3589. if (this.options.panShow && x > gw + PANMAG && y < gh) //@pan
  3590. {
  3591. if (!this.options.showAxis) {
  3592. var t = PANHEAD;
  3593. x -= (gw + PANMAG);
  3594. if (y < t) { } else {
  3595. y -= t;
  3596. y += this.yScroll;
  3597. t = 0;
  3598. for (var i = 0; i < this.trendPens.length; i++) {
  3599. var pen = this.trendPens[i];
  3600. if (y >= t && y <= t + pen.getPanHeight()) {
  3601. if (pen.onClick(x, y - t, e) === true) { }
  3602. break;
  3603. } else
  3604. t += pen.getPanHeight();
  3605. }
  3606. }
  3607. } else {
  3608. for (var i = 0; i < this.trendPens.length; i++) {
  3609. var pen = this.trendPens[i];
  3610. var beg = pen.axisBeg;
  3611. var end = pen.axisEnd;
  3612. if (clientx >= beg && clientx <= end) {
  3613. if (this.btipShow) {
  3614. if (this.artTooltip)
  3615. this.artTooltip.close().remove();
  3616. }
  3617. pen.onSetCommAxis(e);
  3618. break;
  3619. }
  3620. }
  3621. }
  3622. } else if (y >= 0 && y < gh) {
  3623. if (this.trendPens) {
  3624. var ft = this._getXTime(x);
  3625. var oldActive = this.activePen;
  3626. var bFind = false;
  3627. var first = null;
  3628. for (var i in this.trendPens) {
  3629. pen = this.trendPens[i];
  3630. if (pen == oldActive) {
  3631. bFind = true;
  3632. this.requestActive(null);
  3633. } else if (pen.hasDataAtTime(ft, y)) {
  3634. if (bFind || oldActive == null) {
  3635. pen.activePen();
  3636. return;
  3637. } else if (first == null)
  3638. first = pen;
  3639. }
  3640. }
  3641. if (first)
  3642. first.activePen();
  3643. }
  3644. } else if (y > gh && y < gh + TIMELABELHEIGHT) {
  3645. if (x < 70)
  3646. this._onSetBegTime(e);
  3647. else if (x > gw - 80 && x < gw)
  3648. this._onSetEndTime(e);
  3649. }
  3650. },
  3651. _onMouseMove: function (e) {
  3652. if (this.colorPicker && this.colorPicker.is(":visible"))
  3653. return;
  3654. if (this.btipShow === true &&
  3655. this.tipShowPen &&
  3656. this.tipShowPen.getpreventTooltipUpdate() === true)
  3657. return;
  3658. if (!this.trendPens || !this.trendPens.length)
  3659. return;
  3660. if (this.tooltipTimer) {
  3661. window.clearTimeout(this.tooltipTimer);
  3662. this.tooltipTimer = null;
  3663. }
  3664. var oldShow = this.btipShow;
  3665. var bClearCursor = true;
  3666. var bClearNativeTooltip = true;
  3667. this.btipShow = false;
  3668. var gw = this.getGridWidth();
  3669. var gh = this.getGridHeight();
  3670. var o = this.getOffset();
  3671. var x = e.pageX - o.left;
  3672. var y = e.pageY - o.top;
  3673. var clientx = x;
  3674. var clienty = y
  3675. if (clientx > 0 && clientx < this.chartWidth &&
  3676. clienty > 0 && clienty < this.chartHeight) {
  3677. if (this.options.panShow && x > gw + PANMAG && y < gh) //@pan
  3678. {
  3679. if (this.zooming)
  3680. this.canvas.removeClass('zoomcur');
  3681. if (!this.options.showAxis) {
  3682. var t = PANHEAD;
  3683. x -= (gw + PANMAG);
  3684. if (y < t) { } else {
  3685. y -= t;
  3686. y += this.yScroll;
  3687. t = 0;
  3688. for (var i = 0; i < this.trendPens.length; i++) {
  3689. var pen = this.trendPens[i];
  3690. if (y >= t && y <= t + pen.getPanHeight()) {
  3691. if (pen.onMouseMove(x, y - t, e, clientx, clienty, gh) === true)
  3692. bClearCursor = false;
  3693. break;
  3694. } else
  3695. t += pen.getPanHeight();
  3696. }
  3697. }
  3698. } else {
  3699. for (var i = 0; i < this.trendPens.length; i++) {
  3700. var pen = this.trendPens[i];
  3701. var beg = pen.axisBeg;
  3702. var end = pen.axisEnd;
  3703. if (clientx >= beg && clientx <= end) {
  3704. bClearCursor = false;
  3705. bClearNativeTooltip = false;
  3706. this.canvas.css("cursor", "pointer");
  3707. this.canvas.attr("title", "点击进行 " + pen.getLabel() + " 的共轴设置");
  3708. break;
  3709. }
  3710. }
  3711. }
  3712. } else if (y >= 0 && y < gh) {
  3713. if (this.zooming)
  3714. this.canvas.addClass('zoomcur');
  3715. } else if (y > gh && y < gh + TIMELABELHEIGHT) {
  3716. if (this.zooming)
  3717. this.canvas.removeClass('zoomcur');
  3718. if (x < 70) {
  3719. bClearCursor = false;
  3720. bClearNativeTooltip = false;
  3721. this.canvas.css("cursor", "pointer");
  3722. this.canvas.attr("title", "点击设置查询起始时间");
  3723. } else if (x > gw - 80 && x < gw) {
  3724. bClearCursor = false;
  3725. bClearNativeTooltip = false;
  3726. this.canvas.css("cursor", "pointer");
  3727. this.canvas.attr("title", "点击设置查询截至时间");
  3728. }
  3729. } else if (y > gh + TIMELABELHEIGHT && this.thumbsCanshow()) {
  3730. if (this._tumbsCanDrag(x)) {
  3731. bClearCursor = false;
  3732. this.canvas.css("cursor", "e-resize");
  3733. }
  3734. }
  3735. }
  3736. if (bClearNativeTooltip)
  3737. this.canvas.attr("title", null);
  3738. if (bClearCursor && !this.zooming)
  3739. this.canvas.css("cursor", "default");
  3740. if (oldShow && !this.btipShow) {
  3741. if (this.artTooltip)
  3742. this.artTooltip.close().remove();
  3743. }
  3744. if (!this.btipShow && this.tipShowPen) {
  3745. this.tipShowPen.onTooltipHided();
  3746. this.tipShowPen = null;
  3747. }
  3748. },
  3749. _linkData: function (pen) {
  3750. if (!this.webLinks)
  3751. this.webLinks = [];
  3752. var url = pen.getWebURL().toLowerCase();
  3753. var webLink = this.webLinks[url];
  3754. if (webLink == null) {
  3755. webLink = new WebLink(url);
  3756. this.webLinks[url] = webLink;
  3757. }
  3758. webLink.addPen(pen);
  3759. },
  3760. _buildColorPicker: function () {
  3761. if (this.colorPicker)
  3762. return;
  3763. this.colorPicker = $(document.createElement('div'));
  3764. this.colorPicker.css("position", "absolute")
  3765. .addClass("dropdown-menu")
  3766. .addClass("colorpicker-title");
  3767. this.element.append(this.colorPicker);
  3768. this.colorPicker.append(document.createElement('div'));
  3769. $('div:first', this.colorPicker)
  3770. .attr("data-color", "rgb(255, 255, 255)")
  3771. .addClass("colorpicker-ind")
  3772. .colorpicker({
  3773. align: 'left'
  3774. });
  3775. this.colorPicker.draggable({
  3776. drag: function (event, ui) {
  3777. $('.colorpicker-ind', this).colorpicker('reposition');
  3778. }
  3779. });
  3780. var label = $(document.createElement('span'));
  3781. this.colorPicker.append(label);
  3782. label.addClass("colorpicker-label");
  3783. var prev = $(document.createElement('div'));
  3784. prev.html('<div class="colorpicker-prevbk"></div>')
  3785. this.colorPicker.append(prev);
  3786. prev
  3787. .addClass("colorpicker-prev")
  3788. .attr('title', '点击恢复到上次设置');
  3789. var resume = $(document.createElement('div'));
  3790. resume.html('<div class="colorpicker-resumebk"></div>')
  3791. this.colorPicker.append(resume);
  3792. resume
  3793. .addClass("colorpicker-resume")
  3794. .attr('title', '点击恢复初始设置');
  3795. },
  3796. AddPen: function (options) {
  3797. if (!this.trendPens)
  3798. this.trendPens = [];
  3799. var pen = new TrendPen(this, options);
  3800. for (var i = 0; i < this.trendPens.length; i++) {
  3801. if (this.trendPens[i].options.URI == pen.options.URI) {
  3802. alert(pen.options.URI + "已存在");
  3803. return;
  3804. }
  3805. }
  3806. this.trendPens.push(pen);
  3807. this._bindPenList(pen);
  3808. this._linkData(pen);
  3809. this._drawPan(false);
  3810. },
  3811. removePen: function (pen) {
  3812. if (this.tipShowPen == pen) {
  3813. if (this.artTooltip)
  3814. this.artTooltip.close().remove();
  3815. }
  3816. if (this.activePen) {
  3817. this.activePen.setActive(false);
  3818. this.activePen = null;
  3819. if (this.toolBar)
  3820. this.toolBar.disableItem("deletePoint");
  3821. }
  3822. var bFind = false;
  3823. if (this.trendPens) {
  3824. var len = this.trendPens.length;
  3825. for (var i = 0; i < len; i++) {
  3826. if (this.trendPens[i] == pen) {
  3827. bFind = true;
  3828. this.trendPens.splice(i, 1);
  3829. break;
  3830. }
  3831. }
  3832. }
  3833. if (pen.rowId != null && this.listGrid) {
  3834. this.listGrid.deleteRow(pen.rowId);
  3835. }
  3836. pen.destroy();
  3837. if (bFind) {
  3838. this.UpdatePan(true);
  3839. this.updateDataArea();
  3840. }
  3841. },
  3842. getPenIndex: function (pen) {
  3843. if (this.trendPens) {
  3844. for (var i = 0; i < this.trendPens.length; i++) {
  3845. if (this.trendPens[i] == pen)
  3846. return i;
  3847. }
  3848. }
  3849. return -1;
  3850. },
  3851. getPenByIndex: function (i) {
  3852. if (!this.trendPens)
  3853. return null;
  3854. else
  3855. return this.trendPens[i];
  3856. },
  3857. requestLogin: function (from, notCloseAutoLogClose) {
  3858. if (this.artTooltip)
  3859. this.artTooltip.close().remove();
  3860. if (this.loginning === true)
  3861. return;
  3862. this.loginning = true;
  3863. var rtChart = this;
  3864. },
  3865. getActivePen: function () {
  3866. return this.activePen;
  3867. },
  3868. ensurePenPanVisble: function (pen) {
  3869. if (this.options.panShow && !this.options.showAxis) {
  3870. var t = 0;
  3871. var gh = this.getGridHeight();
  3872. for (var i = 0; i < this.trendPens.length; i++) {
  3873. var findPen = this.trendPens[i];
  3874. if (findPen == pen) {
  3875. if (t < this.yScroll) {
  3876. this.yScroll = t;
  3877. this.UpdateDataPan(true);
  3878. } else if (t - this.yScroll + pen.getPanHeight() + PANHEAD > gh) {
  3879. this.yScroll = t + pen.getPanHeight() + PANHEAD - gh;
  3880. this.UpdateDataPan(true);
  3881. }
  3882. break;
  3883. } else
  3884. t += pen.getPanHeight();
  3885. }
  3886. }
  3887. },
  3888. requestActive: function (pen) {
  3889. if (this.activePen == pen)
  3890. return;
  3891. if (this.activePen)
  3892. this.activePen.setActive(false);
  3893. this.activePen = pen;
  3894. if (this.activePen) {
  3895. this.activePen.setActive(true);
  3896. this.ensurePenPanVisble(this.activePen);
  3897. if (this.activePen.rowId && this.listGrid && this.activePen.rowId != this.listGrid.getSelectedRowId())
  3898. this.listGrid.selectRow(this.listGrid.getRowIndex(this.activePen.rowId), false, false, true);
  3899. if (this.toolBar)
  3900. this.toolBar.enableItem("deletePoint");
  3901. } else {
  3902. if (this.toolBar)
  3903. this.toolBar.disableItem("deletePoint");
  3904. if (this.listGrid && this.listGrid.getSelectedRowId() != null)
  3905. this.listGrid.clearSelection();
  3906. }
  3907. this._drawDataArea();
  3908. },
  3909. setPenColor: function (pen, e) {
  3910. if (this.btipShow) {
  3911. if (this.artTooltip)
  3912. this.artTooltip.close().remove();
  3913. }
  3914. if (!this.colorPicker)
  3915. this._buildColorPicker();
  3916. var colorpicker = this.colorPicker;
  3917. if (colorpicker.prevColor != null) {
  3918. $('.colorpicker-prev', colorpicker).show();
  3919. $('.colorpicker-prevbk', colorpicker).css('background-color', colorpicker.prevColor);
  3920. $('.colorpicker-prev', colorpicker).bind("click", function () {
  3921. if (colorpicker) {
  3922. $('.colorpicker-ind', colorpicker).colorpicker('setValue', colorpicker.prevColor);
  3923. }
  3924. });
  3925. } else
  3926. $('.colorpicker-prev', colorpicker).hide();
  3927. colorpicker.resumeColor = pen.getPenColor();
  3928. $('.colorpicker-resume', colorpicker).bind("click", function () {
  3929. if (colorpicker) {
  3930. $('.colorpicker-ind', colorpicker).colorpicker('setValue', colorpicker.resumeColor);
  3931. }
  3932. });
  3933. var o = this.getOffset();
  3934. var x = e.pageX - o.left;
  3935. var y = e.pageY - o.top;
  3936. var at;
  3937. if (x < this.chartWidth / 2)
  3938. at = "left+15";
  3939. else
  3940. at = "right-10";
  3941. if (y < this.chartHeight / 2)
  3942. at += " top+15";
  3943. else
  3944. at += " bottom-140";
  3945. $('.colorpicker-label', colorpicker).text("设置趋势笔颜色:" + pen.getLabel());
  3946. colorpicker.show()
  3947. .position({
  3948. my: at,
  3949. of: e,
  3950. collision: "fit"
  3951. });
  3952. $('.colorpicker-resumebk', colorpicker).css('background-color', pen.getPenColor());
  3953. $('.colorpicker-ind', colorpicker)
  3954. .colorpicker('setValue', pen.getPenColor())
  3955. .colorpicker('show')
  3956. .off()
  3957. .on('changeColor.colorpicker', function (event) {
  3958. if (pen)
  3959. pen.setPenColor(event.color.toString());
  3960. })
  3961. .on('hidePicker.colorpicker', function (event) {
  3962. if (colorpicker) {
  3963. colorpicker.prevColor = $(this).data('colorpicker').color.toString();
  3964. colorpicker.hide();
  3965. $('.colorpicker-ind', colorpicker).off();
  3966. $('.colorpicker-resume', colorpicker).unbind();
  3967. $('.colorpicker-prev', colorpicker).unbind();
  3968. colorpicker = null;
  3969. }
  3970. if (pen)
  3971. pen = null;
  3972. });
  3973. },
  3974. setColors: function (who, clr) {
  3975. switch (who) {
  3976. case 'bkColor':
  3977. this.options.bkColor = clr;
  3978. this.canvas.css('background-color', clr);
  3979. break;
  3980. case 'gridColor':
  3981. if (this.options.gridColor != clr) {
  3982. this.options.gridColor = clr;
  3983. this.updateDataArea();
  3984. this.UpdateAxisPan(true);
  3985. }
  3986. break;
  3987. case 'indColor':
  3988. if (this.options.indicatorColor != clr) {
  3989. var img = this.options.buttonImage;
  3990. if (img) {
  3991. img = img.get(0);
  3992. if (img.complete !== true)
  3993. img = null;
  3994. }
  3995. var gw = this.getGridWidth();
  3996. var gh = this.getGridHeight();
  3997. var hw;
  3998. if (this.options.showAxis)
  3999. hw = this.chartWidth;
  4000. else
  4001. hw = gw + 12;
  4002. this.options.indicatorColor = clr;
  4003. var node = this.hIndicator.get(0);
  4004. var hctx = node.getContext('2d');
  4005. hctx.clearRect(0, 0, node.width, node.height);
  4006. hctx.save();
  4007. hctx.translate(0.5, 0.5);
  4008. hctx.lineWidth = 3.0;
  4009. hctx.strokeStyle = this.options.indicatorColor;
  4010. hctx.beginPath();
  4011. hctx.moveTo(1, 5);
  4012. hctx.lineTo(hw, 5);
  4013. hctx.stroke();
  4014. hctx.restore();
  4015. if (img)
  4016. hctx.drawImage(img, 11, 0, 11, 11, gw - 3, 0, 11, 11);
  4017. node = this.vIndicator.get(0);
  4018. var vctx = node.getContext('2d');
  4019. vctx.clearRect(0, 0, node.width, node.height);
  4020. vctx.save();
  4021. vctx.translate(0.5, 0.5);
  4022. vctx.lineWidth = 3.0;
  4023. vctx.strokeStyle = this.options.indicatorColor;
  4024. vctx.beginPath();
  4025. vctx.moveTo(5, 1);
  4026. vctx.lineTo(5, gh + 10);
  4027. vctx.stroke();
  4028. vctx.restore();
  4029. if (img)
  4030. vctx.drawImage(img, 0, 0, 11, 11, 0, gh - 3, 11, 11);
  4031. }
  4032. break;
  4033. case 'bordrColor':
  4034. if (this.options.borderColor != clr) {
  4035. this.options.borderColor = clr;
  4036. this._reDrawAll();
  4037. }
  4038. break;
  4039. case 'timeLabelColor':
  4040. if (this.options.timeLabelColor != clr) {
  4041. this.options.timeLabelColor = clr;
  4042. this._drawTimeLabel();
  4043. }
  4044. break;
  4045. }
  4046. },
  4047. parseDate: function (datestr) {
  4048. var date = null;
  4049. var indate = datestr.split(" ");
  4050. if (indate.length > 0) {
  4051. var d = indate[0].split("-");
  4052. if (d.length == 3) {
  4053. do {
  4054. var y = parseInt(d[0]);
  4055. if (isNaN(y) || y < 0)
  4056. break;
  4057. if (d[0].length <= 2)
  4058. y += 2000;
  4059. var m = parseInt(d[1]);
  4060. if (isNaN(m))
  4061. break;
  4062. if (m < 1 || m > 12)
  4063. break;
  4064. m--;
  4065. var day = parseInt(d[2]);
  4066. if (isNaN(day))
  4067. break;
  4068. if (day < 1 || day > 31)
  4069. break;
  4070. date = new Date(y, m, day, 0, 0, 0, 0);
  4071. if (indate.length < 2)
  4072. break;
  4073. d = indate[1].split(":");
  4074. if (d.length == 3) {
  4075. var h = parseInt(d[0]);
  4076. if (isNaN(h) || h < 0 || h > 23)
  4077. break;
  4078. date.setHours(h);
  4079. var m = parseInt(d[1]);
  4080. if (isNaN(m) || m < 0 || h > 59)
  4081. break;
  4082. date.setMinutes(m);
  4083. var s = parseInt(d[2]);
  4084. if (isNaN(s) || s < 0 || s > 59)
  4085. break;
  4086. date.setSeconds(s);
  4087. var ms = parseFloat(d[2]);
  4088. if (ms != s) {
  4089. ms -= s;
  4090. ms *= 1000;
  4091. ms = ms.toFixed(0);
  4092. date.setMilliseconds(ms);
  4093. }
  4094. }
  4095. } while (false);
  4096. }
  4097. }
  4098. return date;
  4099. },
  4100. _onSetBegTime: function (e) {
  4101. if (this.btipShow) {
  4102. if (this.artTooltip)
  4103. this.artTooltip.close().remove();
  4104. }
  4105. var rtChart = this;
  4106. var d = dialog({
  4107. title: '设置查询起始时间',
  4108. quickClose: true,
  4109. content: '<input type="text" name="dateSet" style="margin-bottom:5px; width:160px;"/><br><label><input name="fixEnd" type="checkbox" checked="checked"/>保持查询截至时间不变</label>',
  4110. onshow: function () {
  4111. var set =
  4112. $('input[name=dateSet]', this.__popup)
  4113. .val(rtChart.FileTimeToDateString(rtChart.getBegTime()) + " " + rtChart.FileTimeToTimeString(rtChart.getBegTime()))
  4114. .datetimepicker({
  4115. changeMonth: true,
  4116. changeYear: true
  4117. });
  4118. $('input[name=dateSet]', this.__popup).keydown(this, function (e) {
  4119. switch (e.which) {
  4120. case 13:
  4121. d.ok();
  4122. break;
  4123. case 27:
  4124. d.close().remove();
  4125. d = null;
  4126. rtChart = null;
  4127. break;
  4128. }
  4129. });
  4130. $('#ui-datepicker-div').draggable();
  4131. },
  4132. okValue: '确定',
  4133. ok: function () {
  4134. var date = rtChart.parseDate($('input[name=dateSet]', this.__popup).val());
  4135. if (date != null) {
  4136. var fixEnd = $('input[name=fixEnd]', this.__popup)[0].checked;
  4137. rtChart.setBegTime(date, fixEnd);
  4138. }
  4139. d.close().remove();
  4140. d = null;
  4141. },
  4142. onclose: function () {
  4143. $('input[name=dateSet]', this.__popup)
  4144. .datetimepicker("hide");
  4145. $('#ui-datepicker-div').draggable("destroy");
  4146. rtChart = null;
  4147. }
  4148. });
  4149. e.pageX += 10;
  4150. e.pageY -= 30;
  4151. d.show(e);
  4152. },
  4153. _onSetEndTime: function (e) {
  4154. if (this.btipShow) {
  4155. if (this.artTooltip)
  4156. this.artTooltip.close().remove();
  4157. }
  4158. var rtChart = this;
  4159. var d = dialog({
  4160. title: '设置查询截至时间',
  4161. quickClose: true,
  4162. content: '<input type="text" name="dateSet" style="margin-bottom:5px; width:160px;"/><br><label><input name="fixBeg" type="checkbox" checked="checked"/>保持查询起始时间不变</label>',
  4163. onshow: function () {
  4164. var set =
  4165. $('input[name=dateSet]', this.__popup)
  4166. .val(rtChart.FileTimeToDateString(rtChart.getEndTime()) + " " + rtChart.FileTimeToTimeString(rtChart.getEndTime()))
  4167. .datetimepicker({
  4168. changeMonth: true,
  4169. changeYear: true
  4170. });
  4171. $('input[name=dateSet]', this.__popup).keydown(this, function (e) {
  4172. switch (e.which) {
  4173. case 13:
  4174. d.ok();
  4175. break;
  4176. case 27:
  4177. d.close().remove();
  4178. d = null;
  4179. rtChart = null;
  4180. break;
  4181. }
  4182. });
  4183. $('#ui-datepicker-div').draggable();
  4184. },
  4185. okValue: '确定',
  4186. ok: function () {
  4187. var date = rtChart.parseDate($('input[name=dateSet]', this.__popup).val());
  4188. if (date != null) {
  4189. var fixBeg = $('input[name=fixBeg]', this.__popup)[0].checked;
  4190. rtChart.setEndTime(date, fixBeg);
  4191. }
  4192. d.close().remove();
  4193. d = null;
  4194. },
  4195. onclose: function () {
  4196. $('input[name=dateSet]', this.__popup)
  4197. .datetimepicker("hide");
  4198. $('#ui-datepicker-div').draggable("destroy");
  4199. rtChart = null;
  4200. }
  4201. });
  4202. e.pageX += 10;
  4203. e.pageY -= 30;
  4204. d.show(e);
  4205. },
  4206. _loadPoints: function (dia, grid, info, start, count, tabfilter, tagfilter, totalCount, descfilter) {
  4207. info.css("color", "rgb(0,0,100)");
  4208. info.text("正在获取数据...");
  4209. var rtchart = this;
  4210. this._loadAddPoints = true;
  4211. //注意标签点中有#号问题
  4212. var str = "http://" + webServiceIP + ":" + webServicePort + "/api/Point?start=" + start + "&count=" + count + "&filter=" + tagfilter + "&tabfilter=" + tabfilter + "&desc=" + descfilter;
  4213. $.ajax({
  4214. url: str,
  4215. type: 'GET',
  4216. dataType: 'json',
  4217. cache: false,
  4218. success: function (data) {
  4219. // if (data == null) return;
  4220. if (data.Count == 0) {
  4221. totalCount.Num = 0;
  4222. info.css("color", "rgb(0,0,100)");
  4223. info.text("未查询到相关数据点");
  4224. info.attr("title", "未查询到相关数据点)");
  4225. return;
  4226. }
  4227. totalCount.Num = data.Count;
  4228. var ind = start;
  4229. if (data.PointsPros && data.PointsPros.length > 0) {
  4230. info.css("color", "rgb(0,0,100)");
  4231. info.text("请选择一个或多个数据点:(总共:" + totalCount.Num + " 个数据点)");
  4232. info.attr("title", "(共有:" + totalCount.Num + " 个数据点)");
  4233. var pointspros = data.PointsPros;
  4234. var len = data.PointsPros.length;
  4235. var newind = 1;
  4236. var append = false;
  4237. if (grid.getRowsNum() == 0)
  4238. append = true;
  4239. for (var i = 0; i < len; i++) {
  4240. var id, name, des, unit, type;
  4241. id = pointspros[i].Id;
  4242. name = pointspros[i].TagName;
  4243. des = pointspros[i].Desc;
  4244. unit = pointspros[i].Uint;
  4245. type = pointspros[i].Type;
  4246. if (append === true) {
  4247. grid.addRow(i, [false, newind++, id, name, des, unit, type]);
  4248. } else {
  4249. var pid = 'p_' + ind;
  4250. grid.cells(pid, 2).setValue(id);
  4251. grid.cells(pid, 3).setValue(name);
  4252. grid.cells(pid, 4).setValue(des);
  4253. grid.cells(pid, 5).setValue(unit);
  4254. grid.cells(pid, 6).setValue(type);
  4255. grid.changeRowId(pid, id);
  4256. ind++;
  4257. }
  4258. }
  4259. } else {
  4260. info.css("color", "rgb(0,0,100)");
  4261. info.text("没有符合搜索条件的数据点");
  4262. info.attr("title", null);
  4263. }
  4264. }
  4265. })
  4266. },
  4267. _loadTableNames: function (comBox) {
  4268. if (typeof (tableNameStr) != "undefined") {
  4269. if (tableNameStr.length > 0) {
  4270. for (var i = 0; i < tableNames.length; i++) {
  4271. comBox.addOption(tableNames[i], tableNames[i]);
  4272. }
  4273. comBox.setComboText(tableNames[0]);
  4274. return;
  4275. }
  4276. }
  4277. var str = "http://" + webServiceIP + ":" + webServicePort + "/api/Table?isAllTalbleInfo=all";
  4278. $.ajax({
  4279. url: str,
  4280. type: 'GET',
  4281. dataType: 'json',
  4282. cache: false,
  4283. success: function (data) {
  4284. for (var i = 0; i < data.length; i++) {
  4285. comBox.addOption(data[i], data[i]);
  4286. }
  4287. }
  4288. })
  4289. },
  4290. _onAddPoint: function () {
  4291. var rtChart = this;
  4292. var w = 660;
  4293. var h = 480;
  4294. if (w > this.canvas.width() - 60)
  4295. w = this.canvas.width() - 60;
  4296. if (h > this.canvas.height() - 110)
  4297. h = this.canvas.height() - 110;
  4298. var content = '<label>所属表:<div name="tabfileter" style="width:180px;display:inline-block; "></div></label><br>';
  4299. content += '<label style="line-height:30px;">标签名:<input type="text" name="tagfileter" placeholder="所有(*)"></input><br>';
  4300. content += '<label style="line-height:30px;">描&nbsp;&nbsp;&nbsp;述:<input type="text" name="descfileter" placeholder="所有(*)"></input>';
  4301. content += '<input value="选定" type="button" style="float:right" disabled="disabled" name="btnSelected"></input></label><br>';
  4302. content += '<input value="查询" type="button" name="btnSearch" ></input><br>';
  4303. content += '<span style="width:100%; font-size:12px;cursor:pointer" /><br>';
  4304. content += '<div name="gridlist" style="width:' + w + 'px;height:' + h + 'px; margin-top:4px;" class="unselectable"></div>'
  4305. var rowHeight = null;
  4306. var tabRowCount = null;
  4307. var containdiv = null;
  4308. var info = null;
  4309. var grid = null;
  4310. var comBox = null;
  4311. var totalCount = {};
  4312. var tabfilter = null;
  4313. var tagfilter = null;
  4314. var descfilter = null;
  4315. var dia = dialog({
  4316. title: '添加新点',
  4317. quickClose: true,
  4318. content: content,
  4319. onshow: function () {
  4320. containdiv = $('div[name=gridlist]', this.__popup)[0];
  4321. var skin = "dhx_web";
  4322. grid = new dhtmlXGridObject(containdiv);
  4323. grid.setImagePath("htm/codebase/dhtmlxGrid/codebase/imgs/");
  4324. grid.setHeader("选择,序号,Id,点名称,描述,单位,数据类型");
  4325. grid.setColumnsVisibility("false,false,true,false,false,false,false");
  4326. grid.setInitWidths("50,50,45,230,300,60,60");
  4327. grid.setColAlign("center,right,right,left,left,left,left");
  4328. grid.setColTypes("ch,ro,ro,ro,ro,ro,ro");
  4329. grid.setColSorting("na,na,na,na,na,na,na");
  4330. grid.setSkin(skin);
  4331. grid.enableColumnMove(true);
  4332. grid.attachEvent("onScroll", function (sLeft, sTop) {
  4333. var rowCount = grid.getRowsNum();
  4334. if (rowCount == 0) {
  4335. console.log("return");
  4336. return;
  4337. }
  4338. if (tabRowCount == null) {
  4339. rowHeight = $('tr.ev_' + skin, containdiv).height();
  4340. var tabH = $('div.objbox', containdiv).height();
  4341. tabRowCount = Math.ceil(tabH / rowHeight)
  4342. }
  4343. if (rowHeight != null && tabRowCount) {
  4344. var ind = Math.floor(sTop / rowHeight);
  4345. ind += tabRowCount;
  4346. if (ind + 1 >= rowCount && rowCount < totalCount.Num) {
  4347. var count = totalCount.Num - rowCount;
  4348. if (count > 200)
  4349. count = 200;
  4350. var pid = rowCount;
  4351. for (var i = 0; i < count; i++) {
  4352. grid.addRow("p_" + pid, [false, pid + 1]);
  4353. pid++;
  4354. }
  4355. rtChart._loadPoints(dia, grid, info, rowCount, count, tabfilter, tagfilter, totalCount);
  4356. }
  4357. }
  4358. });
  4359. var button = $("input[name=btnSelected]", this.__popup);
  4360. button.click(function () {
  4361. var idsstr = grid.getCheckedRows(0);
  4362. if (idsstr != null) {
  4363. var ids = idsstr.split(',');
  4364. if (ids && ids.length && ids[0] != "") {
  4365. for (var i = 0; i < ids.length; i++) {
  4366. var rowId = parseInt(ids[i]);
  4367. var cell = grid.cells(rowId, 3);
  4368. if (cell)
  4369. var itemDef = new GoldenRtWeb.RtItemDefine(0, 0, 0);
  4370. rtChart.AddPen({
  4371. URI: cell.getValue(),
  4372. itemDef: itemDef
  4373. });
  4374. rtChart.requestHisData({
  4375. URI: cell.getValue(),
  4376. itemDef: itemDef
  4377. }, 100);
  4378. }
  4379. }
  4380. }
  4381. dia.close().remove();
  4382. dia = null;
  4383. })
  4384. grid.attachEvent("onCheck", function (rId, cInd, state) {
  4385. var idsstr = grid.getCheckedRows(0);
  4386. if (idsstr == null)
  4387. button.attr("disabled", "disabled");
  4388. else {
  4389. var ids = idsstr.split(',');
  4390. if (ids && ids.length && ids[0] != "")
  4391. button.removeAttr("disabled");
  4392. else
  4393. button.attr("disabled", "disabled");
  4394. }
  4395. });
  4396. grid.init();
  4397. info = $("span", this.__popup);
  4398. comBox = new dhtmlXCombo($("div[name=tabfileter]", this.__popup).get(0), "combo", 170);
  4399. //comBox.addOption("所有(*)", "所有(*)");
  4400. /*comBox.setComboText("U2");
  4401. tabfilter = "U2";*/
  4402. if (rtChart.options.perfectGroup) {
  4403. comBox.setComboText(rtChart.options.perfectGroup);
  4404. if (rtChart.options.perfectGroup == "所有(*)")
  4405. tabfilter = "*";
  4406. else
  4407. tabfilter = rtChart.options.perfectGroup;
  4408. } else {
  4409. //comBox.setComboText("所有(*)");
  4410. tabfilter = "*";
  4411. }
  4412. comBox.attachEvent("onChange", function () {
  4413. var val = comBox.getComboText();
  4414. rtChart.options.perfectGroup = val;
  4415. if (val == "所有(*)")
  4416. val = "*";
  4417. if (val != tabfilter) {
  4418. tabfilter = val;
  4419. // grid.clearAll();
  4420. // button.attr("disabled", "disabled");
  4421. // rtChart._loadPoints(dia, grid, info, 0, 100, tabfilter, tagfilter, totalCount);
  4422. }
  4423. });
  4424. // var kTimer = null;
  4425. // comBox.attachEvent("onKeyPressed", function () {
  4426. // if (kTimer) {
  4427. // window.clearTimeout(kTimer);
  4428. // kTimer = null;
  4429. // }
  4430. // kTimer = window.setTimeout(function () {
  4431. // if (kTimer) {
  4432. // window.clearTimeout(kTimer);
  4433. // kTimer = null;
  4434. // }
  4435. // var val = comBox.getComboText();
  4436. // if (val == "所有(*)")
  4437. // val = "*";
  4438. // if (val != tabfilter) {
  4439. // tabfilter = val;
  4440. // grid.clearAll();
  4441. // button.attr("disabled", "disabled");
  4442. // rtChart._loadPoints(dia, grid, info, 0, 100, tabfilter, tagfilter, totalCount);
  4443. // }
  4444. // }, 1000);
  4445. // });
  4446. rtChart._loadTableNames(comBox);
  4447. tabfilter = comBox.getComboText();
  4448. // if (tabfilter.length != 0) {
  4449. // rtChart._loadPoints(dia, grid, info, 0, 100, tabfilter, tagfilter, totalCount);
  4450. // };
  4451. // var fTimer = null;
  4452. // $("input[name=tagfileter]", this.__popup).keyup(function () {
  4453. // var input = $(this);
  4454. // // if (fTimer) {
  4455. // // window.clearTimeout(fTimer);
  4456. // // fTimer = null;
  4457. // // }
  4458. // // fTimer = window.setTimeout(function () {
  4459. // // if (fTimer) {
  4460. // // window.clearTimeout(fTimer);
  4461. // // fTimer = null;
  4462. // // }
  4463. // // if (input.val() != tagfilter) {
  4464. // // tagfilter = input.val();
  4465. // // grid.clearAll();
  4466. // // button.attr("disabled", "disabled");
  4467. // // rtChart._loadPoints(dia, grid, info, 0, 100, tabfilter, tagfilter, totalCount);
  4468. // // }
  4469. // // }, 1000);
  4470. // });
  4471. var sbtn = $("input[name=btnSearch]", this.__popup);
  4472. sbtn.click(function () {
  4473. //标签名
  4474. var tagval = $("input[name=tagfileter]", this.parentElement).val();
  4475. if (tagval != tagfilter) {
  4476. tagfilter = tagval;
  4477. }
  4478. //描述
  4479. var descval = $("input[name=descfileter]", this.parentElement).val();
  4480. if (descval != descfilter) {
  4481. descfilter = descval;
  4482. }
  4483. rtChart._loadPoints(dia, grid, info, 0, 100, tabfilter, tagfilter, totalCount, descfilter);
  4484. });
  4485. },
  4486. onremove: function () {
  4487. info = null;
  4488. containdiv = null;
  4489. if (grid) {
  4490. grid.destructor();
  4491. grid = null;
  4492. }
  4493. if (comBox) {
  4494. comBox.unload();
  4495. delete comBox;
  4496. }
  4497. rtChart = null;
  4498. }
  4499. });
  4500. dia.show($('.dhx_toolbar_btn', this.element)[0]);
  4501. },
  4502. _onSaveGroup: function () {
  4503. var rtChart = this;
  4504. var w = 330;
  4505. var h = 130;
  4506. if (w > this.canvas.width() - 60)
  4507. w = this.canvas.width() - 60;
  4508. if (h > this.canvas.height() - 110)
  4509. h = this.canvas.height() - 110;
  4510. var content = '<label style="line-height:30px;">请输入组名称:<input type="text" name="groupName" ></input><br>';
  4511. content += '<input value="确定" type="button" name="btnSaveGroup" style="float:right"></input>';
  4512. var dia = dialog({
  4513. x: 200,
  4514. y: 200,
  4515. title: '设置组名',
  4516. quickClose: true,
  4517. content: content,
  4518. onshow: function () {
  4519. var sbtn = $("input[name=btnSaveGroup]", this.__popup);
  4520. sbtn.click(function () {
  4521. var gName = $("input[name=groupName]", this.parentElement).val();
  4522. if (gName == "") {
  4523. alert("请输入组名称");
  4524. } else {
  4525. }
  4526. });
  4527. },
  4528. onremove: function () {
  4529. info = null;
  4530. containdiv = null;
  4531. if (grid) {
  4532. grid.destructor();
  4533. grid = null;
  4534. }
  4535. if (comBox) {
  4536. comBox.unload();
  4537. delete comBox;
  4538. }
  4539. rtChart = null;
  4540. }
  4541. });
  4542. dia.show($('.dhx_toolbar_btn', this.element)[0]);
  4543. },
  4544. _onEditorPointGroup: function () {
  4545. if (!this.pointGroups) {
  4546. var d = dialog({
  4547. content: "当前没有可用的点组,可以尝试保存点组,<br>从而创建新的点组。",
  4548. quickClose: true
  4549. });
  4550. return;
  4551. }
  4552. var rtChart = this;
  4553. 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>'
  4554. var grid = null;
  4555. var dia = dialog({
  4556. title: '编辑点组',
  4557. quickClose: true,
  4558. content: content,
  4559. onshow: function () {
  4560. var containdiv = $('div[name=gridlist]', this.__popup)[0];
  4561. var info = $('span[name=info]', this.__popup);
  4562. grid = new dhtmlXGridObject(containdiv);
  4563. grid.setImagePath("htm/codebase/dhtmlxGrid/codebase/imgs/");
  4564. grid.setHeader("删除,名称,缺省");
  4565. grid.setInitWidths("50,130,60");
  4566. grid.setColAlign("center,left,center");
  4567. grid.setColTypes("ch,ed,ch");
  4568. grid.setColSorting("na,na,na");
  4569. grid.setSkin("dhx_web");
  4570. grid.enableDragAndDrop(true);
  4571. var commitButton = $("input[name=save]", this.__popup);
  4572. commitButton.click(function () {
  4573. var groups = [];
  4574. var i = 0;
  4575. var ids = grid.getAllRowIds();
  4576. if (ids) {
  4577. ids = ids.split(",");
  4578. if (ids && ids.length && ids[0] != "") {
  4579. for (var i = 0; i < ids.length; i++) {
  4580. var rid = ids[i];
  4581. var set = {
  4582. Id: rid,
  4583. name: grid.cells(rid, 1).getValue(),
  4584. default_: grid.cells(rid, 2).isChecked(),
  4585. seq: i
  4586. };
  4587. groups.push(set);
  4588. }
  4589. }
  4590. }
  4591. rtChart._submitPointGroup(dia, groups, info);
  4592. });
  4593. var delteButton = $("input[name=delete]", this.__popup);
  4594. delteButton.click(function () {
  4595. var idsstr = grid.getCheckedRows(0);
  4596. var ids = idsstr.split(',');
  4597. if (ids && ids.length && ids[0] != "") {
  4598. for (var i = 0; i < ids.length; i++)
  4599. grid.deleteRow(ids[i]);
  4600. }
  4601. });
  4602. grid.attachEvent("onCheck", function (rId, cInd, state) {
  4603. if (cInd == 0) {
  4604. var idsstr = grid.getCheckedRows(0);
  4605. if (idsstr == null)
  4606. delteButton.attr("disabled", "disabled");
  4607. else {
  4608. var ids = idsstr.split(',');
  4609. if (ids && ids.length && ids[0] != "")
  4610. delteButton.removeAttr("disabled");
  4611. else
  4612. delteButton.attr("disabled", "disabled");
  4613. }
  4614. } else if (cInd == 2 && state) {
  4615. var ids = grid.getCheckedRows(2);
  4616. ids = ids.split(',');
  4617. for (var i = 0; i < ids.length; i++) {
  4618. if (ids[i] != rId)
  4619. grid.cells(ids[i], 2).setValue(false);
  4620. }
  4621. }
  4622. });
  4623. grid.init();
  4624. for (var i in rtChart.pointGroups) {
  4625. var pg = rtChart.pointGroups[i];
  4626. grid.addRow(pg.Id, [false, pg.name, pg.bDefault]);
  4627. }
  4628. },
  4629. onremove: function () {
  4630. if (grid) {
  4631. grid.destructor();
  4632. grid = null;
  4633. }
  4634. rtChart = null;
  4635. }
  4636. });
  4637. dia.show($('.dhx_toolbar_btn', this.element)[4]);
  4638. },
  4639. _onSetColors: function (clrName) {
  4640. if (!clrName) {
  4641. var rtChart = this;
  4642. var d = dialog({
  4643. title: '设置颜色',
  4644. quickClose: true,
  4645. 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>',
  4646. onshow: function () {
  4647. $('input[type=radio]', this.__popup).change(function () {
  4648. rtChart._onSetColors($(this).val());
  4649. rtChart = null;
  4650. d.close().remove();
  4651. d = null;
  4652. });
  4653. }
  4654. });
  4655. d.show($('.dhx_toolbar_btn', this.element)[2]);
  4656. return;
  4657. } else {
  4658. var clrLabel;
  4659. var clr;
  4660. switch (clrName) {
  4661. case 'bkColor':
  4662. clrLabel = '背景色';
  4663. clr = this.canvas.css('background-color');
  4664. break;
  4665. case 'gridColor':
  4666. clrLabel = '格线色';
  4667. clr = this.options.gridColor;
  4668. break;
  4669. case 'indColor':
  4670. clrLabel = '指示线颜色';
  4671. clr = this.options.indicatorColor;
  4672. break;
  4673. case 'bordrColor':
  4674. clrLabel = '边框色';
  4675. clr = this.options.borderColor;
  4676. break;
  4677. case 'timeLabelColor':
  4678. clrLabel = '时间标签颜色';
  4679. clr = this.options.timeLabelColor;
  4680. break;
  4681. default:
  4682. return;
  4683. }
  4684. if (this.btipShow) {
  4685. if (this.artTooltip)
  4686. this.artTooltip.close().remove();
  4687. }
  4688. if (!this.colorPicker)
  4689. this._buildColorPicker();
  4690. var colorpicker = this.colorPicker;
  4691. if (colorpicker.prevColor != null) {
  4692. $('.colorpicker-prev', colorpicker).show();
  4693. $('.colorpicker-prevbk', colorpicker).css('background-color', colorpicker.prevColor);
  4694. $('.colorpicker-prev', colorpicker).bind("click", function () {
  4695. if (colorpicker) {
  4696. $('.colorpicker-ind', colorpicker).colorpicker('setValue', colorpicker.prevColor);
  4697. }
  4698. });
  4699. } else
  4700. $('.colorpicker-prev', colorpicker).hide();
  4701. colorpicker.resumeColor = clr;
  4702. var rtchart = this;
  4703. $('.colorpicker-resume', colorpicker).bind("click", function () {
  4704. if (colorpicker) {
  4705. $('.colorpicker-ind', colorpicker).colorpicker('setValue', colorpicker.resumeColor);
  4706. }
  4707. });
  4708. $('.colorpicker-label', colorpicker).text("设置 " + clrLabel);
  4709. colorpicker.show()
  4710. .position({
  4711. my: "left+10 top+20",
  4712. of: $('.dhx_toolbar_btn', this.element)[0],
  4713. collision: "fit"
  4714. });
  4715. $('.colorpicker-resumebk', colorpicker).css('background-color', clr);
  4716. $('.colorpicker-ind', colorpicker)
  4717. .colorpicker('setValue', clr)
  4718. .colorpicker('show')
  4719. .off()
  4720. .on('changeColor.colorpicker', function (event) {
  4721. rtchart.setColors(clrName, event.color.toString());
  4722. })
  4723. .on('hidePicker.colorpicker', function (event) {
  4724. if (colorpicker) {
  4725. colorpicker.prevColor = $(this).data('colorpicker').color.toString();
  4726. colorpicker.hide();
  4727. $('.colorpicker-ind', colorpicker).off();
  4728. $('.colorpicker-resume', colorpicker).unbind();
  4729. $('.colorpicker-prev', colorpicker).unbind();
  4730. colorpicker = null;
  4731. }
  4732. if (rtchart)
  4733. rtchart = null;
  4734. });
  4735. }
  4736. },
  4737. setPointGroupName: function (gName, bDefault) {
  4738. if (gName != null)
  4739. window.document.title = gName;
  4740. this.bDeafultGroup = bDefault;
  4741. this.options.pointGroupName = gName;
  4742. },
  4743. loadConfig: function (groupName, config) {
  4744. if (config == null)
  4745. return;
  4746. this.setPointGroupName(groupName, (config.bDefault != null ? config.bDefault : false));
  4747. var pensConfig = null;
  4748. var bRtRefresh = false;
  4749. var bShowAxis = false;
  4750. if (config.spanSec != null)
  4751. this.setTimeSpan(parseInt(config.spanSec), true);
  4752. if (config.bkColor != null)
  4753. this.options.bkColor = config.bkColor;
  4754. if (config.showAxis != null)
  4755. bShowAxis = config.showAxis;
  4756. if (config.rtRefresh != null)
  4757. bRtRefresh = config.rtRefresh;
  4758. if (config.listExpand != null)
  4759. this.options.listExpand = config.listExpand;
  4760. if (config.perfectGroup != null)
  4761. this.options.listExpand = config.perfectGroup;
  4762. if (config.indicatorColor != null)
  4763. this.options.indicatorColor = config.indicatorColor;
  4764. if (config.timeLabelColor != null)
  4765. this.options.timeLabelColor = config.timeLabelColor;
  4766. if (config.panShow != null)
  4767. this.options.panShow = config.panShow;
  4768. if (config.listHeight != null)
  4769. this.options.listHeight = parseInt(config.listHeight);
  4770. if (config.showGrid != null)
  4771. this.options.showGrid = config.showGrid;
  4772. if (config.borderColor != null)
  4773. this.options.borderColor = config.borderColor;
  4774. if (config.timeLabelColor != null)
  4775. this.options.timeLabelColor = config.timeLabelColor;
  4776. if (config.gridColor != null)
  4777. this.options.gridColor = config.gridColor;
  4778. if (config.tooltipDelay != null)
  4779. this.options.tooltipDelay = config.tooltipDelay;
  4780. if (config.panWidth != null)
  4781. this.options.panWidth = config.panWidth;
  4782. if (config.showThumbs != null)
  4783. this.options.showThumbs = config.showThumbs;
  4784. if (config.showList != null)
  4785. this.options.showList = config.showList;
  4786. if (config.trendPens != null) {
  4787. if (pensConfig == null)
  4788. pensConfig = [];
  4789. for (var i = 0; i < config.trendPens.length; i++) {
  4790. var penOption = {};
  4791. pensConfig.push(penOption);
  4792. var pen = config.trendPens[i];
  4793. if (pen.URI != null)
  4794. penOption.URI = pen.URI;
  4795. if (pen.linkReTryTime != null)
  4796. penOption.linkReTryTime = pen.linkReTryTime;
  4797. if (pen.penColor != null)
  4798. penOption.penColor = pen.penColor;
  4799. if (pen.Num != null)
  4800. penOption.Num = pen.Num;
  4801. if (pen.drawLine != null)
  4802. penOption.drawLine = pen.drawLine;
  4803. if (pen.stepLine != null)
  4804. penOption.stepLine = pen.stepLine;
  4805. if (pen.drawTag != null)
  4806. penOption.drawTag = pen.drawTag;
  4807. if (pen.interpolate != null)
  4808. penOption.interpolate = pen.interpolate;
  4809. if (pen.hisReTryTime != null)
  4810. penOption.hisReTryTime = pen.hisReTryTime;
  4811. if (pen.lockRange != null)
  4812. penOption.lockRange = pen.lockRange;
  4813. if (pen.penWidth != null)
  4814. penOption.penWidth = pen.penWidth;
  4815. if (pen.rageMax != null)
  4816. penOption.rageMax = pen.rageMax;
  4817. if (pen.rageMin != null)
  4818. penOption.rageMin = pen.rageMin;
  4819. }
  4820. }
  4821. if (this.trendPens) {
  4822. var pens = [];
  4823. for (var i = 0; i < this.trendPens.length; i++)
  4824. pens.push(this.trendPens[i]);
  4825. for (var i = 0; i < pens.length; i++)
  4826. this.removePen(pens[i]);
  4827. }
  4828. if (this.listGrid)
  4829. this.listGrid.clearAll();
  4830. this.trendPens = [];
  4831. if (pensConfig) {
  4832. for (var i = 0; i < pensConfig.length; i++)
  4833. this.trendPens.push(new TrendPen(this, pensConfig[i]));
  4834. }
  4835. for (var i = 0; i < this.trendPens.length; i++) {
  4836. var pen = this.trendPens[i];
  4837. if (pen.options.commAxis) {
  4838. for (var j = 0; j < pen.options.commAxis.length; j++) {
  4839. var uri = pen.options.commAxis[j];
  4840. for (var k = 0; k < this.trendPens.length; k++) {
  4841. var commpen = this.trendPens[k];
  4842. if (commpen.getURI() == uri) {
  4843. if (pen.commAxis == null)
  4844. pen.commAxis = [];
  4845. pen.commAxis.push(commpen);
  4846. }
  4847. }
  4848. }
  4849. }
  4850. this._linkData(pen);
  4851. }
  4852. this._resetTumbs();
  4853. this._bulidCanvas();
  4854. this.setRtrefresh(bRtRefresh);
  4855. this.setShowAxis(bShowAxis);
  4856. if (this.toolBar)
  4857. this.toolBar.setItemText("timeSpan", this.getTimeSpanString());
  4858. },
  4859. _onSaveConfig: function () {
  4860. var rtChart = this;
  4861. var d = dialog({
  4862. title: '保存设置',
  4863. quickClose: true,
  4864. 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>',
  4865. onshow: function () {
  4866. $('input[name=groupName]', this.__popup).val(rtChart.options.pointGroupName == null ? "" : rtChart.options.pointGroupName);
  4867. $('form', this.__popup).keydown(this, function (e) {
  4868. switch (e.which) {
  4869. case 13:
  4870. d.ok();
  4871. break;
  4872. case 27:
  4873. d.close().remove();
  4874. d = null;
  4875. rtChart = null;
  4876. break;
  4877. }
  4878. });
  4879. },
  4880. okValue: '确定',
  4881. ok: function () {
  4882. // var tags=this.options.tags;
  4883. // console.log(rtChart);
  4884. var gName = $('input[name=groupName]', this.__popup).val();
  4885. var bDefault = $('input[type=checkbox]', this.__popup)[0].checked;
  4886. if (gName == null || gName.length == 0) {
  4887. var pd = dialog({
  4888. quickClose: true,
  4889. content: "点组名称不能为空"
  4890. });
  4891. pd.show();
  4892. window.setTimeout(function () {
  4893. pd.close().remove();
  4894. }, 2000);
  4895. $('input[name=groupName]', this.__popup).focus();
  4896. return false;
  4897. }
  4898. rtChart.setPointGroupName(gName, bDefault);
  4899. rtChart.saveConfig(bDefault);
  4900. d.close().remove();
  4901. d = null;
  4902. rtChart = null;
  4903. }
  4904. });
  4905. d.show($('.dhx_toolbar_btn', this.element)[3]);
  4906. },
  4907. saveConfig: function (bDefault) {
  4908. if (this.options.pointGroupName == null || this.options.pointGroupName.length == 0) {
  4909. var pd = dialog({
  4910. quickClose: true,
  4911. content: "点组名称不能为空"
  4912. });
  4913. pd.show();
  4914. window.setTimeout(function () {
  4915. pd.close().remove();
  4916. }, 2000);
  4917. return;
  4918. }
  4919. var config = {};
  4920. config.name = this.options.pointGroupName;
  4921. config.spanSec = this.options.spanSec;
  4922. config.bkColor = this.options.bkColor;
  4923. config.showAxis = this.options.showAxis;
  4924. config.rtRefresh = this.options.rtRefresh;
  4925. config.listExpand = this.options.listExpand;
  4926. if (this.options.perfectGroup) {
  4927. config.perfectGroup = this.options.perfectGroup;
  4928. }
  4929. config.indicatorColor = this.options.indicatorColor;
  4930. config.timeLabelColor = this.options.timeLabelColor;
  4931. config.spanSec = this.options.spanSec;
  4932. config.panShow = this.options.panShow;
  4933. config.listHeight = this.options.listHeight;
  4934. config.showGrid = this.options.showGrid;
  4935. config.borderColor = this.options.borderColor;
  4936. config.timeLabelColor = this.options.timeLabelColor;
  4937. config.gridColor = this.options.gridColor;
  4938. config.tooltipDelay = this.options.tooltipDelay;
  4939. config.panWidth = this.options.panWidth;
  4940. config.showThumbs = this.options.showThumbs;
  4941. config.showList = this.options.showList;
  4942. config.freeRange = this.options.freeRange;
  4943. config.bDefault = (bDefault ? true : false);
  4944. if (this.trendPens) {
  4945. var len = this.trendPens.length;
  4946. config.trendPens = [];
  4947. for (var i = 0; i < len; i++) {
  4948. var pen = this.trendPens[i];
  4949. config.trendPens.push(pen.getConfig());
  4950. }
  4951. } else {
  4952. alert("请添加测点");
  4953. return;
  4954. }
  4955. var configs = localStorage.getItem("goldenTrendConfig");
  4956. if (configs) {
  4957. try {
  4958. configs = JSON.parse(configs);
  4959. } catch (ex) {
  4960. localStorage.removeItem("goldenTrendConfig");
  4961. configs = null;
  4962. }
  4963. }
  4964. if (configs) {
  4965. if (config.bDefault) {
  4966. for (var i in configs) {
  4967. var setconfig = configs[i];
  4968. setconfig.bDeafult = false;
  4969. }
  4970. }
  4971. } else {
  4972. configs = {};
  4973. }
  4974. configs[this.options.pointGroupName] = config;
  4975. var id = 0;
  4976. for (var i in configs) {
  4977. var setconfig = configs[i];
  4978. setconfig.Id = id++;
  4979. }
  4980. localStorage.setItem("goldenTrendConfig", JSON.stringify(configs));
  4981. var d = dialog({
  4982. content: "点组设置保存已成功!",
  4983. quickClose: true
  4984. });
  4985. d.show();
  4986. window.setTimeout(function () {
  4987. d.close().remove();
  4988. d = null;
  4989. }, 2000);
  4990. this._loadPointGroupNames();
  4991. },
  4992. _loadPointGroupNames: function () {
  4993. var dia = null;
  4994. if (this.initDialogShow !== true) {
  4995. this.initDialogShow = true;
  4996. }
  4997. if (typeof localStorage == "undefined") {
  4998. return;
  4999. }
  5000. var pointGroups = localStorage.getItem("goldenTrendConfig");
  5001. if (pointGroups) {
  5002. try {
  5003. pointGroups = JSON.parse(pointGroups);
  5004. } catch (ex) {
  5005. localStorage.removeItem("goldenTrendConfig");
  5006. pointGroups = null;
  5007. }
  5008. }
  5009. this._onPointGroupNamesLoaded(pointGroups);
  5010. },
  5011. _onPointGroupNamesLoaded: function (pointGroups) {
  5012. if (!this.toolBar || !pointGroups)
  5013. return;
  5014. this.pointGroups = pointGroups;
  5015. var opts =
  5016. [
  5017. ['newPiointGroup', 'obj', '新建点组', 'window_new.png'],
  5018. ['editorPointGroup', 'obj', '编辑点组...', 'tag_blue_edit.png'],
  5019. ['refreshPointGroup', 'obj', '刷新点组列表', 'reload.png'],
  5020. ['idsep', 'sep']
  5021. ];
  5022. this.toolBar.removeItem("pointGroup");
  5023. for (var n in this.pointGroups) {
  5024. var pg = this.pointGroups[n];
  5025. if (!this.isNewPage && pg.bDefault === true && this.options.pointGroupName == null) {
  5026. this.options.pointGroupName = n;
  5027. this._loadPointGroup();
  5028. }
  5029. var opt = [pg.Id, 'obj', n, 'tags.png'];
  5030. opts.push(opt);
  5031. }
  5032. this.toolBar.addButtonSelect("pointGroup", 4, "点组", opts, "tag.png");
  5033. },
  5034. _onSetTimeSpan: function (e) {
  5035. var rtChart = this;
  5036. var d = dialog({
  5037. title: '设置时间跨度',
  5038. quickClose: true,
  5039. 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>',
  5040. onshow: function () {
  5041. $('form', this.__popup).keydown(this, function (e) {
  5042. switch (e.which) {
  5043. case 13:
  5044. d.ok();
  5045. break;
  5046. case 27:
  5047. d.close().remove();
  5048. d = null;
  5049. rtChart = null;
  5050. break;
  5051. }
  5052. });
  5053. },
  5054. okValue: '确定',
  5055. ok: function () {
  5056. var span = $('input[ name="timespan"]', d.__popup).val();
  5057. span = parseInt(span, 10);
  5058. if (!span || isNaN(span) || span < 1)
  5059. span = 1;
  5060. switch ($('input:radio:checked', this.__popup).val()) {
  5061. case 'm':
  5062. span *= 60;
  5063. break;
  5064. case 'h':
  5065. span *= 3600;
  5066. break;
  5067. }
  5068. d.close().remove();
  5069. d = null;
  5070. if (!rtChart.getHisRefreshing()) {
  5071. d = dialog({
  5072. title: '固定哪个时间?',
  5073. quickClose: true,
  5074. 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>',
  5075. onshow: function () {
  5076. $('input[type=radio]', this.__popup).change(function () {
  5077. var fixEnd = false;
  5078. if ($(this).val() == 'fixEnd')
  5079. fixEnd = true;
  5080. d.close().remove();
  5081. d = null;
  5082. rtChart.setTimeSpan(span, fixEnd);
  5083. rtChart = null;
  5084. });
  5085. }
  5086. });
  5087. d.show(e);
  5088. } else {
  5089. rtChart.setTimeSpan(span);
  5090. rtChart = null;
  5091. }
  5092. }
  5093. });
  5094. e.pageX += 10;
  5095. e.pageY -= 30;
  5096. d.show(e);
  5097. },
  5098. _toggleZoom: function () {
  5099. this.zooming = this.zooming ? false : true;
  5100. if (this.zooming)
  5101. this.canvas.addClass('zoomcur');
  5102. else
  5103. this.canvas.removeClass('zoomcur');
  5104. },
  5105. _updateReZoom: function () {
  5106. if (this.zoomStack && this.zoomStack.length)
  5107. this.toolBar.enableItem("zoomResume");
  5108. else
  5109. this.toolBar.disableItem("zoomResume");
  5110. },
  5111. _onReZoom: function () {
  5112. if (this.zoomStack && this.zoomStack.length) {
  5113. var zoomItem = this.zoomStack.pop();
  5114. this._updateReZoom();
  5115. if (zoomItem.pens) {
  5116. for (var i in zoomItem.pens) {
  5117. var zoomPen = zoomItem.pens[i];
  5118. }
  5119. }
  5120. this.setBegTimeAndSpan(zoomItem.begTime, zoomItem.spanTime);
  5121. }
  5122. },
  5123. RegistRtPt: function (pen, rtDef, callback, opt) {
  5124. var url = pen.getWebURL().toLowerCase();
  5125. var webLink = this.webLinks[url];
  5126. if (webLink) {
  5127. return webLink.RegistRtPt(rtDef, pen, callback, opt);
  5128. } else
  5129. return null;
  5130. },
  5131. UnRegistRtPt: function (pen, rtRefreshKey) {
  5132. if (!this.webLinks)
  5133. return;
  5134. var url = pen.getWebURL().toLowerCase();
  5135. var webLink = this.webLinks[url];
  5136. if (webLink)
  5137. webLink.UnRegistRtPt(pen, rtRefreshKey);
  5138. },
  5139. requestHisData: function (pen, delay) {
  5140. var url = GoldenRtWeb.getWebURL();
  5141. var webLink = this.webLinks[url];
  5142. if (webLink)
  5143. return webLink.requestHisData(delay);
  5144. else
  5145. return false;
  5146. },
  5147. DateToFileTime: function (date) {
  5148. var epoch_diff = 116444736000000000;
  5149. var rate_diff = 10000;
  5150. var ut = date.getTime();
  5151. var ft = ut * rate_diff + epoch_diff;
  5152. return ft;
  5153. },
  5154. FileTimeToDate: function (fTime) {
  5155. var epoch_diff = 116444736000000000;
  5156. var rate_diff = 10000;
  5157. var ut = (fTime - epoch_diff) / rate_diff;
  5158. return new Date(ut);
  5159. },
  5160. FileTimeToDateString: function (fTime) {
  5161. if (isNaN(fTime) || fTime == 0)
  5162. return "";
  5163. var date = this.FileTimeToDate(fTime);
  5164. var dstr = date.getFullYear().toString();
  5165. dstr += "-";
  5166. if (date.getMonth() + 1 < 10)
  5167. dstr += "0" + (date.getMonth() + 1).toString();
  5168. else
  5169. dstr += (date.getMonth() + 1).toString();
  5170. dstr += "-";
  5171. if (date.getDate() < 10)
  5172. dstr += "0" + date.getDate();
  5173. else
  5174. dstr += date.getDate();
  5175. return dstr;
  5176. },
  5177. FileTimeToTimeString: function (fTime, ms) {
  5178. if (isNaN(fTime) || fTime == 0)
  5179. return "";
  5180. var date = this.FileTimeToDate(fTime);
  5181. var time;
  5182. if (date.getHours() < 10)
  5183. time = "0" + date.getHours();
  5184. else
  5185. time = date.getHours().toString();
  5186. time += ":";
  5187. if (date.getMinutes() < 10)
  5188. time += "0" + date.getMinutes().toString();
  5189. else
  5190. time += date.getMinutes();
  5191. time += ":";
  5192. if (date.getSeconds() < 10)
  5193. time += "0" + date.getSeconds().toString();
  5194. else
  5195. time += date.getSeconds();
  5196. if (ms === true) {
  5197. time += ".";
  5198. if (date.getMilliseconds() < 10)
  5199. time += "00" + date.getMilliseconds().toString();
  5200. else if (date.milliseconds < 100)
  5201. time += "0" + date.getMilliseconds().toString();
  5202. else
  5203. time += date.getMilliseconds().toString();
  5204. }
  5205. return time;
  5206. }
  5207. });
  5208. WebLink.prototype = {
  5209. addPen: function (pen) {
  5210. if (!this.Pens)
  5211. this.Pens = [];
  5212. this.Pens.push(pen);
  5213. this.startLink();
  5214. },
  5215. destroy: function () {
  5216. if (this.hisTimer) {
  5217. window.clearTimeout(this.hisTimer);
  5218. this.hisTimer = null;
  5219. }
  5220. if (this.linkTimer) {
  5221. window.clearTimeout(this.linkTimer);
  5222. this.linkTimer = null;
  5223. }
  5224. if (this.rtRefresher) {
  5225. this.rtRefresher.clear();
  5226. delete this.rtRefresher;
  5227. }
  5228. if (this.Pens)
  5229. delete this.Pens;
  5230. },
  5231. startLink: function (delay) {
  5232. if (this.linkTimer) {
  5233. window.clearTimeout(this.linkTimer);
  5234. this.linkTimer = null;
  5235. }
  5236. var self = this;
  5237. this.linkTimer = window.setTimeout(function () {
  5238. window.clearTimeout(self.linkTimer);
  5239. self.linkTimer = null;
  5240. self._beginLink();
  5241. self = null;
  5242. }, delay || 10);
  5243. },
  5244. _beginLink: function () {
  5245. if (!this.Pens || !this.Pens.length)
  5246. return;
  5247. var self = this;
  5248. for (var i in this.Pens) {
  5249. var pen = this.Pens[i];
  5250. if (pen.isLinkRq()) {
  5251. self._addpenClosure(pen);
  5252. }
  5253. pen.setLinkStatus("linking", "正在连接...");
  5254. }
  5255. },
  5256. _addpenClosure: function (pen) {
  5257. var str = "http://" + webServiceIP + ":" + webServicePort + "/api/Point?tagName=" + encodeURIComponent(pen.getURI());
  5258. $.ajax({
  5259. url: str,
  5260. type: 'GET',
  5261. dataType: 'json',
  5262. cache: false,
  5263. success: function (data) {
  5264. if (data)
  5265. pen.onLinkTab(data);
  5266. }
  5267. });
  5268. },
  5269. RegistRtPt: function (rtDef, scope, callback, opt) {
  5270. if (!this.rtRefresher)
  5271. this.rtRefresher = new GoldenRtWeb.RtRefresher(this.weburl);
  5272. return this.rtRefresher.RegistRtPt(rtDef, scope, callback, opt);
  5273. },
  5274. UnRegistRtPt: function (pen, rtRefreshKey) {
  5275. if (this.rtRefresher)
  5276. this.rtRefresher.UnRegistRtPt(rtRefreshKey);
  5277. if (this.Pens) {
  5278. for (i in this.Pens) {
  5279. if (this.Pens[i] == pen) {
  5280. this.Pens.splice(i, 1);
  5281. break;
  5282. }
  5283. }
  5284. }
  5285. },
  5286. requestHisData: function (delay) {
  5287. if (this.hisTimer) {
  5288. window.clearTimeout(this.hisTimer);
  5289. this.hisTimer = null;
  5290. }
  5291. var self = this;
  5292. this.hisTimer = window.setTimeout(function () {
  5293. window.clearTimeout(self.hisTimer);
  5294. self.hisTimer = null;
  5295. self._pullHisData();
  5296. self = null;
  5297. }, delay || 10);
  5298. return true;
  5299. },
  5300. _pullHisData: function () {
  5301. if (!this.Pens || !this.Pens.length)
  5302. return;
  5303. var reqInfoset = null;
  5304. var tagName = [];
  5305. var metaId = "";
  5306. var beginTime = "";
  5307. var endTime = "";
  5308. var tabs = [];
  5309. for (i in this.Pens) {
  5310. var pen = this.Pens[i];
  5311. if (pen.isHisRq()) {
  5312. var tab = pen.getHisRequestTab();
  5313. tab.reqHisPen = pen;
  5314. tab.clientHandle = i;
  5315. pen.setHisStatus("getting", "正在获取历史数据...");
  5316. tabs.push(tab);
  5317. tab.reqHisPen = pen;
  5318. tab.clientHandle = i;
  5319. if (beginTime == "") {
  5320. if (pen.options.itemDef.beginTime != null) {
  5321. beginTime = pen.options.itemDef.beginTime;
  5322. } else {
  5323. beginTime = 0;
  5324. }
  5325. }
  5326. if (endTime == "") {
  5327. if (pen.options.itemDef.endTime != null) {
  5328. endTime = pen.options.itemDef.endTime;
  5329. } else {
  5330. endTime = 0;
  5331. }
  5332. }
  5333. var item = encodeURIComponent(pen.options.URI);;
  5334. item += "&beginTime=" + beginTime + "&endTime=" + endTime + "&interval=1000";
  5335. tagName.push(item);
  5336. }
  5337. }
  5338. if (tagName.length > 0) {
  5339. for (var i = 0; i < tagName.length; i++) {
  5340. {
  5341. var str = "http://" + webServiceIP + ":" + webServicePort + "/api/HistoryPlot?tagNames=" + tagName[i];
  5342. var self = this;
  5343. var tab = tabs[i];
  5344. $.ajax({
  5345. url: str,
  5346. type: 'GET',
  5347. dataType: 'json',
  5348. cache: false,
  5349. complete: function (xhr, ts) {
  5350. if (xhr.tab) {
  5351. var data = xhr.responseJSON;
  5352. if (typeof (data) == "undefined") return;
  5353. if (data.length > 0)
  5354. self._onHisEnd(xhr.tab, data);
  5355. delete xhr.tab;
  5356. }
  5357. }
  5358. }).tab = tab;
  5359. }
  5360. }
  5361. } else
  5362. this._onHisEnd();
  5363. },
  5364. _onHisEnd: function (tab, data) {
  5365. if (tab && data && data.length > 0) {
  5366. if (tab.reqHisPen) {
  5367. tab.hisData = data[0];
  5368. tab.reqHisPen.onHisTab(tab);
  5369. tab.reqHisPen = null;
  5370. }
  5371. }
  5372. if (!this.Pens || !this.Pens.length)
  5373. return;
  5374. this.requestHisData(3000);
  5375. }
  5376. };
  5377. TrendPen.prototype = {
  5378. destroy: function () {
  5379. if (this.linkingTime) {
  5380. window.clearTimeout(this.linkingTime);
  5381. this.linkingTime = null;
  5382. }
  5383. if (this.hisingTime) {
  5384. window.clearTimeout(this.hisingTime);
  5385. this.hisingTime = null;
  5386. }
  5387. if (this.rtRefreshKey) {
  5388. this.rtChart.UnRegistRtPt(this, this.rtRefreshKey);
  5389. this.rtRefreshKey = null;
  5390. }
  5391. var oldComm = this.commAxis;
  5392. this.commAxis = null;
  5393. if (oldComm) {
  5394. for (var i = 0; i < oldComm.length; i++)
  5395. oldComm[i].removeCommAxis(this);
  5396. }
  5397. this.rtChart = null;
  5398. },
  5399. hisDatRemove: function (array, from, to) {
  5400. var rest = array.slice((to || from) + 1 || array.length);
  5401. array.length = from < 0 ? array.length + from : from;
  5402. return array.push.apply(array, rest);
  5403. },
  5404. updateRangeList: function () {
  5405. if (this.rageMax != null && this.rageMin != null) {
  5406. this.setGridSelf = true;
  5407. this.rtChart._updateList(this.rowId, "量程下限", this.rageMin.toFixed(this.options.Num));
  5408. this.rtChart._updateList(this.rowId, "量程上限", this.rageMax.toFixed(this.options.Num));
  5409. this.setGridSelf = false;
  5410. } else {
  5411. this.setGridSelf = true;
  5412. this.rtChart._updateList(this.rowId, "量程下限", null);
  5413. this.rtChart._updateList(this.rowId, "量程上限", null);
  5414. this.setGridSelf = false;
  5415. }
  5416. },
  5417. setDataReader: function () {
  5418. if (this.rtChart == null)
  5419. return;
  5420. var ft = this.rtChart.getReaderTimer();
  5421. var vqt = null;
  5422. var prev = null;
  5423. var next = null;
  5424. if (this.hisData) {
  5425. var len = this.hisData.length;
  5426. for (var i = 0; i < len; i++) {
  5427. var findVQT = this.hisData[i];
  5428. if (findVQT.StampTime == ft) {
  5429. vqt = findVQT;
  5430. break;
  5431. } else if (findVQT.StampTime > ft) {
  5432. if (prev) {
  5433. vqt = prev;
  5434. next = findVQT;
  5435. } else
  5436. vqt = findVQT;
  5437. break;
  5438. } else
  5439. prev = findVQT;
  5440. }
  5441. }
  5442. if (vqt) {
  5443. if (vqt.Value != null) {
  5444. if (next && next.StampTime > vqt.StampTime && next.Value != null) {
  5445. var val;
  5446. if (this.isString(vqt))
  5447. val = vqt.Value ? vqt.Value : "";
  5448. else if (this.isBoolen(vqt)) {
  5449. if (vqt.Value)
  5450. val = "1";
  5451. else
  5452. val = "0";
  5453. } else {
  5454. val = vqt.Value + (next.Value - vqt.Value) * (ft - vqt.StampTime) / (next.StampTime - vqt.StampTime);
  5455. val = val.toFixed(this.options.Num);
  5456. }
  5457. if (this.unit)
  5458. val += " " + this.unit;
  5459. var time = this.rtChart.FileTimeToDateString(ft) + " " + this.rtChart.FileTimeToTimeString(ft);
  5460. this.rtChart._updateList(this.rowId, "数据时间", time);
  5461. this.rtChart._updateList(this.rowId, "数据值", val);
  5462. } else {
  5463. var time = this.getFullStampTimeStr(vqt);
  5464. var val;
  5465. if (this.isString(vqt))
  5466. val = vqt.Value ? vqt.Vvalue : "";
  5467. else if (this.isBoolen(vqt)) {
  5468. if (vqt.Value)
  5469. val = "1";
  5470. else
  5471. val = "0";
  5472. } else
  5473. val = (this.isFloat(vqt) ? vqt.Value.toFixed(this.options.Num) : vqt.Value);
  5474. if (this.unit)
  5475. val += " " + this.unit;
  5476. this.rtChart._updateList(this.rowId, "数据时间", time);
  5477. this.rtChart._updateList(this.rowId, "数据值", val);
  5478. }
  5479. }
  5480. } else {
  5481. var time = this.rtChart.FileTimeToDateString(ft) + " " + this.rtChart.FileTimeToTimeString(ft);
  5482. var val = '[!!无历史数据]';
  5483. this.rtChart._updateList(this.rowId, "数据时间", time);
  5484. this.rtChart._updateList(this.rowId, "数据值", val);
  5485. }
  5486. },
  5487. updateDataReader: function () {
  5488. if (this.rtChart == null)
  5489. return;
  5490. if (this.dataReaderTime == null) {
  5491. var me = this;
  5492. this.dataReaderTime = window.setTimeout(function () {
  5493. window.clearTimeout(me.dataReaderTime);
  5494. me.dataReaderTime = null;
  5495. me.setDataReader();
  5496. me = null;
  5497. }, 100);
  5498. }
  5499. },
  5500. setRangeLock: function (lock, updateList) {
  5501. if (this.options.lockRange === lock)
  5502. return;
  5503. this.options.lockRange = lock;
  5504. if (!lock) {
  5505. var gh = this.rtChart.getGridHeight();
  5506. }
  5507. if (updateList !== false)
  5508. this.rtChart._updateList(this.rowId, "量程锁定", this.options.lockRange);
  5509. },
  5510. onSetMinRange: function (nValue) {
  5511. if (!this.setGridSelf) {
  5512. var minset = parseFloat(nValue);
  5513. if (this.rageMax > minset) {
  5514. this.options.lockRange = true;
  5515. this.rtChart._updateList(this.rowId, "量程锁定", this.options.lockRange);
  5516. this.setRange(minset, this.rageMax, null);
  5517. }
  5518. this.updateRangeList();
  5519. }
  5520. },
  5521. onSetMaxRange: function (nValue) {
  5522. if (!this.setGridSelf) {
  5523. var maxset = parseFloat(nValue);
  5524. var gh = this.rtChart.getGridHeight();
  5525. if (maxset > this.rageMin) {
  5526. this.options.lockRange = true;
  5527. this.rtChart._updateList(this.rowId, "量程锁定", this.options.lockRange);
  5528. this.setRange(this.rageMin, maxset, null);
  5529. }
  5530. this.updateRangeList();
  5531. }
  5532. },
  5533. log10: function (val) {
  5534. return Math.log(val) / Math.LN10;
  5535. },
  5536. setRange: function (rageMin, rageMax, calls) {
  5537. if (this.rageMin != rageMin || this.rageMax != rageMax) {
  5538. this.rageMin = rageMin;
  5539. this.rageMax = rageMax;
  5540. if ((this.maxVqt && this.isFloat(this.maxVqt)) ||
  5541. (this.minVqt && this.isFloat(this.minVqt))) {
  5542. var r = Math.abs(this.rageMax - this.rageMin);
  5543. if (r < 1) {
  5544. var bSet = false;
  5545. if (r > 0.1) {
  5546. if (this.options.Num < 3) {
  5547. this.options.Num = 3;
  5548. bSet = true;
  5549. }
  5550. } else if (r > 0.01) {
  5551. if (this.options.Num < 4) {
  5552. this.options.Num = 4;
  5553. bSet = true;
  5554. }
  5555. } else if (r > 0.001) {
  5556. if (this.options.Num < 5) {
  5557. this.options.Num = 5;
  5558. bSet = true;
  5559. }
  5560. } else if (this.options.Num < 6) {
  5561. this.options.Num = 6;
  5562. bSet = true
  5563. }
  5564. if (bSet)
  5565. this.updateListGrid();
  5566. }
  5567. }
  5568. this.rtChart.updateDataArea();
  5569. this.rtChart.UpdateAxisPan(true);
  5570. this.updateRangeList();
  5571. }
  5572. if (this.commAxis && this.commAxis.length) {
  5573. if (calls == null)
  5574. calls = [];
  5575. calls.push(this);
  5576. for (var i = 0; i < this.commAxis.length; i++) {
  5577. var pen = this.commAxis[i];
  5578. var seted = false;
  5579. for (var k in calls) {
  5580. if (calls[k] == pen) {
  5581. seted = true;
  5582. break;
  5583. }
  5584. }
  5585. if (!seted)
  5586. pen.setRange(rageMin, rageMax, calls);
  5587. }
  5588. }
  5589. },
  5590. moveY: function (deltY) {
  5591. if (this.rageMin == null || this.rageMax == null || this.rageMax == this.rageMin)
  5592. return;
  5593. var gh = this.rtChart.getGridHeight();
  5594. var delt = (this.rageMax - this.rageMin) * deltY / gh;
  5595. this.setRange(this.rageMin + delt, this.rageMax + delt);
  5596. },
  5597. isGood: function (vqt) {
  5598. if (!vqt)
  5599. return false;
  5600. return (vqt.Qua == 0 || ((vqt.Qua & 0x100) && (vqt.Qua & 0xc0) == 0xc0));
  5601. },
  5602. isBad: function (vqt) {
  5603. return !this.isGood(vqt);
  5604. },
  5605. isUncertain: function (vqt) {
  5606. return false;
  5607. },
  5608. isFloat: function (vqt) {
  5609. if (!vqt || !vqt.Value)
  5610. return false;
  5611. var num = parseFloat(vqt.Value);
  5612. if (isNaN(num))
  5613. return false;
  5614. else {
  5615. if (num.toString().indexOf(".") > 0)
  5616. return true;
  5617. else
  5618. return false;
  5619. }
  5620. },
  5621. GetNumber: function (vqt) {
  5622. if (!vqt)
  5623. return 0;
  5624. var num = parseFloat(vqt.Value);
  5625. if (num == null)
  5626. return 0;
  5627. if (!isNaN(num))
  5628. return num;
  5629. else if (num.toString().toLowerCase() == "true")
  5630. return 1;
  5631. else if (num.toString().toLowerCase() == "false")
  5632. return 0;
  5633. var hash = 0;
  5634. if (!this.value || !this.value.length) return hash;
  5635. for (i = 0; i < this.value.length; i++) {
  5636. char = this.value.charCodeAt(i);
  5637. hash = ((hash << 5) - hash) + char;
  5638. hash = hash & hash;
  5639. }
  5640. return hash;
  5641. },
  5642. isBoolen: function (vqt) {
  5643. if (!vqt)
  5644. return false;
  5645. else if (vqt.Value == "true" || vqt.Value == "false")
  5646. return true;
  5647. else
  5648. return false;
  5649. },
  5650. isString: function (vqt) {
  5651. if (!vqt)
  5652. return false;
  5653. else if (vqt.Value == null)
  5654. return false;
  5655. else if (typeof vqt.Value == 'string')
  5656. return true;
  5657. else
  5658. return false;
  5659. },
  5660. getQuaStr: function (vqt) {
  5661. var re = "";
  5662. if (!vqt || vqt.Qua == null)
  5663. return re;
  5664. switch (vqt.Qua) {
  5665. case 0: //
  5666. re = "正常";
  5667. break;
  5668. case 1:
  5669. re = "无数据";
  5670. break;
  5671. case 2:
  5672. re = "创建";
  5673. break;
  5674. case 3:
  5675. re = "停机";
  5676. break;
  5677. case 4:
  5678. re = "计算停止";
  5679. break;
  5680. case 5:
  5681. re = "坏点";
  5682. break;
  5683. case 6:
  5684. re = "被零除";
  5685. break;
  5686. case 7:
  5687. re = "已被删除";
  5688. break;
  5689. default:
  5690. if (this.qua & 0x0100) // 从0x0100至0x01FF为OPC质量码
  5691. {
  5692. switch (this.qua & 0xFC) {
  5693. case 0x00:
  5694. re = "坏值";
  5695. break;
  5696. case 0x04:
  5697. re = "坏值(组态错误)";
  5698. break;
  5699. case 0x08:
  5700. re = "坏值(没有连接)";
  5701. break;
  5702. case 0x0C:
  5703. re = "坏值(设备故障)";
  5704. break;
  5705. case 0x10:
  5706. re = "坏值(传感器故障)";
  5707. break;
  5708. case 0x14:
  5709. re = "坏值(最后值)";
  5710. break;
  5711. case 0x18:
  5712. re = "坏值(通讯故障)";
  5713. break;
  5714. case 0x1C:
  5715. re = "坏值(退出服务)";
  5716. break;
  5717. case 0x20:
  5718. re = "坏值(不被许可)";
  5719. break;
  5720. case 0x24:
  5721. re = "坏值(超出量程)";
  5722. break;
  5723. case 0x2C:
  5724. re = "坏值(未定义值)";
  5725. break;
  5726. case 0x28:
  5727. re = "坏值(计算错误)";
  5728. break;
  5729. case 0x30:
  5730. re = "坏值(输出开路)";
  5731. break;
  5732. case 0x34:
  5733. re = "坏值(输入开路)";
  5734. break;
  5735. case 0x3C:
  5736. re = "坏值(转换错误)";
  5737. break;
  5738. case 0x40:
  5739. re = "坏值(可疑值)";
  5740. break;
  5741. case 0x44:
  5742. re = "可疑值(最后值)";
  5743. break;
  5744. case 0x48:
  5745. re = "可疑值(输出开路)";
  5746. break;
  5747. case 0x4C:
  5748. re = "可疑值(等待同步)";
  5749. break;
  5750. case 0x50:
  5751. re = "可疑值(传感器校正)";
  5752. break;
  5753. case 0x54:
  5754. re = "可疑值(超出量程)";
  5755. break;
  5756. case 0x58:
  5757. re = "可疑值(子故障)";
  5758. break;
  5759. case 0x5C:
  5760. re = "可疑值(输入开路)";
  5761. break;
  5762. case 0x60:
  5763. re = "可疑值(转换错误)";
  5764. break;
  5765. case 0xC0:
  5766. re = "正常";
  5767. break;
  5768. case 0xC4:
  5769. re = "正常(初始化)";
  5770. break;
  5771. case 0xC4:
  5772. re = "正常(无状态)";
  5773. break;
  5774. case 0xD8:
  5775. re = "正常(当地重载)";
  5776. break;
  5777. }
  5778. } else {
  5779. re = "用户自定义";
  5780. }
  5781. break;
  5782. }
  5783. return re;
  5784. },
  5785. getFullStampTimeStr: function (vqt) {
  5786. return GoldenRtWeb.FileTimeToString(vqt.StampTime, false);
  5787. },
  5788. getStampTimeStr: function (vqt) {
  5789. return GoldenRtWeb.FileTimeToString(vqt.StampTime, false);
  5790. },
  5791. expendY: function (deltaY) {
  5792. if (this.rageMin == null || this.rageMax == null || this.rageMax == this.rageMin)
  5793. return;
  5794. var gh = this.rtChart.getGridHeight();
  5795. var delt = (this.rageMax - this.rageMin) * deltaY / gh;
  5796. var M = null;
  5797. if (this.minVqt && this.isGood(this.minVqt) && this.maxVqt && this.isGood(this.maxVqt)) {
  5798. if (this.isBoolen(this.minVqt))
  5799. M = 0.5;
  5800. else if (this.GetNumber(this.minVqt) != this.GetNumber(this.maxVqt))
  5801. M = 0.5 * (this.GetNumber(this.maxVqt) - this.GetNumber(this.minVqt)) + this.GetNumber(this.minVqt);
  5802. else
  5803. M = 0.5 * this.GetNumber(this.maxVqt);
  5804. } else if (this.minVqt && this.isGood(this.minVqt)) {
  5805. if (this.isBoolen(this.minVqt))
  5806. M = 0.5;
  5807. else
  5808. M = 0.5 * this.GetNumber(this.minVqt);
  5809. } else if (this.maxVqt && this.isGood(this.maxVqt)) {
  5810. if (this.isBoolen(this.maxVqt))
  5811. M = 0.5;
  5812. else
  5813. M = 0.5 * this.GetNumber(this.maxVqt);
  5814. } else
  5815. return;
  5816. var K = (M - this.rageMin) / (this.rageMax - this.rageMin);
  5817. var max = this.rageMax + delt;
  5818. var min = (M - K * max) / (1 - K);
  5819. if (max <= min)
  5820. return;
  5821. this.setRange(min, max);
  5822. },
  5823. getY: function (val) {
  5824. if (this.rageMin == null || this.rageMax == null || this.rageMin == this.rageMax)
  5825. return null;
  5826. var gh = this.rtChart.getGridHeight();
  5827. var y = gh - gh * (val - this.rageMin) / (this.rageMax - this.rageMin);
  5828. return y;
  5829. },
  5830. getVal: function (y) {
  5831. if (this.rageMin == null || this.rageMax == null || this.rageMin == this.rageMax)
  5832. return null;
  5833. var gh = this.rtChart.getGridHeight();
  5834. var v = this.rageMin + (gh - y) * (this.rageMax - this.rageMin) / gh;
  5835. return v;
  5836. },
  5837. hasDataAtTime: function (ft, y) {
  5838. if (this.hisData) {
  5839. var yVal = this.getVal(y);
  5840. if (yVal == null)
  5841. return false;
  5842. if (this.minVqt && this.isGood(this.minVqt) && this.GetNumber(this.minVqt) > yVal) {
  5843. if (this.isBoolen(this.minVqt) && yVal < 0)
  5844. return false;
  5845. if (this.maxVqt && this.isGood(this.maxVqt) && this.GetNumber(this.maxVqt) == this.GetNumber(this.minVqt)) {
  5846. if (this.rageMin > yVal)
  5847. return false;
  5848. } else
  5849. return false;
  5850. }
  5851. if (this.maxVqt && this.isGood(this.maxVqt) && this.GetNumber(this.maxVqt) < yVal) {
  5852. if (this.isBoolen(this.maxVqt) && yVal > 1)
  5853. return false;
  5854. else if (this.minVqt && this.isGood(this.minVqt) && this.GetNumber(this.maxVqt) == this.GetNumber(this.minVqt)) {
  5855. if (this.rageMax < yVal)
  5856. return false;
  5857. } else
  5858. return false;
  5859. }
  5860. var prev = null;
  5861. var len = this.hisData.length;
  5862. for (var i = 0; i < len; i++) {
  5863. var vqt = this.hisData[i];
  5864. if (vqt.StampTime == ft)
  5865. return true;
  5866. else if (vqt.StampTime > ft) {
  5867. if (prev)
  5868. return true;
  5869. else
  5870. return false;
  5871. } else
  5872. prev = vqt;
  5873. }
  5874. return false;
  5875. } else
  5876. return false;
  5877. },
  5878. hasDataBetweenTime: function (begTime, endTime) {
  5879. if (this.hisData) {
  5880. var len = this.hisData.length;
  5881. for (var i = 0; i < len; i++) {
  5882. var vqt = this.hisData[i];
  5883. if (vqt.StampTime >= begTime && vqt.StampTime <= endTime)
  5884. return true;
  5885. }
  5886. return false;
  5887. } else
  5888. return false;
  5889. },
  5890. getPanHeight: function () {
  5891. var h = 55;
  5892. if (this.vqt)
  5893. h += SPANLINEHEIGHT;
  5894. if (this.avg != null)
  5895. h += SPANLINEHEIGHT;
  5896. if (this.maxVqt)
  5897. h += SPANLINEHEIGHT
  5898. if (this.minVq)
  5899. h += SPANLINEHEIGHT;
  5900. return h;
  5901. },
  5902. isLinkRq: function () {
  5903. if (this.itemDef)
  5904. return false;
  5905. else if (this.linkTime && (new Date() - this.linkTime < this.options.linkReTryTime))
  5906. return false;
  5907. else
  5908. return true;
  5909. },
  5910. isLinked: function () {
  5911. return this.itemDef != null;
  5912. },
  5913. getConfig: function () {
  5914. var config = {};
  5915. config.URI = this.getURI();
  5916. config.linkReTryTime = this.options.linkReTryTime;
  5917. config.penColor = this.options.penColor;
  5918. config.Num = this.options.Num;
  5919. config.penWidth = this.options.penWidth || 1;
  5920. config.drawLine = this.options.drawLine;
  5921. config.stepLine = this.options.stepLine == null ? false : this.options.stepLine;
  5922. config.drawTag = this.options.drawTag;
  5923. config.interpolate = this.options.interpolate == null ? false : this.options.interpolate;
  5924. config.hisReTryTime = this.options.hisReTryTime;
  5925. config.lockRange = this.options.lockRange;
  5926. config.rageMax = this.rageMax;
  5927. config.rageMin = this.rageMin;
  5928. if (this.commAxis) {
  5929. var axis = [];
  5930. for (var i = 0; i < this.commAxis.length; i++) {
  5931. var pen = this.commAxis[i];
  5932. axis.push(pen.getURI());
  5933. }
  5934. config.commAxis = axis;
  5935. }
  5936. return config;
  5937. },
  5938. setDes: function (des) {
  5939. this.des = des;
  5940. if (this.rtChart && this.rowId)
  5941. this.rtChart._updateList(this.rowId, "描述", this.getDes());
  5942. },
  5943. getDes: function () {
  5944. return this.des;
  5945. },
  5946. getWebURL: function () {
  5947. return GoldenRtWeb.getWebURL();
  5948. },
  5949. getURI: function () {
  5950. return this.options.URI;
  5951. },
  5952. getLabel: function () {
  5953. var uri = this.getURI();
  5954. var i = uri.lastIndexOf(".");
  5955. if (i > 0)
  5956. return uri.substring(i + 1);
  5957. else
  5958. return uri;
  5959. },
  5960. getPenColor: function () {
  5961. return this.options.penColor;
  5962. },
  5963. onSetLineWidth: function (nValue, fromgrid) {
  5964. this.options.penWidth = parseInt(nValue);
  5965. this.rtChart.updateDataArea();
  5966. if (!fromgrid)
  5967. this.rtChart._updateList(this.rowId, "线宽", this.options.penWidth);
  5968. },
  5969. setPenColor: function (rgba) {
  5970. this.options.penColor = rgba;
  5971. this.panPos = null;
  5972. this.rtChart.UpdatePan(false);
  5973. this.rtChart.updateDataArea();
  5974. this.rtChart._updateList(this.rowId, "点名称", {
  5975. uri: this.getURI(),
  5976. color: this.getPenColor()
  5977. });
  5978. },
  5979. drawPan: function (bredraw, ctx, t, w) {
  5980. var bReDaw = this.activeChanged || bredraw || ((t === this.panPos) ? false : true);
  5981. var cleared = false;
  5982. var dt = SPANPAD;
  5983. var h = SPANLINEHEIGHT;
  5984. if (bReDaw) {
  5985. this.activeChanged = false;
  5986. this.panPos = t;
  5987. ctx.clearRect(1, 0, w - 2, this.getPanHeight());
  5988. cleared = true;
  5989. ctx.translate(0.5, 0.5);
  5990. ctx.lineWidth = 1;
  5991. ctx.beginPath();
  5992. ctx.strokeStyle = "rgb(30,30,30)";
  5993. ctx.moveTo(1, 1)
  5994. ctx.lineTo(w - 2, 1);
  5995. ctx.stroke();
  5996. ctx.beginPath();
  5997. ctx.strokeStyle = "rgb(220,220,220)";
  5998. ctx.moveTo(1, 2)
  5999. ctx.lineTo(w - 2, 2);
  6000. ctx.stroke();
  6001. ctx.beginPath();
  6002. ctx.fillStyle = this.options.penColor;
  6003. ctx.strokeStyle = this.options.penColor;
  6004. ctx.rect(6.5, 9.5, 8, 8);
  6005. ctx.fill();
  6006. ctx.textAlign = "left";
  6007. ctx.fillText(this.getLabel(), 18, dt, w - 12);
  6008. if (this.bActive) {
  6009. ctx.rect(2, 3, w - 4, this.getPanHeight() - 4);
  6010. ctx.stroke();
  6011. }
  6012. var r = w - 10;
  6013. ctx.beginPath();
  6014. ctx.moveTo(r, 6)
  6015. ctx.lineTo(r + 6, 12);
  6016. ctx.moveTo(r + 6, 6)
  6017. ctx.lineTo(r, 12);
  6018. ctx.stroke();
  6019. }
  6020. var img = this.rtChart.getButtonImage();
  6021. if (img && !img.complete)
  6022. img = null;
  6023. var likdarwed = false;
  6024. dt += h;
  6025. if ((bReDaw || this.linkChanged) && this.linkStatus != null) {
  6026. this.linkChanged = false;
  6027. if (!cleared)
  6028. ctx.clearRect(3, dt, w - 5, h);
  6029. likdarwed = true;
  6030. if (img) {
  6031. switch (this.linkStatus) {
  6032. case 'linking':
  6033. ctx.drawImage(img, 22, 0, 5, 6, 8, dt, 5, 6);
  6034. break;
  6035. case 'linked':
  6036. ctx.drawImage(img, 36, 0, 10, 7, 8, dt, 10, 7);
  6037. break;
  6038. case 'error':
  6039. ctx.drawImage(img, 27, 0, 5, 5, 8, dt, 5, 5);
  6040. break;
  6041. default:
  6042. ctx.drawImage(img, 32, 0, 4, 5, 8, dt, 4, 5);
  6043. break;
  6044. }
  6045. }
  6046. if (this.unit) {
  6047. ctx.fillStyle = this.options.penColor;
  6048. ctx.textAlign = "right";
  6049. ctx.textBaseline = "top";
  6050. ctx.fillText(this.unit, w - 2, dt, w - 50);
  6051. }
  6052. }
  6053. if ((bReDaw || this.hisChanged || likdarwed) && this.hisGetStaus != null) {
  6054. this.hisChanged = false;
  6055. if (!likdarwed && !cleared)
  6056. ctx.clearRect(20, dt, 10, h);
  6057. if (img) {
  6058. switch (this.hisGetStaus) {
  6059. case 'getting':
  6060. ctx.drawImage(img, 22, 0, 5, 6, 20, 23, 5, 6);
  6061. break;
  6062. case 'error':
  6063. ctx.drawImage(img, 27, 0, 5, 5, 20, 23, 5, 5);
  6064. break;
  6065. case 'linked':
  6066. ctx.drawImage(img, 22, 6, 8, 5, 20, 24, 8, 5);
  6067. break;
  6068. case "nodata":
  6069. case "wait":
  6070. ctx.drawImage(img, 46, 0, 10, 10, 20, 23, 10, 10);
  6071. break;
  6072. default:
  6073. ctx.drawImage(img, 32, 0, 4, 5, 20, 23, 4, 5);
  6074. break;
  6075. }
  6076. }
  6077. }
  6078. dt += h;
  6079. if (bReDaw || this.vqtChanged) {
  6080. this.vqtChanged = false;
  6081. if (!cleared)
  6082. ctx.clearRect(3, dt, w - 5, h);
  6083. if (this.vqt) {
  6084. ctx.fillStyle = this.options.penColor;
  6085. ctx.textAlign = "left";
  6086. ctx.textBaseline = "top";
  6087. ctx.fillText("实时", 5, dt, 30);
  6088. if (this.vqt.isBad())
  6089. ctx.fillStyle = "rgb(200,0,0)";
  6090. else if (this.vqt.isUncertain())
  6091. ctx.fillStyle = "rgb(160,150,0)";
  6092. ctx.textAlign = "right";
  6093. if (this.vqt.value != null)
  6094. ctx.fillText((this.vqt.isFloat() ? this.vqt.value.toFixed(this.options.Num) : this.vqt.value), w - 3, dt, w - 30);
  6095. else if (this.vqt.isBad())
  6096. ctx.fillText("####", w - 3, dt, w - 30);
  6097. else if (this.vqt.isUncertain())
  6098. ctx.fillText("????", w - 3, dt, w - 30);
  6099. }
  6100. }
  6101. if (this.vqt)
  6102. dt += h;
  6103. if (bReDaw || this.avgChanged) {
  6104. this.avgChanged = false;
  6105. if (!cleared)
  6106. ctx.clearRect(3, dt, w - 5, h);
  6107. if (this.avg != null) {
  6108. ctx.fillStyle = this.options.penColor;
  6109. ctx.textAlign = "left";
  6110. ctx.textBaseline = "top";
  6111. ctx.fillText("平均", 5, dt, 30);
  6112. ctx.textAlign = "right";
  6113. ctx.fillText(this.avg.toFixed(this.options.Num), w - 3, dt, w - 30);
  6114. }
  6115. }
  6116. if (this.avg != null)
  6117. dt += h;
  6118. if (bReDaw || this.minChanged) {
  6119. this.minChanged = false;
  6120. if (!cleared)
  6121. ctx.clearRect(3, dt, w - 5, h);
  6122. if (this.minVqt) {
  6123. ctx.fillStyle = this.options.penColor;
  6124. ctx.textAlign = "left";
  6125. ctx.textBaseline = "top";
  6126. ctx.fillText("最小", 5, dt, 30);
  6127. if (!this.isGood(this.minVqt)) {
  6128. ctx.fillStyle = "rgb(120,0,0)";
  6129. }
  6130. ctx.textAlign = "right";
  6131. if (this.minVqt.Value != null)
  6132. ctx.fillText((this.isFloat(this.minVqt) ? this.minVqt.Value.toFixed(this.options.Num) : this.minVqt.Value), w - 3, dt, w - 30);
  6133. else if (!this.isGood(this.minVqt))
  6134. ctx.fillText("####", w - 3, dt, w - 30);
  6135. }
  6136. }
  6137. if (this.minVqt)
  6138. dt += h;
  6139. if (bReDaw || this.maxChanged) {
  6140. this.maxChanged = false;
  6141. if (!cleared)
  6142. ctx.clearRect(3, dt, w - 5, h);
  6143. if (this.maxVqt) {
  6144. ctx.fillStyle = this.options.penColor;
  6145. ctx.textAlign = "left";
  6146. ctx.textBaseline = "top";
  6147. ctx.fillText("最大", 5, dt, 30);
  6148. if (!this.isGood(this.maxVqt)) {
  6149. ctx.fillStyle = "rgb(120,0,0)";
  6150. }
  6151. ctx.textAlign = "right";
  6152. if (this.maxVqt.Value != null)
  6153. ctx.fillText((this.isFloat(this.maxVqt) ? this.maxVqt.Value.toFixed(this.options.Num) : this.maxVqt.Value), w - 3, dt, w - 30);
  6154. else if (!this.isGood(this.maxVqt))
  6155. ctx.fillText("####", w - 3, dt, w - 30);
  6156. }
  6157. }
  6158. },
  6159. setLinkStatus: function (status, info, nodelay) {
  6160. if (!this.rtChart)
  6161. return;
  6162. if (status == "linking")
  6163. this.linkTime = new Date();
  6164. else if (this.linkStatus == "linking" && !(nodelay === true)) {
  6165. var self = this;
  6166. if (this.linkingTime)
  6167. window.clearTimeout(this.linkingTime);
  6168. this.linkingTime = window.setTimeout(function () {
  6169. window.clearTimeout(self.linkingTime);
  6170. self.linkingTime = null;
  6171. self.setLinkStatus(status, info, true);
  6172. self = null;
  6173. }, 100);
  6174. return;
  6175. }
  6176. if (this.linkStatus != status || this.linkInfo != info) {
  6177. this.linkStatus = status;
  6178. this.linkInfo = info;
  6179. if (this.linkStatus == "error" && this.linkInfo && this.linkInfo.lastIndexOf("E_AUTHENERR") >= 0) {
  6180. this.requestLogin = true;
  6181. this.rtChart.requestLogin();
  6182. } else if (this.linkStatus != 'linking')
  6183. this.requestLogin = false;
  6184. this.linkChanged = true;
  6185. this.rtChart.UpdateDataPan(false);
  6186. if (!this.preventTooltipUpdate && this.showTolltip && this.toolTipAt == "linkStatus" && !(this.requestLogin === true))
  6187. this.rtChart.UpdateTooltip(this.getLinkStatus());
  6188. }
  6189. },
  6190. getLinkStatus: function () {
  6191. var st;
  6192. switch (this.linkStatus) {
  6193. case "linking":
  6194. st = '<span style="color:#00BFFF">正在连接...</span>';
  6195. break;
  6196. case "error":
  6197. st = '<span style="color:#DF0101">连接故障!</span>';
  6198. break;
  6199. case "linked":
  6200. st = '<span style="color:#00aa00">已连接</span>';
  6201. break;
  6202. default:
  6203. st = '<span style="color:#DF0101">状态码未知!</span>';
  6204. }
  6205. if (this.linkInfo) {
  6206. st += "<br>";
  6207. st += this.linkInfo;
  6208. }
  6209. return st;
  6210. },
  6211. resetAxisDrawed: function () {
  6212. this.axisDrawed = false;
  6213. this.axisBeg = null;
  6214. this.axisEnd = null;
  6215. },
  6216. setAxisDrawed: function (calls) {
  6217. this.axisDrawed = true;
  6218. if (this.commAxis && this.commAxis.length) {
  6219. if (calls == null)
  6220. calls = [];
  6221. calls.push(this);
  6222. for (var i = 0; i < this.commAxis.length; i++) {
  6223. var pen = this.commAxis[i];
  6224. var seted = false;
  6225. for (var k in calls) {
  6226. if (calls[k] == pen) {
  6227. seted = true;
  6228. break;
  6229. }
  6230. }
  6231. if (!seted)
  6232. pen.setAxisDrawed(calls);
  6233. }
  6234. }
  6235. },
  6236. drawAxis: function (begX, h, ctx) {
  6237. if (this.axisDrawed || !this.options.drawLine)
  6238. return 0;
  6239. var maxW = 30;
  6240. ctx.beginPath();
  6241. if (this == this.rtChart.getActivePen())
  6242. ctx.strokeStyle = this.getPenColor();
  6243. else if (this.commAxis && this.commAxis.length) {
  6244. for (var i = 0; i < this.commAxis.length; i++) {
  6245. var pen = this.commAxis[i];
  6246. if (pen == this.rtChart.getActivePen()) {
  6247. ctx.strokeStyle = pen.getPenColor();
  6248. break;
  6249. }
  6250. }
  6251. }
  6252. if ((this.minVqt && this.isBoolen(this.minVqt)) || (this.maxVqt && this.isBoolen(this.maxVqt))) {
  6253. var t = this.getY(1);
  6254. if (t == null)
  6255. return 0;
  6256. var b = this.getY(0);
  6257. ctx.moveTo(begX, t);
  6258. ctx.lineTo(begX, b);
  6259. ctx.moveTo(begX, t);
  6260. ctx.lineTo(begX + 3, t);
  6261. ctx.textBaseline = "top";
  6262. ctx.fillText("1", begX + 2, t);
  6263. ctx.moveTo(begX, b);
  6264. ctx.lineTo(begX + 3, b);
  6265. ctx.textBaseline = "bottom";
  6266. ctx.fillText("0", begX + 2, b);
  6267. ctx.stroke();
  6268. maxW -= 22;
  6269. } else {
  6270. if (this.rageMax == null || this.rageMin == null || this.rageMax == this.rageMin)
  6271. return 0;
  6272. var r = Math.abs(this.rageMax - this.rageMin) / 20;
  6273. var Num = 0;
  6274. if (r < 1) {
  6275. r = 1.0 / r;
  6276. Num = Math.ceil(this.log10(r));
  6277. }
  6278. ctx.moveTo(begX, 0);
  6279. ctx.lineTo(begX, h);
  6280. ctx.moveTo(begX - 2, 0)
  6281. ctx.lineTo(begX + 2, 0);
  6282. ctx.textBaseline = "top";
  6283. var str = this.rageMax.toFixed(Num).toString();
  6284. if (str.length > 5) {
  6285. var d = (str.length - 5) * 5;
  6286. if (d > 20)
  6287. d = 20;
  6288. maxW += d;
  6289. }
  6290. ctx.fillText(str, begX + 2, -2, maxW - 2);
  6291. ctx.moveTo(begX - 2, h)
  6292. ctx.lineTo(begX + 2, h);
  6293. ctx.textBaseline = "middle";
  6294. ctx.fillText(this.rageMin.toFixed(Num), begX + 2, h, maxW - 2);
  6295. ctx.textBaseline = "middle";
  6296. var y = h / 20.0;
  6297. for (var i = 1; i < 20; i++) {
  6298. var iy = Math.floor(y);
  6299. ctx.moveTo(begX - 2, iy)
  6300. ctx.lineTo(begX + 1, iy);
  6301. ctx.fillText((this.rageMax - i * (this.rageMax - this.rageMin) / 20).toFixed(Num), begX + 3, iy, maxW - 2);
  6302. y += h / 20.0;
  6303. }
  6304. ctx.stroke();
  6305. }
  6306. var x = begX;
  6307. var y;
  6308. if ((this.minVqt && this.isBoolen(this.minVqt)) || (this.maxVqt && this.isBoolen(this.maxVqt)))
  6309. y = this.getY(0) + 6;
  6310. else
  6311. y = h + 6;
  6312. ctx.beginPath();
  6313. ctx.fillStyle = this.getPenColor();
  6314. ctx.rect(x, y, 5, 5);
  6315. ctx.fill();
  6316. x += 7;
  6317. if (x + 5 > begX + maxW) {
  6318. x = begX;
  6319. y += 7;
  6320. }
  6321. this.setAxisDrawed();
  6322. if (this.commAxis && this.commAxis.length) {
  6323. for (var i = 0; i < this.commAxis.length; i++) {
  6324. var pen = this.commAxis[i];
  6325. ctx.beginPath();
  6326. ctx.fillStyle = pen.getPenColor();
  6327. ctx.rect(x, y, 5, 5);
  6328. ctx.fill();
  6329. x += 7;
  6330. if (x + 5 > begX + maxW) {
  6331. x = begX;
  6332. y += 7;
  6333. }
  6334. }
  6335. }
  6336. this.axisBeg = begX;
  6337. this.axisEnd = begX + maxW;
  6338. return maxW;
  6339. },
  6340. removeCommAxis: function (pen) {
  6341. if (this.commAxis) {
  6342. var len = this.commAxis.length;
  6343. for (var i = 0; i < len; i++) {
  6344. if (this.commAxis[i] == pen) {
  6345. this.commAxis.splice(i, 1);
  6346. break;
  6347. }
  6348. }
  6349. }
  6350. },
  6351. addCommAxis: function (pen) {
  6352. var oldComm = this.commAxis;
  6353. this.commAxis = null;
  6354. if (oldComm) {
  6355. for (var i = 0; i < oldComm.length; i++)
  6356. oldComm[i].removeCommAxis(this);
  6357. }
  6358. this.setRange(pen.rageMin, pen.rageMax);
  6359. this.commAxis = [];
  6360. this.commAxis.push(pen);
  6361. },
  6362. onCommAxisSet: function (arr) {
  6363. var newComm = null;
  6364. for (var i = 0; i < arr.length; i++) {
  6365. var ind = arr[i];
  6366. var pen = this.rtChart.trendPens[ind];
  6367. if (pen && pen != this) {
  6368. if (newComm == null)
  6369. newComm = [];
  6370. newComm.push(pen);
  6371. }
  6372. }
  6373. var oldComm = this.commAxis;
  6374. this.commAxis = null;
  6375. if (oldComm) {
  6376. for (var i = 0; i < oldComm.length; i++) {
  6377. var pen = oldComm[i];
  6378. pen.removeCommAxis(this);
  6379. }
  6380. }
  6381. if (newComm) {
  6382. for (var i = 0; i < newComm.length; i++)
  6383. newComm[i].addCommAxis(this);
  6384. }
  6385. this.commAxis = newComm;
  6386. this.rtChart.UpdateAxisPan(true);
  6387. },
  6388. onSetCommAxis: function (e) {
  6389. this.rtChart.requestActive(this);
  6390. var pen = this;
  6391. var content = '<form action="" method="get" style="line-height:26px;width:100%">选择共轴位号:';
  6392. var bIsBool = false;
  6393. if (this.minVqt && this.isBoolen(this.minVqt))
  6394. bIsBool = true;
  6395. else if (this.maxVqt && this.isBoolen(this.maxVqt))
  6396. bIsBool = true;
  6397. var pens = this.rtChart.trendPens;
  6398. for (var i = 0; i < pens.length; i++) {
  6399. var pen = pens[i];
  6400. if (pen == this)
  6401. 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>';
  6402. else {
  6403. var bIsComm = false;
  6404. if (this.commAxis && this.commAxis.length) {
  6405. for (var k = 0; k < this.commAxis.length; k++) {
  6406. if (this.commAxis[k] == pen) {
  6407. bIsComm = true;
  6408. break;
  6409. }
  6410. }
  6411. }
  6412. if (bIsComm) {
  6413. content += '<br><label ' + (pen.getDes() ? ('title="' + pen.getDes() + '"') : '') + ' style="color:' + pen.getPenColor() + '"><input type="checkbox" checked="checked" value="' + i + '"/>' + pen.getLabel() + '</label>';
  6414. } else {
  6415. var bpenIsBool = false;
  6416. if (pen.minVqt && pen.isBoolen(pen.minVqt))
  6417. bpenIsBool = true;
  6418. else if (pen.maxVqt && pen.isBoolen(pen.maxVqt))
  6419. bpenIsBool = true;
  6420. if (bpenIsBool == bIsBool) {
  6421. content += '<br><label ' + (pen.getDes() ? ('title="' + pen.getDes() + '"') : '') + ' style="color:' + pen.getPenColor() + '"><input type="checkbox" value="' + i + '"/>' + pen.getLabel() + '</label>';
  6422. }
  6423. }
  6424. }
  6425. }
  6426. content += '</form>';
  6427. var pen = this;
  6428. var d = dialog({
  6429. title: '设置 ' + this.getLabel() + ' 的共轴显示',
  6430. quickClose: true,
  6431. content: content,
  6432. padding: 10,
  6433. okValue: '确定',
  6434. ok: function () {
  6435. var arr = [];
  6436. var sel = $('input[type=checkbox]', this.__popup);
  6437. for (var i = 0; i < sel.length; i++) {
  6438. if (sel[i].checked)
  6439. arr.push(parseInt(sel[i].value));
  6440. }
  6441. pen.onCommAxisSet(arr);
  6442. pen = null;
  6443. d.close().remove();
  6444. d = null;
  6445. }
  6446. });
  6447. e.pageX += 10;
  6448. e.pageY -= 30;
  6449. d.show(e);
  6450. },
  6451. getCommGroup: function (penGroup) {
  6452. penGroup.push(this);
  6453. if (this.commAxis && this.commAxis.length) {
  6454. for (var i = 0; i < this.commAxis.length; i++) {
  6455. var pen = this.commAxis[i];
  6456. var find = false;
  6457. for (var k in penGroup) {
  6458. if (penGroup[k] == pen) {
  6459. find = true;
  6460. break;
  6461. }
  6462. }
  6463. if (!find)
  6464. pen.getCommGroup(penGroup);
  6465. }
  6466. }
  6467. },
  6468. setHisStatus: function (status, info, nodelay) {
  6469. if (!this.rtChart)
  6470. return;
  6471. if (status == "getting")
  6472. this.hisTime = new Date();
  6473. else if (this.hisGetStaus == "getting" && !(nodelay === true)) {
  6474. var self = this;
  6475. if (this.hisingTime)
  6476. window.clearTimeout(this.hisingTime);
  6477. this.hisingTime = window.setTimeout(function () {
  6478. window.clearTimeout(self.hisingTime);
  6479. self.hisingTime = null;
  6480. self.setHisStatus(status, info, true);
  6481. self = null;
  6482. }, 100);
  6483. return;
  6484. }
  6485. if (this.hisGetStaus != status || this.hisInfo != info) {
  6486. this.hisGetStaus = status;
  6487. this.hisInfo = info;
  6488. this.hisChanged = true;
  6489. this.rtChart.UpdateDataPan(false);
  6490. if (!this.preventTooltipUpdate && this.showTolltip && this.toolTipAt == "hisStatus" && !(this.requestLogin === true))
  6491. this.rtChart.UpdateTooltip(this.getHisStatus());
  6492. }
  6493. },
  6494. getHisStatus: function () {
  6495. var st;
  6496. switch (this.hisGetStaus) {
  6497. case "getting":
  6498. st = '<span style="color:#00BFFF">正在获取...</span>';
  6499. break;
  6500. case "wait":
  6501. st = '<span style="color:#00BFFF">正在等待...</span>';
  6502. break;
  6503. case "error":
  6504. st = '<span style="color:#DF0101">连接故障!</span>';
  6505. break;
  6506. case "linked":
  6507. st = '<span style="color:#00aa00">已获得历史数据</span>';
  6508. break;
  6509. case "nodata":
  6510. st = '<span style="color:#003366">无历史数据</span>';
  6511. break;
  6512. default:
  6513. st = '<span style="color:#DF0101">状态码未知!</span>';
  6514. }
  6515. if (this.hisInfo) {
  6516. st += "<br>";
  6517. st += this.hisInfo;
  6518. }
  6519. return st;
  6520. },
  6521. getpreventTooltipUpdate: function () {
  6522. return this.preventTooltipUpdate;
  6523. },
  6524. onTooltipShowed: function () {
  6525. this.showTolltip = true;
  6526. },
  6527. onTooltipHided: function () {
  6528. this.showTolltip = false;
  6529. this.preventTooltipUpdate = false;
  6530. this.toolTipAt = null;
  6531. },
  6532. isActive: function () {
  6533. return this.bActive;
  6534. },
  6535. setActive: function (bActive) {
  6536. if (this.bActive == bActive || !this.rtChart)
  6537. return;
  6538. this.bActive = bActive;
  6539. this.activeChanged = true;
  6540. this.rtChart.UpdatePan(false);
  6541. },
  6542. activePen: function () {
  6543. var nowActived = this.rtChart.getActivePen() == this;
  6544. if (nowActived)
  6545. this.bActive = true;
  6546. else
  6547. this.rtChart.requestActive(this);
  6548. },
  6549. onMouseMove: function (x, y, e, clientX, clientY, panH) {
  6550. var w = this.rtChart.getPanWidth();
  6551. var ta = (clientY > panH / 2) ? 'top right' : 'bottom right';
  6552. var ty = e.pageY + ((clientY > panH / 2) ? -8 : 8);
  6553. var t = SPANPAD;
  6554. var h = SPANLINEHEIGHT;
  6555. if (y >= 0 && y < t + h) {
  6556. if (x < 20) {
  6557. var opt = {
  6558. content: "点击设置趋势笔颜色",
  6559. align: ta,
  6560. skin: 'tooltipTans',
  6561. x: e.pageX + 10,
  6562. y: ty
  6563. }
  6564. this.toolTipAt = null;
  6565. this.rtChart.showTooltip(opt, this);
  6566. this.rtChart.setCursor("pointer");
  6567. return true;
  6568. } else if (x < w - 10) {
  6569. if (this.rtChart && this.rtChart.getLoginPen && this.rtChart.getLoginPen() != this) {
  6570. var opt = {
  6571. title: this.getLabel(),
  6572. content: "<b>存取路径:</b><br>" + this.getURI() + (this.des && this.des.length ? ("<br><b>描 述:</b><br>" + this.des) : "") + "<br><b>Web服务:</b><br>" + this.getWebURL(),
  6573. skin: 'tooltipTans',
  6574. align: ta,
  6575. x: e.pageX + 20,
  6576. y: ty
  6577. }
  6578. this.toolTipAt = null;
  6579. this.rtChart.showTooltip(opt, this, e);
  6580. this.rtChart.setCursor("pointer");
  6581. return true;
  6582. }
  6583. } else {
  6584. var opt = {
  6585. content: "单击移除趋势笔",
  6586. skin: 'tooltipTans',
  6587. align: ta,
  6588. x: e.pageX,
  6589. y: ty
  6590. }
  6591. this.toolTipAt = null;
  6592. this.rtChart.showTooltip(opt, this);
  6593. this.rtChart.setCursor("pointer");
  6594. return true;
  6595. }
  6596. } else if (y >= t + h && y < t + 2 * h) {
  6597. if (x >= 0 && x < 18) {
  6598. var st;
  6599. var bHook = false;
  6600. if (this.requestLogin === true) {
  6601. st = '实时信息网站:<br><span style="color:#00BFFF">' + this.getWebURL() + "</span><br>需要登录,点击<a href='Javascript: void(0)'>这里</a>进行操作";
  6602. this.preventTooltipUpdate = true;
  6603. bHook = true;
  6604. } else {
  6605. st = this.getLinkStatus();
  6606. this.preventTooltipUpdate = false;
  6607. }
  6608. var opt = {
  6609. title: '连接状态',
  6610. content: st,
  6611. skin: 'tooltipTans',
  6612. align: ta,
  6613. x: e.pageX + 20,
  6614. y: ty
  6615. }
  6616. if (bHook) {
  6617. var trendPen = this;
  6618. var showed = false;
  6619. opt.onshow = function () {
  6620. if (showed === false) {
  6621. showed = true;
  6622. $('a', this.__popup).click(function () {
  6623. $(this).unbind('click');
  6624. trendPen.rtChart.requestLogin();
  6625. trendPen = null;
  6626. });
  6627. }
  6628. };
  6629. } else
  6630. opt.width = 180;
  6631. this.rtChart.showTooltip(opt, this);
  6632. this.toolTipAt = "linkStatus";
  6633. } else if (x >= 20 && x < 30 && this.hisGetStaus != null) {
  6634. var opt = {
  6635. title: '历史数据获取状态',
  6636. content: this.getHisStatus(),
  6637. skin: 'tooltipTans',
  6638. width: 180,
  6639. align: ta,
  6640. x: e.pageX + 20,
  6641. y: ty
  6642. }
  6643. this.rtChart.showTooltip(opt, this);
  6644. this.toolTipAt = "hisStatus";
  6645. } else if (x > w - 22) {
  6646. if (this.unit) {
  6647. var opt = {
  6648. content: '工程单位:' + this.unit,
  6649. skin: 'tooltipTans',
  6650. align: ta,
  6651. x: e.pageX + 10,
  6652. y: ty
  6653. }
  6654. this.rtChart.showTooltip(opt, this);
  6655. this.toolTipAt = null;
  6656. }
  6657. }
  6658. } else if (y >= t + 2 * h && y < t + 3 * h) {
  6659. if (this.vqt) {
  6660. var opt = {
  6661. title: this.getLabel() + ' 的实时数据',
  6662. content: this.getVQTTooltip(),
  6663. align: ta,
  6664. skin: 'tooltipTans',
  6665. width: 250,
  6666. x: e.pageX + 10,
  6667. y: ty
  6668. }
  6669. this.rtChart.showTooltip(opt, this);
  6670. this.toolTipAt = "vqt";
  6671. }
  6672. } else if (y >= t + 3 * h && y < t + 4 * h) {
  6673. if (this.avg != null) {
  6674. var opt = {
  6675. title: this.getLabel() + ' 的平均值(中值)',
  6676. content: this.getAVGTooltip(),
  6677. align: ta,
  6678. skin: 'tooltipTans',
  6679. width: 250,
  6680. x: e.pageX + 10,
  6681. y: ty
  6682. }
  6683. this.rtChart.showTooltip(opt, this);
  6684. this.toolTipAt = "avg";
  6685. }
  6686. } else if (y >= t + 4 * h && y < t + 5 * h) {
  6687. if (this.minVqt != null) {
  6688. var opt = {
  6689. title: this.getLabel() + ' 的最小值',
  6690. content: this.getMinVQTTooltip(),
  6691. align: ta,
  6692. skin: 'tooltipTans',
  6693. width: 250,
  6694. height: 90,
  6695. x: e.pageX + 10,
  6696. y: ty
  6697. }
  6698. this.rtChart.showTooltip(opt, this);
  6699. this.toolTipAt = "minVQT";
  6700. this.rtChart.setCursor("pointer");
  6701. return true;
  6702. }
  6703. } else if (y >= t + 5 * h && y < t + 6 * h) {
  6704. if (this.maxVqt != null) {
  6705. var opt = {
  6706. title: this.getLabel() + ' 的最大值',
  6707. content: this.getMaxVQTTooltip(),
  6708. align: ta,
  6709. skin: 'tooltipTans',
  6710. width: 250,
  6711. height: 90,
  6712. x: e.pageX + 10,
  6713. y: ty
  6714. }
  6715. this.rtChart.showTooltip(opt, this);
  6716. this.toolTipAt = "maxVQT";
  6717. this.rtChart.setCursor("pointer");
  6718. return true;
  6719. }
  6720. }
  6721. },
  6722. onClick: function (x, y, e) {
  6723. var w = this.rtChart.getPanWidth();
  6724. var t = SPANPAD;
  6725. var h = SPANLINEHEIGHT;
  6726. if (x > 20 && x < w - 10 && this.requestLogin !== true && !this.bActive) {
  6727. this.rtChart.requestActive(this);
  6728. return;
  6729. }
  6730. if (y >= 0 && y < t + h) {
  6731. if (x < 20) {
  6732. this.rtChart.setPenColor(this, e);
  6733. } else if (x < w - 10) {
  6734. if (this.requestLogin === true) {
  6735. this.rtChart.requestLogin();
  6736. } else {
  6737. if (this.bActive)
  6738. this.rtChart.requestActive(null);
  6739. else
  6740. this.rtChart.requestActive(this);
  6741. }
  6742. } else
  6743. this.rtChart.removePen(this);
  6744. } else if (y >= t + 4 * h && y < t + 5 * h)
  6745. this.posVQT("min");
  6746. else if (y >= t + 5 * h && y < t + 6 * h)
  6747. this.posVQT("max");
  6748. },
  6749. onLinkTab: function (data) {
  6750. if (!data || !data.length || !this.rtChart)
  6751. return;
  6752. var base = data[0].BasePointInfo;
  6753. if (base && base.Unit)
  6754. this.unit = base.Unit;
  6755. if (base && base.Desc)
  6756. this.setDes(base.Desc);
  6757. this.rtRefreshKey = this.rtChart.RegistRtPt(this, this.getURI(), this.onRtRefresh);
  6758. if (!this.rtRefreshKey)
  6759. this.setLinkStatus("error", "实时刷新注册失败!");
  6760. if (!this.rtChart.requestHisData(this))
  6761. this.setHisStatus("error", "历史数据查询请求失败!");
  6762. },
  6763. setRtVQT: function (vqt) {
  6764. if (!this.rtChart)
  6765. return;
  6766. var bReDraw = (this.vqt && !vqt) || (!this.vqt && vqt);
  6767. this.vqt = vqt;
  6768. this.vqtChanged = true;
  6769. if (this.rowId)
  6770. this.rtChart._updateList(this.rowId, "实时值", this.getVQTList());
  6771. this.rtChart.UpdateDataPan(bReDraw);
  6772. if (!this.preventTooltipUpdate && this.showTolltip && this.toolTipAt == "vqt")
  6773. this.rtChart.UpdateTooltip(this.getVQTTooltip());
  6774. },
  6775. getVQTList: function () {
  6776. if (!this.vqt) {
  6777. return {
  6778. title: "尚未获取实时值",
  6779. color: "rgb(160,0,0)",
  6780. value: "[!!尚未获取实时值]"
  6781. };
  6782. } else {
  6783. var vqt = {};
  6784. vqt.title = "质量码:" + this.vqt.getQuaStr() + "\n" + "时间戳:" + this.vqt.getFullStampTimeStr();
  6785. if (this.vqt.isGood())
  6786. vqt.color = "rgb(0,30,0)";
  6787. else if (this.vqt.isUncertain())
  6788. vqt.color = "rgb(100,100,0)";
  6789. else
  6790. vqt.color = "rgb(180,0,0)";
  6791. vqt.value = (this.vqt.isFloat() ? this.vqt.value.toFixed(this.options.Num) : this.vqt.value);
  6792. if (this.unit && this.unit.length) {
  6793. vqt.unit = this.unit;
  6794. }
  6795. vqt.numberVal = this.vqt.GetNumber();
  6796. return vqt;
  6797. }
  6798. },
  6799. getMaxVQTList: function () {
  6800. if (!this.maxVqt) {
  6801. return {
  6802. title: "尚未获得最大值",
  6803. color: "rgb(160,0,0)",
  6804. value: "[!!尚未获得最大值]"
  6805. };
  6806. } else {
  6807. var vqt = {};
  6808. vqt.tip = "max";
  6809. vqt.title = "质量码:" + this.getQuaStr(this.maxVqt) + "\n" + "时间戳:" + this.rtChart.FileTimeToDateString(this.maxVqt.StampTime) + " " + this.rtChart.FileTimeToTimeString(this.maxVqt.StampTime);
  6810. if (this.isGood(this.maxVqt))
  6811. vqt.color = "rgb(0,80,0)";
  6812. else if (this.isUncertain(this.maxVqt))
  6813. vqt.color = "rgb(100,100,0)";
  6814. else
  6815. vqt.color = "rgb(180,0,0)";
  6816. vqt.value = (this.isFloat(this.maxVqt) ? this.maxVqt.Value.toFixed(this.options.Num) : this.maxVqt.Value);
  6817. if (this.unit && this.unit.length) {
  6818. vqt.unit = this.unit;
  6819. }
  6820. return vqt;
  6821. }
  6822. },
  6823. getMinVQTList: function () {
  6824. if (!this.minVqt) {
  6825. return {
  6826. title: "尚未获得最小值",
  6827. color: "rgb(160,0,0)",
  6828. value: "[!!尚未获得最小值]"
  6829. };
  6830. } else {
  6831. var vqt = {};
  6832. vqt.tip = "min";
  6833. vqt.title = "质量码:" + this.getQuaStr(this.minVqt) + "\n" + "时间戳:" + this.rtChart.FileTimeToDateString(this.minVqt.StampTime) + " " + this.rtChart.FileTimeToTimeString(this.minVqt.StampTime);
  6834. if (this.isGood(this.minVqt))
  6835. vqt.color = "rgb(0,80,0)";
  6836. else if (this.isUncertain(this.minVqt))
  6837. vqt.color = "rgb(100,100,0)";
  6838. else
  6839. vqt.color = "rgb(180,0,0)";
  6840. vqt.value = (this.isFloat(this.minVqt) ? this.minVqt.Value.toFixed(this.options.Num) : this.minVqt.Value);
  6841. if (this.unit && this.unit.length) {
  6842. vqt.unit = this.unit;
  6843. }
  6844. return vqt;
  6845. }
  6846. },
  6847. getVQTTooltip: function () {
  6848. if (!this.vqt)
  6849. return null;
  6850. var tip = '<div class="'
  6851. if (this.vqt.isGood())
  6852. tip += 'tooltpgoodval">';
  6853. else
  6854. tip += 'tooltpbadval">';
  6855. tip += '<span class="tooltiplabel">实时值:</span>';
  6856. if (this.vqt.value != null) {
  6857. tip += (this.vqt.isFloat() ? this.vqt.value.toFixed(this.options.Num) : this.vqt.value);
  6858. if (this.unit && this.unit.length) {
  6859. tip += " " + this.unit;
  6860. }
  6861. }
  6862. tip += '</div>';
  6863. if (this.vqt.isGood())
  6864. tip += '<div class="tooltipQGood">';
  6865. else
  6866. tip += '<div class="tooltipQBad">';
  6867. tip += '<span class="tooltiplabel">质量码:</span>';
  6868. tip += this.vqt.getQuaStr();
  6869. tip += '</div>';
  6870. tip += '<div class="tooltipT">';
  6871. tip += '<span class="tooltiplabel">时间戳:</span>';
  6872. tip += this.vqt.getFullStampTimeStr();
  6873. tip += '</div>';
  6874. tip += '</div>';
  6875. return tip;
  6876. },
  6877. getAVGTooltip: function () {
  6878. if (this.avg == null)
  6879. return null;
  6880. var tip = '<div class="tooltpgoodval">'
  6881. tip += '<span class="tooltiplabel">平均值:</span>';
  6882. tip += (Math.floor(this.avg) != this.avg ? this.avg.toFixed(this.options.Num) : this.avg);
  6883. if (this.unit && this.unit.length) {
  6884. tip += " " + this.unit;
  6885. }
  6886. tip += '</div>';
  6887. return tip
  6888. },
  6889. getAVGList: function () {
  6890. var avg = {};
  6891. if (this.avg != null) {
  6892. avg.value = (Math.floor(this.avg) != this.avg ? this.avg.toFixed(this.options.Num) : this.avg);
  6893. if (this.unit && this.unit.length) {
  6894. avg.unit = this.unit;
  6895. }
  6896. }
  6897. return avg;
  6898. },
  6899. getMinVQTTooltip: function () {
  6900. if (!this.minVqt)
  6901. return null;
  6902. var tip = '<div class="'
  6903. if (this.isGood(this.minVqt))
  6904. tip += 'tooltpgoodval">';
  6905. else
  6906. tip += 'tooltpbadval">';
  6907. tip += '<span class="tooltiplabel">最小值:</span>';
  6908. if (this.minVqt.Value != null) {
  6909. tip += (this.isFloat(this.minVqt) ? this.minVqt.Value.toFixed(this.options.Num) : this.minVqt.Value);
  6910. if (this.unit && this.unit.length) {
  6911. tip += " " + this.unit;
  6912. }
  6913. }
  6914. tip += '</div>';
  6915. if (this.isGood(this.minVqt))
  6916. tip += '<div class="tooltipQGood">';
  6917. else
  6918. tip += '<div class="tooltipQBad">';
  6919. tip += '<span class="tooltiplabel">质量码:</span>';
  6920. tip += this.getQuaStr(this.minVqt);
  6921. tip += '</div>';
  6922. tip += '<div class="tooltipT">';
  6923. tip += '<span class="tooltiplabel">时间戳:</span>';
  6924. tip += this.rtChart.FileTimeToDateString(this.minVqt.StampTime) + " " + this.rtChart.FileTimeToTimeString(this.minVqt.StampTime);
  6925. tip += '</div>';
  6926. tip += '<div class="tooltipT">';
  6927. tip += '点击可定位最小值';
  6928. tip += '</div>';
  6929. tip += '</div>';
  6930. return tip;
  6931. },
  6932. getMaxVQTTooltip: function () {
  6933. if (!this.maxVqt)
  6934. return null;
  6935. var tip = '<div class="'
  6936. if (this.isGood(this.maxVqt))
  6937. tip += 'tooltpgoodval">';
  6938. else
  6939. tip += 'tooltpbadval">';
  6940. tip += '<span class="tooltiplabel">最大值:</span>';
  6941. if (this.maxVqt.Value != null) {
  6942. tip += (this.isFloat(this.maxVqt) ? this.maxVqt.Value.toFixed(this.options.Num) : this.maxVqt.Value);
  6943. if (this.unit && this.unit.length) {
  6944. tip += " " + this.unit;
  6945. }
  6946. }
  6947. tip += '</div>';
  6948. if (this.isGood(this.maxVqt))
  6949. tip += '<div class="tooltipQGood">';
  6950. else
  6951. tip += '<div class="tooltipQBad">';
  6952. tip += '<span class="tooltiplabel">质量码:</span>';
  6953. tip += this.getQuaStr(this.maxVqt);
  6954. tip += '</div>';
  6955. tip += '<div class="tooltipT">';
  6956. tip += '<span class="tooltiplabel">时间戳:</span>';
  6957. tip += this.rtChart.FileTimeToDateString(this.maxVqt.StampTime) + " " + this.rtChart.FileTimeToTimeString(this.maxVqt.StampTime);
  6958. tip += '</div>';
  6959. tip += '<div class="tooltipT">';
  6960. tip += '<span class="tooltiplabel">点击可定位最大值</span>';
  6961. tip += '</div>';
  6962. tip += '</div>';
  6963. return tip;
  6964. },
  6965. posVQT: function (tip) {
  6966. switch (tip) {
  6967. case 'max':
  6968. if (this.maxVqt != null)
  6969. this.rtChart.posvIndicator(this.maxVqt.StampTime);
  6970. break;
  6971. case 'min':
  6972. if (this.minVqt != null)
  6973. this.rtChart.posvIndicator(this.minVqt.StampTime);
  6974. break;
  6975. }
  6976. },
  6977. getValueTooltipAtTime: function (ft) {
  6978. var vqt = null;
  6979. var prev = null;
  6980. var next = null;
  6981. if (this.hisData) {
  6982. var len = this.hisData.length;
  6983. for (var i = 0; i < len; i++) {
  6984. var findVQT = this.hisData[i];
  6985. if (findVQT.StampTime == ft) {
  6986. vqt = findVQT;
  6987. break;
  6988. } else if (findVQT.StampTime > ft) {
  6989. if (prev) {
  6990. vqt = prev;
  6991. next = findVQT;
  6992. } else
  6993. vqt = findVQT;
  6994. break;
  6995. } else
  6996. prev = findVQT;
  6997. }
  6998. }
  6999. var tip = '<div class="';
  7000. if (vqt) {
  7001. if (this.isGood(vqt))
  7002. tip += 'tooltpgoodval" ';
  7003. else
  7004. tip += 'tooltpbadval" ';
  7005. tip += 'title="质量码:' + this.getQuaStr(vqt) + '" ';
  7006. tip += 'style="color:';
  7007. tip += this.getPenColor();
  7008. tip += '">';
  7009. } else {
  7010. tip += 'tooltpnoval" ';
  7011. tip += 'style="color:';
  7012. tip += this.getPenColor();
  7013. tip += '">';
  7014. tip += '[!!无历史数据]';
  7015. }
  7016. tip += '<span class="tooltiplabel"';
  7017. tip += 'style="color:';
  7018. tip += this.getPenColor();
  7019. tip += '">';
  7020. tip += this.getLabel();
  7021. tip += '</span>';
  7022. if (vqt) {
  7023. if (vqt.Value != null) {
  7024. if (next && next.StampTime > vqt.StampTime && next.Value != null) {
  7025. if (this.isString(vqt))
  7026. tip += (vqt.Value ? vqt.Value : "");
  7027. else if (this.isBoolen(vqt)) {
  7028. if (vqt.Value)
  7029. tip += "1";
  7030. else
  7031. tip += "0";
  7032. } else {
  7033. var inter = vqt.Value + (next.Value - vqt.Value) * (ft - vqt.StampTime) / (next.StampTime - vqt.StampTime);
  7034. tip += inter.toFixed(this.options.Num);
  7035. }
  7036. } else {
  7037. tip += '<span class="tooltipvalstamp">';
  7038. tip += this.getStampTimeStr(vqt);
  7039. tip += '</span>';
  7040. if (this.isString(vqt))
  7041. tip += (vqt.Value ? vqt.Value : "");
  7042. else if (this.isBoolen(vqt)) {
  7043. if (vqt.Value)
  7044. tip += "1";
  7045. else
  7046. tip += "0";
  7047. } else
  7048. tip += (this.isFloat(vqt) ? vqt.Value.toFixed(this.options.Num) : vqt.Value);
  7049. }
  7050. if (this.unit && this.unit.length)
  7051. tip += " " + this.unit;
  7052. } else {
  7053. tip += '<span class="tooltipvalstamp">';
  7054. tip += this.getStampTimeStr(vqt);
  7055. tip += '</span>';
  7056. tip += '[!!空值]';
  7057. }
  7058. }
  7059. tip += '</div>';
  7060. return tip;
  7061. },
  7062. getValueLine: function (iy) {
  7063. var tip = '<div class="valine">';
  7064. tip += '<span class="tooltiplabel"';
  7065. tip += 'style="color:';
  7066. tip += this.getPenColor();
  7067. tip += '">';
  7068. tip += this.getLabel();
  7069. tip += '</span>';
  7070. var val = this.getVal(iy);
  7071. if (val == null) {
  7072. tip += '</div>';
  7073. return tip;
  7074. }
  7075. val = val.toFixed(this.options.Num)
  7076. tip += val;
  7077. if (this.unit && this.unit.length)
  7078. tip += " " + this.unit;
  7079. tip += '</div>';
  7080. return tip;
  7081. },
  7082. _setListRowId: function (rowId) {
  7083. this.rowId = rowId;
  7084. this.updateListGrid();
  7085. },
  7086. setDisplay: function (drawLine, updateList) {
  7087. if (this.options.drawLine === drawLine)
  7088. return;
  7089. this.options.drawLine = drawLine;
  7090. if (!this.options.drawLine) {
  7091. if (this.rtChart.activePen == this)
  7092. this.rtChart.requestActive(null);
  7093. }
  7094. if (updateList !== false)
  7095. this.rtChart._updateList(this.rowId, "显示", this.options.drawLine);
  7096. this.rtChart.updateDataArea();
  7097. this.rtChart.UpdateAxisPan(true);
  7098. },
  7099. setStepLine: function (stepline, updateList, force) {
  7100. if (this.options.stepLine === stepline)
  7101. return;
  7102. if (!force && stepline === false) {
  7103. var type = null;
  7104. if ((this.minVqt && this.isString(this.minVqt)) || (this.maxVqt && this.isString(this.maxVqt))) {
  7105. type = "字符串";
  7106. } else if ((this.minVqt && this.isBoolen(this.minVqt)) || (this.maxVqt && this.isBoolen(this.maxVqt))) {
  7107. type = "开关量";
  7108. }
  7109. if (type != null) {
  7110. var pen = this;
  7111. var d = dialog({
  7112. title: '设置阶跃绘制',
  7113. content: '点:' + this.getLabel() + " 的数据类型为:" + type + ",<br>不适合采用非阶跃的方式绘制趋势线,是否仍改变趋势线绘制方式?",
  7114. okValue: '确定',
  7115. ok: function () {
  7116. pen.setStepLine(stepline, updateList, true);
  7117. pen = null;
  7118. return true;
  7119. },
  7120. cancelValue: '取消',
  7121. cancel: function () {
  7122. pen.rtChart._updateList(pen.rowId, "阶跃", pen.options.stepLine == null ? false : pen.options.stepLine);
  7123. }
  7124. });
  7125. d.showModal();
  7126. return;
  7127. }
  7128. }
  7129. this.options.stepLine = stepline;
  7130. if (updateList !== false)
  7131. this.rtChart._updateList(this.rowId, "阶跃", this.options.stepLine == null ? false : this.options.stepLine);
  7132. this.rtChart.updateDataArea();
  7133. },
  7134. setDrawTag: function (drawTag, updateList) {
  7135. if (this.options.drawTag === drawTag)
  7136. return;
  7137. this.options.drawTag = drawTag;
  7138. if (updateList !== false)
  7139. this.rtChart._updateList(this.rowId, "标记", this.options.drawTag);
  7140. this.rtChart.updateDataArea();
  7141. },
  7142. setInterpolate: function (inter, updateList) {
  7143. if (this.options.interpolate === inter)
  7144. return;
  7145. if (inter) {
  7146. var type = null;
  7147. if ((this.minVqt && this.isString(this.minVqt)) || (this.maxVqt && this.isString(this.maxVqt))) {
  7148. type = "字符串";
  7149. } else if ((this.minVqt && this.isBoolen(this.minVqt)) || (this.maxVqt && this.isBoolen(this.maxVqt))) {
  7150. type = "开关量";
  7151. }
  7152. if (type != null) {
  7153. var pen = this;
  7154. var d = dialog({
  7155. title: '插值显示设置',
  7156. content: '点:' + this.getLabel() + " 的数据类型为:" + type + ",<br>不适合采用插值显示方式?"
  7157. });
  7158. d.show();
  7159. this.rtChart._updateList(pen.rowId, "插值", false);
  7160. window.setTimeout(function () {
  7161. d.close().remove();
  7162. d = null;
  7163. }, 2000);
  7164. return;
  7165. }
  7166. }
  7167. this.options.interpolate = inter;
  7168. if (updateList !== false)
  7169. this.rtChart._updateList(this.rowId, "插值", this.options.interpolate);
  7170. this.updateDataReader();
  7171. this.rtChart._updatevIndicatorTooltip();
  7172. },
  7173. updateListGrid: function () {
  7174. if (!this.rowId)
  7175. return;
  7176. this.rtChart._updateList(this.rowId, "点名称", {
  7177. uri: this.getURI(),
  7178. color: this.getPenColor()
  7179. });
  7180. this.rtChart._updateList(this.rowId, "线宽", this.options.penWidth);
  7181. this.rtChart._updateList(this.rowId, "显示", this.options.drawLine);
  7182. this.rtChart._updateList(this.rowId, "阶跃", this.options.stepLine == null ? false : this.options.stepLine);
  7183. this.rtChart._updateList(this.rowId, "标记", this.options.drawTag);
  7184. this.rtChart._updateList(this.rowId, "插值", this.options.interpolate);
  7185. this.rtChart._updateList(this.rowId, "描述", this.getDes());
  7186. this.rtChart._updateList(this.rowId, "实时值", this.getVQTList());
  7187. this.rtChart._updateList(this.rowId, "最大值", this.getMaxVQTList());
  7188. this.rtChart._updateList(this.rowId, "最小值", this.getMinVQTList());
  7189. this.rtChart._updateList(this.rowId, "平均值", this.getAVGList());
  7190. this.rtChart._updateList(this.rowId, "量程锁定", this.options.lockRange);
  7191. this.updateRangeList();
  7192. this.updateDataReader();
  7193. },
  7194. onRtRefresh: function (status, data, opt) {
  7195. switch (status) {
  7196. case "getting":
  7197. this.setLinkStatus("linking", "正在获取实时数据...");
  7198. break;
  7199. case "error":
  7200. this.setLinkStatus("error", "获取实时数据失败" + ((data && data.length) ? ("\n" + data) : ""));
  7201. if (this.vqt && this.vqt.isGood()) {
  7202. this.vqt.qua = 0x14;
  7203. this.vqt.errMess = data;
  7204. this.setRtVQT(this.vqt);
  7205. }
  7206. break;
  7207. case "success":
  7208. this.setLinkStatus("linked", "已成功获取实时数据");
  7209. this.setRtVQT(data);
  7210. break;
  7211. }
  7212. },
  7213. refreshHisData: function (bClearData) {
  7214. if (bClearData === true)
  7215. delete this.hisData;
  7216. else if (this.hisData) {
  7217. var begTime = this.rtChart.getBegTime();
  7218. var endTime = this.rtChart.getEndTime();
  7219. if (this.getBegTime() <= begTime && this.getEndTime() >= endTime)
  7220. return;
  7221. else if (!((this.getBegTime() <= begTime && this.getEndTime() <= endTime) ||
  7222. (this.getBegTime() >= begTime && this.getEndTime() >= endTime)))
  7223. delete this.hisData;
  7224. }
  7225. this.setHisStatus("wait", "正在等待查询启动");
  7226. if (!this.rtChart.requestHisData(this))
  7227. this.setHisStatus("error", "历史数据查询请求失败!");
  7228. },
  7229. getBegTime: function () {
  7230. if (this.hisData && this.hisData.length)
  7231. return this.hisData[0].StampTime;
  7232. else
  7233. return null;
  7234. },
  7235. getEndTime: function () {
  7236. if (this.hisData && this.hisData.length)
  7237. return this.hisData[this.hisData.length - 1].StampTime;
  7238. else
  7239. return null;
  7240. },
  7241. isHisRq: function () {
  7242. if (!this.rtChart)
  7243. return false;
  7244. else if (this.options.itemDef != null && this.options.itemDef.entityId != null && this.options.itemDef.propId != null)
  7245. return true;
  7246. else if (this.hisGetStaus == null)
  7247. return true;
  7248. else if (this.hisGetStaus == 'wait')
  7249. return true;
  7250. else if (this.hisGetStaus == 'error') {
  7251. if (this.hisTime && (new Date() - this.hisTime > this.options.hisReTryTime))
  7252. return true;
  7253. else
  7254. return false;
  7255. } else if (this.hisGetStaus != 'getting') {
  7256. if (this.rtChart.getHisRefreshing())
  7257. return true;
  7258. else if (this.hisGetStaus == 'nodata')
  7259. return false;
  7260. else if (!this.getEndTime())
  7261. return true;
  7262. else if (this.getEndTime() < this.rtChart.getEndTime())
  7263. return true;
  7264. else
  7265. return false;
  7266. } else {
  7267. if (this.linkTime && new Date() - this.hisTime > this.options.hisReTryTime)
  7268. return true;
  7269. else
  7270. return false;
  7271. }
  7272. },
  7273. getHisRequestTab: function () {
  7274. var tab = new GoldenRtWeb.Tab();
  7275. tab.resultCode = 'S_RTREFRESHHISDATA';
  7276. if (this.options.itemDef == null)
  7277. this.options.itemDef = {};
  7278. this.options.itemDef.dataMethod = 'HDBAGGREG_MAXMINMUM';
  7279. var gw = this.rtChart.getGridWidth();
  7280. var begTime = this.rtChart.getBegTime();
  7281. var endTime = this.rtChart.getEndTime();
  7282. if (this.rtChart.getHisRefreshing()) {
  7283. if (this.getEndTime() != null && this.getEndTime() > begTime) {
  7284. this.options.itemDef.beginTime = this.getEndTime();
  7285. this.options.itemDef.endTime = null;
  7286. } else {
  7287. this.options.itemDef.beginTime = begTime;
  7288. this.options.itemDef.endTime = null;
  7289. }
  7290. this.options.itemDef.slotTime = gw;
  7291. } else if (this.getBegTime() != null && this.getBegTime() <= begTime && this.getEndTime() != null && this.getEndTime() <= endTime) {
  7292. this.options.itemDef.beginTime = this.getEndTime();
  7293. this.options.itemDef.endTime = endTime;
  7294. this.options.itemDef.slotTime = gw * (this.options.itemDef.endTime - this.options.itemDef.beginTime) / this.rtChart.getTimeSpan();
  7295. } else if (this.getBegTime() >= begTime && this.getEndTime() >= endTime) {
  7296. this.options.itemDef.beginTime = begTime;
  7297. this.options.itemDef.endTime = this.getBegTime();
  7298. this.options.itemDef.slotTime = gw * (this.options.itemDef.endTime - this.options.itemDef.beginTime) / this.rtChart.getTimeSpan();
  7299. } else {
  7300. this.options.itemDef.beginTime = begTime;
  7301. this.options.itemDef.endTime = endTime;
  7302. this.options.itemDef.slotTime = gw;
  7303. }
  7304. /*Modify*/
  7305. if (this.vqt) {
  7306. if (this.options.itemDef.beginTime > this.vqt.StampTime)
  7307. this.options.itemDef.beginTime = this.vqt.StampTime;
  7308. if (this.options.itemDef.endTime > this.vqt.StampTime)
  7309. this.optionsitemDef.endTime = 0;
  7310. }
  7311. //this.itemDef.slotTime = this.rtChart.getTimeSlot();
  7312. //if (this.itemDef.slotTime < PERHOUR && this.rtChart.getTimeSpan() > 120 * PERHOUR)
  7313. // this.itemDef.slotTime = PERHOUR;
  7314. var col = new GoldenRtWeb.Col();
  7315. col.key = "hisdata";
  7316. col.value = this.itemDef;
  7317. var row = new GoldenRtWeb.Row();
  7318. row.addCol(col);
  7319. tab.addRow(row);
  7320. tab.hisRequestSeed = ++this.hisRequestSeed;
  7321. return tab;
  7322. },
  7323. onHisTab: function (tab) {
  7324. // debugger;
  7325. if (!this.rtChart)
  7326. return;
  7327. var err = null;
  7328. if (tab.hisRequestSeed == this.hisRequestSeed) {
  7329. var newData = tab.hisData;
  7330. var lastVQT = newData[newData.length - 1];
  7331. if (lastVQT.StampTime < this.rtChart.getBegTime()) {
  7332. this.setHisStatus("nodata", "查询不到有效的历史数据");
  7333. return;
  7334. }
  7335. this.newHisData = newData;
  7336. this.setHisStatus("linked");
  7337. if (this.rtChart.getHisRefreshing())
  7338. this.rtChart._setNewLastTime(lastVQT.StampTime);
  7339. this.rtChart._setNewLastTime(lastVQT.StampTime);
  7340. this.rtChart._onNewHisData();
  7341. } else if (tab.isErr()) {
  7342. err = "信息服务返回错误,错误码是:" + tab.resultCode + "<br/>" + "错误信息是:" + tab.errMess + "<br/>" + "错误源是:" + tab.errorSource;
  7343. this.setHisStatus("error", err);
  7344. }
  7345. },
  7346. prepareHisData: function (begTime, endTime) {
  7347. if (this.hisData && this.hisData.length) {
  7348. var i = 0;
  7349. var len = this.hisData.length;
  7350. for (; i < len; i++) {
  7351. if (this.hisData[i].StampTime >= begTime)
  7352. break;
  7353. }
  7354. var prev = this.rtChart.options.reservePrevData || 1;
  7355. if (i >= prev)
  7356. this.hisDatRemove(this.hisData, 0, (i - prev));
  7357. }
  7358. var dataChanged = false;
  7359. if (this.newHisData && this.newHisData.length) {
  7360. if (this.hisData && this.hisData.length > 0) {
  7361. var firstTime = this.newHisData[0].StampTime;
  7362. var lastTime = this.newHisData[this.newHisData.length - 1].StampTime;
  7363. if (lastTime <= this.getBegTime()) {
  7364. if (lastTime == this.getBegTime())
  7365. this.hisDatRemove(this.hisData, 0);
  7366. dataChanged = true;
  7367. this.hisData = this.newHisData.concat(this.hisData);
  7368. } else if (firstTime < this.getBegTime() && lastTime <= this.getEndTime()) {
  7369. var i = 0;
  7370. for (; i < this.hisData.length; i++) {
  7371. if (this.hisData[i].StampTime > lastTime)
  7372. break;
  7373. }
  7374. if (i > 0)
  7375. this.hisDatRemove(this.hisData, 0, i - 1);
  7376. dataChanged = true;
  7377. this.hisData = this.newHisData.concat(this.hisData);
  7378. } else if (firstTime >= this.getBegTime() && lastTime > this.getEndTime()) {
  7379. var i = 0;
  7380. var len = this.hisData.length;
  7381. for (; i < len; i++) {
  7382. if (this.hisData[i].StampTime >= firstTime)
  7383. break;
  7384. }
  7385. if (i < this.hisData.length)
  7386. this.hisDatRemove(this.hisData, i, this.hisData.length - 1);
  7387. dataChanged = true;
  7388. this.hisData = this.hisData.concat(this.newHisData);
  7389. } else if (firstTime >= this.getEndTime()) {
  7390. if (firstTime == this.getEndTime())
  7391. this.hisDatRemove(this.hisData, -1);
  7392. dataChanged = true;
  7393. this.hisData = this.hisData.concat(this.newHisData);
  7394. }
  7395. } else {
  7396. dataChanged = true;
  7397. this.hisData = this.newHisData;
  7398. }
  7399. delete this.newHisData;
  7400. }
  7401. if (dataChanged || this.lastBegTime != begTime || this.lastEndTime != endTime) {
  7402. this.lastBegTime = begTime;
  7403. this.lastEndTime = endTime;
  7404. var minVqt = null;
  7405. var maxVqt = null;
  7406. var goodCount = 0;
  7407. var badCount = 0;
  7408. var unCertain = 0;
  7409. var sum = 0.0;
  7410. var det = 0.0;
  7411. var avg;
  7412. var prevVQT;
  7413. var min = this.rageMin;
  7414. var max = this.rageMax;
  7415. if (this.hisData) {
  7416. var len = this.hisData.length;
  7417. for (var i = 0; i < len; i++) {
  7418. var vqt = this.hisData[i];
  7419. if (vqt.StampTime >= begTime &&
  7420. vqt.StampTime <= endTime) {
  7421. if (this.isGood(vqt))
  7422. goodCount++;
  7423. else if (this.isBad(vqt))
  7424. badCount++;
  7425. else
  7426. unCertain++;
  7427. if (vqt.Value != null) {
  7428. var val = this.GetNumber(vqt);
  7429. if (minVqt == null || val < this.GetNumber(minVqt))
  7430. minVqt = vqt;
  7431. if (maxVqt == null || val > this.GetNumber(maxVqt))
  7432. maxVqt = vqt;
  7433. if (prevVQT && prevVQT.Value != null) {
  7434. var dt = (vqt.StampTime - prevVQT.StampTime);
  7435. sum += 0.5 * (val + this.GetNumber(prevVQT)) * dt;
  7436. det += dt;
  7437. }
  7438. }
  7439. prevVQT = vqt;
  7440. } else if (vqt.StampTime < begTime)
  7441. prevVQT = vqt;
  7442. }
  7443. }
  7444. if (det != 0.0)
  7445. avg = sum / det;
  7446. else
  7447. avg = null;
  7448. var fix = false;
  7449. var bIsBoolen = false;
  7450. if (minVqt) {
  7451. if (this.isString(minVqt) || this.isBoolen(minVqt)) {
  7452. if (this.options.stepLine == null)
  7453. this.setStepLine(true, true);
  7454. }
  7455. if (isNaN(min)) {
  7456. if (this.isBoolen(maxVqt))
  7457. min = -1;
  7458. else
  7459. min = this.GetNumber(minVqt);
  7460. } else if (!this.options.lockRange && (this.commAxis == null || this.commAxis.length == 0)) {
  7461. if (min > this.GetNumber(minVqt)) {
  7462. min = this.GetNumber(minVqt);
  7463. fix = true;
  7464. }
  7465. }
  7466. }
  7467. if (maxVqt) {
  7468. if (this.isString(maxVqt) || this.isBoolen(maxVqt)) {
  7469. if (this.options.stepLine == null)
  7470. this.setStepLine(true, true);
  7471. }
  7472. if (isNaN(max)) {
  7473. if (this.isBoolen(maxVqt))
  7474. max = 5;
  7475. else
  7476. max = this.GetNumber(maxVqt);
  7477. } else if (!this.options.lockRange && (this.commAxis == null || this.commAxis.length == 0)) {
  7478. if (max < this.GetNumber(maxVqt)) {
  7479. max = this.GetNumber(maxVqt);
  7480. fix = true;
  7481. }
  7482. }
  7483. }
  7484. /*
  7485. if (isNaN(min)) {
  7486. if (!isNaN(max)) {
  7487. if (maxVqt && this.isBoolen(maxVqt))
  7488. min = max - 4;
  7489. else
  7490. min = max - 0.1 * Math.abs(max);
  7491. } else
  7492. min = 0;
  7493. }
  7494. if (isNaN(max)) {
  7495. if (!isNaN(min)) {
  7496. if (minVqt && this.isBoolen(minVqt))
  7497. max = min + 4;
  7498. else
  7499. max = min + 0.1 * Math.abs(min);
  7500. } else
  7501. max = 1;
  7502. }
  7503. if (min == max) {
  7504. if ((minVqt && this.isBoolen(minVqt)) || (maxVqt && this.isBoolen(maxVqt))) {
  7505. min--;
  7506. max++;
  7507. } else
  7508. max = min + 0.1 * Math.abs(min);
  7509. }*/
  7510. /*Modify*/
  7511. /*if (this.rageMin == null || this.rageMax == null || fix) {
  7512. if ((minVqt && this.isBoolen(minVqt)) || (maxVqt && this.isBoolen(maxVqt))) {
  7513. if (fix) {
  7514. min = -1;
  7515. max = 5;
  7516. }
  7517. } else {
  7518. min -= 0.2 * Math.abs(max - min);
  7519. var saveMax = max;
  7520. max += 20 * Math.abs(max - min);
  7521. if (max > 2000.0)
  7522. max = saveMax + 0.2 * Math.abs(saveMax - min);
  7523. }
  7524. }
  7525. this.setRange(min, max);
  7526. */
  7527. // 自由量程
  7528. min = this.GetNumber(minVqt);
  7529. max = this.GetNumber(maxVqt);
  7530. (function () {
  7531. var diff = Math.abs(max - min);
  7532. if (diff === 0 && avg !== 0) {
  7533. diff = avg * 0.2;
  7534. } else if (diff === 0 && avg === 0) {
  7535. diff = 250;
  7536. }
  7537. min = min - diff * 0.2;
  7538. max = max + diff * 0.2;
  7539. })();
  7540. // 自由量程
  7541. if (this.rtChart && this.rtChart.options && this.rtChart.options.freeRange) {
  7542. this.setRange(min, max);
  7543. } else { // 固定量程
  7544. min = this.rageMin || 0;
  7545. max = this.rageMax || 1000;
  7546. this.setRange(this.rageMin, this.rageMax);
  7547. }
  7548. if (this.avg != avg) {
  7549. this.avgChanged = true;
  7550. this.rtChart.UpdateDataPan((this.avg == null || avg == null) ? true : false);
  7551. this.avg = avg;
  7552. this.rtChart._updateList(this.rowId, "平均值", this.getAVGList());
  7553. if (!this.preventTooltipUpdate && this.showTolltip && this.toolTipAt == "avg" && !(this.requestLogin === true))
  7554. this.rtChart.UpdateTooltip(this.getAVGTooltip());
  7555. }
  7556. if (this.minVqt != minVqt) {
  7557. this.minChanged = true;
  7558. this.rtChart.UpdateDataPan((this.minVqt == null || minVqt == null) ? true : false);
  7559. this.minVqt = minVqt;
  7560. if (!this.preventTooltipUpdate && this.showTolltip && this.toolTipAt == "minVQT" && !(this.requestLogin === true))
  7561. this.rtChart.UpdateTooltip(this.getMinVQTTooltip());
  7562. this.rtChart._updateList(this.rowId, "最小值", this.getMinVQTList());
  7563. }
  7564. if (this.maxVqt != maxVqt) {
  7565. this.maxChanged = true;
  7566. this.rtChart.UpdateDataPan((this.maxVqt == null || maxVqt == null) ? true : false);
  7567. this.maxVqt = maxVqt;
  7568. if (!this.preventTooltipUpdate && this.showTolltip && this.toolTipAt == "maxVQT" && !(this.requestLogin === true))
  7569. this.rtChart.UpdateTooltip(this.getMaxVQTTooltip());
  7570. this.rtChart._updateList(this.rowId, "最大值", this.getMaxVQTList());
  7571. }
  7572. if (this.maxVqt == null && this.minVqt == null)
  7573. this.setHisStatus("nodata", "查询不到有效的历史数据");
  7574. this.updateDataReader();
  7575. }
  7576. },
  7577. drawTrendLine: function (ctx, begTime, endTime, gw, gh, timeScale, shadowOffset) {
  7578. if (!this.hisData || !this.hisData.length || !this.options.drawLine || this.rageMax == null || this.rageMin == null || this.rageMin == this.rageMax)
  7579. return;
  7580. var bStep = this.options.stepLine === true;
  7581. if (bStep)
  7582. ctx.lineJoin = 'miter';
  7583. else
  7584. ctx.lineJoin = 'round';
  7585. if (shadowOffset == null)
  7586. shadowOffset = 0;
  7587. ctx.beginPath();
  7588. if (!shadowOffset) {
  7589. ctx.lineWidth = (this.options.penWidth || 1);
  7590. ctx.strokeStyle = this.options.penColor;
  7591. } else
  7592. ctx.lineWidth = (this.options.penWidth || 1) + 3;
  7593. var yScale = -gh / (this.rageMax - this.rageMin);
  7594. var yBase = gh;
  7595. var bPrev = false;
  7596. var x, y, px, py;
  7597. var len = this.hisData.length;
  7598. for (var i = 0; i < len; i++) {
  7599. var vqt = this.hisData[i];
  7600. if (vqt != null && vqt.Value != null) {
  7601. x = Math.floor((vqt.StampTime - begTime) * timeScale);
  7602. py = y;
  7603. y = Math.floor(yBase + (this.GetNumber(vqt) - this.rageMin) * yScale) + shadowOffset;
  7604. if (bPrev) {
  7605. if (!bStep)
  7606. ctx.lineTo(x, y);
  7607. else {
  7608. ctx.lineTo(x + shadowOffset / 2, py);
  7609. ctx.lineTo(x + shadowOffset / 2, y);
  7610. }
  7611. } else
  7612. ctx.moveTo(x, y);
  7613. if (this.options.drawTag) {
  7614. ctx.arc(x, y, 4, 0, 2 * Math.PI, false);
  7615. ctx.moveTo(x - 4, y);
  7616. ctx.lineTo(x + 4, y);
  7617. ctx.moveTo(x, y - 4);
  7618. ctx.lineTo(x, y + 4);
  7619. ctx.moveTo(x, y);
  7620. }
  7621. bPrev = true;
  7622. } else {
  7623. if (this.options.drawTag) {
  7624. x = Math.floor((vqt.StampTime - begTime) * timeScale);
  7625. y = Math.floor(yBase + 0, 5 * (this.rageMax - this.rageMin) * yScale) + shadowOffset;
  7626. ctx.moveTo(x - 4, y - 4);
  7627. ctx.lineTo(x + 4, y + 4);
  7628. ctx.moveTo(x - 4, y + 4);
  7629. ctx.lineTo(x + 4, y - 4);
  7630. ctx.arc(x, y, 6, 0, 2 * Math.PI, false);
  7631. ctx.moveTo(x, y);
  7632. }
  7633. bPrev = false;
  7634. }
  7635. if (vqt.StampTime > endTime)
  7636. break;
  7637. }
  7638. ctx.stroke();
  7639. },
  7640. drawThumbsTrendLine: function (ctx, begTime, endTime, gh, gt, h, timeScale) {
  7641. if (!this.hisData || !this.hisData.length || !this.options.drawLine || this.rageMax == null || this.rageMin == null || this.rageMin == this.rageMax)
  7642. return;
  7643. ctx.strokeStyle = this.options.penColor;
  7644. var bStep = this.options.stepLine === true;
  7645. if (bStep)
  7646. ctx.lineJoin = 'miter';
  7647. else
  7648. ctx.lineJoin = 'round';
  7649. ctx.beginPath();
  7650. var scale = h / gh;
  7651. var yScale = -gh * scale / (this.rageMax - this.rageMin);
  7652. var yBase = gt + h;
  7653. var bPrev = false;
  7654. var x, y, py;
  7655. var len = this.hisData.length;
  7656. for (var i = 0; i < len; i++) {
  7657. var vqt = this.hisData[i];
  7658. if (vqt != null && vqt.value != null) {
  7659. x = Math.floor((vqt.StampTime - begTime) * timeScale);
  7660. py = y;
  7661. y = Math.floor(yBase + (this.GetNumber(vqt) - this.rageMin) * yScale);
  7662. if (bPrev) {
  7663. if (!bStep)
  7664. ctx.lineTo(x, y);
  7665. else {
  7666. ctx.lineTo(x, py);
  7667. ctx.lineTo(x, y);
  7668. }
  7669. } else
  7670. ctx.moveTo(x, y);
  7671. bPrev = true;
  7672. } else
  7673. bPrev = false;
  7674. }
  7675. ctx.stroke();
  7676. }
  7677. };
  7678. TrendColor.prototype = {
  7679. scale: function (rf, gf, bf, af) {
  7680. var x = 4;
  7681. while (-1 < --x) {
  7682. if (!(arguments[x] === void 0)) this[this.rgba[x]] *= arguments[x];
  7683. }
  7684. return this.normalize();
  7685. },
  7686. alpha: function (alpha) {
  7687. if (!(alpha === void 0) && !(alpha === null)) {
  7688. this.a = alpha;
  7689. }
  7690. return this.normalize();
  7691. },
  7692. clone: function () {
  7693. return new TrendColor(this.r, this.b, this.g, this.a);
  7694. },
  7695. limit: function (val, minVal, maxVal) {
  7696. return Math.max(Math.min(val, maxVal), minVal);
  7697. },
  7698. normalize: function () {
  7699. var limit = this.limit;
  7700. this.r = limit(parseInt(this.r, 10), 0, 255);
  7701. this.g = limit(parseInt(this.g, 10), 0, 255);
  7702. this.b = limit(parseInt(this.b, 10), 0, 255);
  7703. this.a = limit(this.a, 0, 1);
  7704. return this;
  7705. },
  7706. distance: function (color) {
  7707. if (!color) return;
  7708. color = new TrendColor.parse(color);
  7709. var dist = 0,
  7710. x = 3;
  7711. while (-1 < --x) {
  7712. dist += Math.abs(this[this.rgba[x]] - color[this.rgba[x]]);
  7713. }
  7714. return dist;
  7715. },
  7716. toString: function () {
  7717. return (this.a >= 1.0) ? 'rgb(' + [this.r, this.g, this.b].join(',') + ')' : 'rgba(' + [this.r, this.g, this.b, this.a].join(',') + ')';
  7718. },
  7719. toRGBAString: function () {
  7720. return 'rgba(' + [this.r, this.g, this.b, this.a].join(',') + ')';
  7721. },
  7722. contrast: function () {
  7723. var
  7724. test = 1 - (0.299 * this.r + 0.587 * this.g + 0.114 * this.b) / 255;
  7725. return (test < 0.5 ? '#000000' : '#ffffff');
  7726. }
  7727. };
  7728. })(jQuery);