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