rtinfo.trendChart.js 368 KB

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