trendChart.js 351 KB

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