12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232 |
- $(function () {
- "use strict";
- BWA.Chart = BWA.Chart || {};
- BWA.Chart.getLastYearSameWeekDate = function (dateStart, dateEnd, weekday) {
- var data = {
- startDate: dateStart,
- endDate: dateEnd
- };
- for (var i = 0; i < 7; i++) {
- if (moment(data.startDate).toDate().getDay() == weekday)
- return data;
- data.startDate = moment(data.startDate).subtract(-1, 'days');
- data.endDate = moment(data.endDate).subtract(-1, 'days');
- }
- return data;
- }
- BWA.Chart.getCustermTimeArgumentAxisString = function (codeTimeType, date) { // $Code.TimeType
- switch (codeTimeType) {
- case $Code.TimeType.QUARTERMIN:
- var year = date.getFullYear();
- var mon = (date.getMonth() + 1);
- var day = date.getDate();
- var hour = date.getHours()
- var min = date.getMinutes();
- if (mon < 10)
- mon = "0" + mon;
- if (day < 10)
- day = "0" + day;
- if (hour < 10)
- hour = "0" + hour;
- if (min < 10)
- min = "0" + min;
- return year + "-" + mon + "-" + day + " " + hour + ":" + min;
- break;
- case $Code.TimeType.NONE:
- var year = date.getFullYear();
- var mon = (date.getMonth() + 1);
- var day = date.getDate();
- if (mon < 10)
- mon = "0" + mon;
- if (day < 10)
- day = "0" + day;
- return year + "-" + mon + "-" + day;
- break;
- case $Code.TimeType.HOUR:
- return date.getDate() + "일 : " + date.getHours() + "시";
- break;
- case $Code.TimeType.DAY:
- return date.getMonth() + 1 + "월 : " + date.getDate() + "일";
- break;
- case $Code.TimeType.MONTH:
- return date.getFullYear() + "년 : " + (date.getMonth() + 1) + "월";
- break;
- }
- return date.toLocaleDateString('ja-JP');
- };
- BWA.Chart.getTimeLineArgumentAxis = function (momentDateTime, codeTimeType, MS, ME) { // $Code.TimeType
- var argumentAxis = null;
- var dateType = '';
- switch (codeTimeType) {
- case $Code.TimeType.MIN:
- dateType = 'day';
- argumentAxis = {
- argumentType: 'datetime',
- title: $G('hour'),
- label: {
- alignment: 'center',
- format: 'HH'
- },
- tickInterval: { hours: 1 },
- };
- break;
- case $Code.TimeType.QUARTERMIN:
- dateType = 'day';
- argumentAxis = {
- argumentType: 'datetime',
- title: $G('hour'),
- label: {
- alignment: 'center',
- format: 'HH'
- },
- tickInterval: { hours: 1 },
- };
- break;
- case $Code.TimeType.HOUR:
- dateType = 'day';
- argumentAxis = {
- argumentType: 'string',
- title: $G('hour'),
- label: {
- alignment: 'center',
- format: 'HH:mm'
- },
- tickInterval: { hours: 1 },
- };
- if (!_.isNull(MS) && !_.isNull(ME)) {
- argumentAxis.min = moment(MS).add(-1, 'hours').toDate();
- argumentAxis.max = moment(ME).add(1, 'hours').toDate();
- }
- break;
- case $Code.TimeType.DAY:
- dateType = 'month';
- argumentAxis = {
- argumentType: 'string',
- title: $G('day'),
- label: {
- alignment: 'center',
- format: 'MM-dd'
- },
- tickInterval: { days: 1 },
- };
- if (!_.isNull(MS) && !_.isNull(ME)) {
- argumentAxis.min = moment(MS).add(-1, 'days').toDate();
- argumentAxis.max = moment(ME).add(1, 'days').toDate();
- }
- break;
- case $Code.TimeType.MONTH:
- dateType = 'year';
- argumentAxis = {
- argumentType: 'string',
- title: $G('month'),
- label: {
- alignment: 'center',
- format: 'MM'
- },
- tickInterval: { months: 1 },
- };
- if (!_.isNull(MS) && !_.isNull(ME)) {
- argumentAxis.min = moment(MS).add(-1, 'months').toDate();
- argumentAxis.max = moment(ME).add(1, 'months').toDate();
- }
- break;
- }
- if (!_.isNull(momentDateTime)) {
- argumentAxis.min = moment(momentDateTime.startOf(dateType).toDate()).add(-1, 'hours').toDate();
- argumentAxis.max = moment(momentDateTime.endOf(dateType).toDate()).add(1, 'hours').toDate();
- }
- argumentAxis.valueMarginsEnabled = false;
- return argumentAxis;
- };
- BWA.Chart.mapWithConvertingDateTime = function (array, timetype) {
- return _.map(array, function (x) {
- if (timetype)
- if (!_.isNull(timetype))
- x.DateTime = BWA.Chart.getCustermTimeArgumentAxisString(timetype, moment(x.DateTime).toDate());
- else
- x.DateTime = moment(x.DateTime).toDate();
- return x;
- });
- };
- BWA.Chart.mapNewWithConvertingDateTime = function (array, timetype) {
- return _.map(array, function (x) {
- return {
- DateTime: (!_.isNull(timetype)) ? BWA.Chart.getCustermTimeArgumentAxisString(timetype, moment(x.DateTime).toDate()) : moment(x.DateTime).toDate(),
- Value: x.Value
- };
- return x;
- });
- };
- BWA.Chart.getRelationDataArrayOnDateTime = function (dataArray1, dataArray2, fieldName1, fieldName2) {
- var dataArray = [];
- var minLength = Math.min(dataArray1.length, dataArray2.length)
- var index1 = 0;
- var index2 = 0;
- for (var i = 0 ; i < minLength ; i++) {
- var l = dataArray1[index1];
- var r = dataArray2[index2];
- if (l.DateTime === r.DateTime) {
- var obj = {};
- obj[fieldName1] = l.Value;
- obj[fieldName2] = r.Value;
- dataArray.push(obj);
- index1++;
- index2++;
- }
- else if (l.DateTime > r.DateTime) {
- index2++;
- }
- else if (l.DateTime < r.DateTime) {
- index1++;
- }
- }
- return dataArray;
- }
- // hcLee 2015 04 23
- BWA.Chart.getRelationDataArrayOnDateTime2 = function (dataArray1, dataArray2, dataArray3, fieldName1, fieldName2, fieldName3) {
- var dataArray = [];
- var minLength = Math.min(dataArray1.length, dataArray2.length);
- minLength = Math.min(minLength, dataArray3.length);
- var index1 = 0;
- var index2 = 0;
- var index3 = 0;
- for (var i = 0 ; i < minLength ; i++) {
- var l = dataArray1[index1];
- var r = dataArray2[index2];
- var m = dataArray3[index3];
- if (l.DateTime === r.DateTime) {
- var obj = {};
- obj[fieldName1] = l.Value;
- obj[fieldName2] = r.Value;
- dataArray.push(obj);
- index1++;
- index2++;
- }
- else if (l.DateTime > r.DateTime) {
- index2++;
- }
- else if (l.DateTime < r.DateTime) {
- index1++;
- }
- }
- return dataArray;
- }
- // hcLee 2018 02 27
- BWA.Chart.getRelationDataArrayOnDateTimeNew = function (dataArray1, dataArray2, fieldName1, fieldName2) {
- var dataArray = [];
- var minLength = Math.min(dataArray1.length, dataArray2.length)
- var index1 = 0;
- var index2 = 0;
- for (var i = 0 ; i < minLength ; i++) {
- var l = dataArray1[index1];
- var r = dataArray2[index2];
- if (l.DateTime === r.DateTime) {
- var obj = {};
- obj[fieldName1] = l.lv1;
- obj[fieldName2] = r.rv1;
- dataArray.push(obj);
- index1++;
- index2++;
- }
- else if (l.DateTime > r.DateTime) {
- index2++;
- }
- else if (l.DateTime < r.DateTime) {
- index1++;
- }
- }
- return dataArray;
- }
- BWA.Chart.Instance = function (id, chartType) {
- id = '#' + id;
- return function (options) {
- $(id)[chartType](options);
- return function () {
- return $(id)[chartType]('instance');
- }
- }
- }
- });
- $(function () {
- 'use strict';
- BemsWebApplication.Factory.FA = function (FA_fType, params, viewInfo) {
- var initialized = false,
- shouldReload = false,
- datagrid = null,
- currentTabIndex = ko.observable(0),
- facilityViewModel = new BWA.CmFacilityViewModel(),
- dataSource;
- var m_Facility;
- var facilityDataSource = BWA.db.createDataSource('CmFacility'),
- facilitiesForSearch = ko.observableArray(),
- facilityCodeForSearch = ko.observable(0),
- deferredForSearch = new $.Deferred();
- var visiblePopup = ko.observable(false);
- var formulaGet = new BWA.Chart.FormulaGet(BWA.UserInfo.SiteId());
- // cyim 2016.08.22 : 성능분석 그래프의 경우 시간 데이타만 표시되어야 한다
- var timeBoxForSearch = BWA.SearchView.createDateTimeBox($G.TimeTypesForHourOnly, null, false);
- // !!!! 중요 hcLee
- var charts = BWA.UserInfo.GetCharts(FA_fType);
- var multiViewOptions = {
- viewIndex: currentTabIndex,
- viewCount: parseInt(charts.length / 6) + 1,
- PageChanged: function () {
- if (currentTabIndex() == 1) {
- makePageChart(1);
- }
- if (currentTabIndex() == 2) {
- makePageChart(2);
- }
- handleSearchInSearchView();
- },
- };
- var divs = [];
- function makePageChart(p) {
- // TYPE 1~5먼저 처리
- if (p == 0 && charts.length < 5)
- switch (charts.length) {
- case 1:
- document.getElementById("f_detail_chart").style.height = "700px";
- makeChart('clearfix', 0, 'margin-left: 1.1%; width: 66.25%; height: 700px; margin-top:28px;');
- break;
- case 2:
- document.getElementById("f_detail_chart").style.height = "700px";
- makeChart('clearfix', 0, 'margin-left: 1.1%; width: 66.25%; height: 340px; margin-top:28px;');
- makeChart('clearfix', 1, 'margin-left: 1.1%; width: 66.25%; height: 340px; margin-top:18px;');
- break;
- case 3:
- document.getElementById("f_detail_chart").style.height = "700px";
- makeChart('clearfix', 0, 'margin-left: 1.1%; width: 66.25%; height: 340px; margin-top:28px;');
- makeChart('clearfix', 1, 'margin-left: 1.1%; width: 32.5%; height: 340px; margin-top:18px;');
- makeChart('clearfix', 2, 'margin-left: 1.1%; width: 32.5%; height: 340px; margin-top:18px;');
- break;
- case 4:
- makeChart('clearfix', 0, 'margin-left: 1.1%; width: 66.25%; height: 340px; margin-top:28px;');
- // 필요
- document.getElementById('clearfix').insertAdjacentHTML('beforeend', "<div class='clear'></div>");
- makeChart('clearfix', 1, 'width: 32.5%; height: 340px; margin-top:18px;');
- makeChart('clearfix', 2, 'margin-left: 1.1%; width: 32.5%; height: 340px; margin-top:18px;');
- makeChart('clearfix', 3, 'margin-left: 1.1%; width: 32.5%; height: 340px; margin-top:18px;');
- break;
- }
- if (p == 0 && charts.length >= 5) {
- makeChart('clearfix', 0, 'margin-left: 1.1%; width: 32.5%; height: 340px; margin-top:28px;');
- makeChart('clearfix', 1, 'margin-left: 1.1%; width: 32.5%; height: 340px; margin-top:28px;');
- document.getElementById('clearfix').insertAdjacentHTML('beforeend', "<div class='clear'></div>");
- makeChart('clearfix', 2, 'width: 32.5%; height: 340px; margin-top:18px;');
- makeChart('clearfix', 3, 'margin-left: 1.1%; width: 32.5%; height: 340px; margin-top:18px;');
- makeChart('clearfix', 4, 'margin-left: 1.1%; width: 32.5%; height: 340px; margin-top:18px;');
- }
- if (p >= 1) {
- var chartpage = 'subCharts_' + p;
- var itemIndex = 0;
- for (var c = p * 6 - 1; c < charts.length; c++) {
- if (c >= charts.length) return;
- if (c >= p * 6 + 5) return;
- var divid = 'divchart_' + charts[c].ChartId();
- var chartId = 'chart_' + charts[c].ChartId();
- var style = 'margin-left: 1.1%; width: 32.5%; height: 340px;';
- if (itemIndex == 0) style = 'width: 32.5%; height: 340px;';
- if (itemIndex == 3) style = 'width: 32.5%; height: 340px; margin-top:18px;';
- if (itemIndex == 3)
- document.getElementById('clearfix').insertAdjacentHTML('beforeend', "<div class='clear'></div>");
- if (itemIndex > 3) style = 'margin-left: 1.1%; width: 32.5%; height: 340px; margin-top:18px;';
- makeChart(chartpage, c, style);
- itemIndex++;
- }
- }
- }
- function makeChart(pid, index, style) {
- var divid = 'divchart_' + charts[index].ChartId();
- if (document.getElementById(divid) == null)
- document.getElementById(pid).insertAdjacentHTML('beforeend',
- "<div id=" + divid +
- " class='fl chart_wrap_box' style='" + style + "' >" +
- "<p class='body_sub_title_2depth'>" +
- (charts[index].Title()) +
- "</p>" +
- "<div id=" + ('chart_' + charts[index].ChartId()) +
- " style='height: 90%; width: 100%;' /> </div>");
- }
- function makeChartView(p) {
- var div = [];
- if (p == 0) {
- div.push({
- id: 'f_detail'
- });
- for (var c = 0; c < charts.length; c++) {
- if (c >= charts.length) return div;
- if (c >= 5) return div;
- div.push({ id: 'divchart_' + charts[c].ChartId(), chartId: 'chart_' + charts[c].ChartId() });
- }
- }
- else {
- for (var c = p * 6 - 1; c < charts.length; c++) {
- if (c >= charts.length) return div;
- if (c >= p * 6 + 5) return div;
- div.push({ id: 'divchart_' + charts[c].ChartId(), chartId: 'chart_' + charts[c].ChartId() });
- }
- }
- return div;
- }
- for (var p = 0; p < multiViewOptions.viewCount; p++) {
- divs.push(makeChartView(p));
- }
- var chartLayout = new BWA.ChartLayout({
- divs: divs,
- multiViewOptions: multiViewOptions,
- });
- var m = moment();
- // 추가 2015 04 20 hcLee ->
- var CODE = $Code,
- FuelType = CODE.FuelType,
- FT = CODE.FacilityType,
- FC = CODE.FacilityCode,
- F = CODE.Formula,
- TIT = CODE.TimeIntervalType;
- function handleViewShown() {
- if (initialized === false) {
- makePageChart(0);
- initialized = true;
- timeBoxForSearch.setDefaultDate();
- var eq = BWA.DataUtil.constructEqualFilter;
- facilityDataSource.filter([eq('SiteId', BWA.UserInfo.SiteId()), 'and', eq('FacilityTypeId', FA_fType)]);
- $.when(facilityDataSource.load()).done(function (facilities) {
- facilitiesForSearch(facilities);
- if (_.isEmpty(facilities) === false) {
- var f = facilities[0]; // 첫번째 설비 그려주기 위해
- handleSelectedFacilityInSearchView(f);
- handleSearchInSearchView();
- //2018 03 06 hcLee
- var datagrid = $('#FA_DataGridViewInSearchView').dxDataGrid('instance');
- if (_.has(datagrid, 'selectRows')) {
- datagrid.selectRows(f);
- }
- }
- });
- }
- else {
- handleSearchInSearchView();
- }
- }
- if (shouldReload) {
- }
- function handleViewHidden() {
- var paging = BWA.ChartLayout.Paging;
- paging.sideOverlayVisible(false);
- $SearchView.visibleObservable(false); // hcLee 2015 03 23
- visiblePopup(false);
- }
- function handleViewShowing() {
- }
- function refreshList() {
- }
- var searchViewOptions = {
- searchViewItems: [
- { id: 'FacilityCode', ignoreValue: 0, defaultValue: 0, value: facilityCodeForSearch, dataSource: facilitiesForSearch },
- ],
- promiseDataInSearchView: deferredForSearch.promise()
- };
- function handleSelectedFacilityInSearchView(facility) {
- m_Facility = facility;
- return;
- }
- function ChartProcess(chartInfo, DataArray, valueAx, seriesF) {
- var chartid = '#chart_' + chartInfo.ChartId();
- $(chartid).dxChart({
- dataSource: DataArray,
- palette: chartInfo.Palette(),
- legend: {
- visible: true,
- verticalAlignment: 'top',
- horizontalAlignment: 'center'
- },
- commonAxisSettings: {
- title: {
- valueMarginsEnabled: true,
- margin: 20,
- font: {
- color: "black",
- size: 18,
- weight: 600,
- family: "Nanum Gothic",
- },
- },
- axisDivisionFactor: 50,
- grid: {
- visible: false,
- }
- },
- commonSeriesSettings: {
- argumentField: "DateTime",
- selectionStyle: {
- hatching: {
- direction: "left"
- }
- }
- },
- valueAxis: valueAx,
- series: seriesF,
- crosshair: {
- enabled: true,
- width: 1,
- horizontalLine: {
- color: '#452d11',
- dashStyle: 'dash',
- visible: false
- },
- verticalLine: {
- color: '#452d11',
- dashStyle: 'dash',
- visible: true
- },
- label: {
- visible: true,
- backgroundColor: "#452d11",
- font: {
- color: "white",
- size: 12,
- weight: 600,
- }
- }
- },
- tooltip: {
- enabled: true,
- color: "#3e1717",
- format: 'fixedPoint',
- precision: 2,
- font: {
- color: "white",
- size: 12,
- weight: 600,
- },
- argumentFormat: 'shortDate',
- customizeText: function () {
- return {
- text: [this.argumentText, ': ', this.valueText].join('')
- };
- }
- },
- });
- }
- function ChartProcess2(chartInfo, DataArray, valueAx) {
- var chartid = '#chart_' + chartInfo.ChartId();
- var argAxis = {
- title: {
- text: chartInfo.XAxTitle(),
- }
- };
- if (chartInfo.UseXAxMinMax())
- $.extend(argAxis, {
- max: chartInfo.XAxMax(),
- min: chartInfo.XAxMin(),
- });
- $(chartid).dxChart({
- dataSource: DataArray,
- palette: chartInfo.Palette(),
- legend: {
- visible: false,
- verticalAlignment: 'top',
- horizontalAlignment: 'center'
- },
- argumentAxis: argAxis,
- valueAxis: valueAx,
- series: {
- type: chartInfo.XSType(),
- valueField: 'lv1',
- argumentField: 'xv', //
- label: {
- visible: false,
- //customizeText: function() {
- // return this.argumentField + this.valueText;
- //}
- },
- point: { size: 8 }
- },
- crosshair: {
- enabled: true,
- width: 1,
- horizontalLine: {
- color: '#452d11',
- dashStyle: 'dash',
- visible: false
- },
- verticalLine: {
- color: '#452d11',
- dashStyle: 'dash',
- visible: true
- },
- label: {
- visible: true,
- backgroundColor: "#452d11",
- font: {
- color: "white",
- size: 12,
- weight: 600,
- }
- }
- },
- tooltip: {
- enabled: true,
- color: "#3e1717",
- format: 'fixedPoint',
- precision: 2,
- font: {
- color: "white",
- size: 12,
- weight: 600,
- },
- //argumentFormat: 'shortDate',
- customizeText: function () {
- return {
- text: [this.argumentText, ': ', this.valueText].join('')
- };
- }
- },
- });
- }
- function FormulaProcessLeft(timeIntervalType, date, formulaList) {
- var deferred = new $.Deferred();
- var promises = [];
- var f = m_Facility.toJS();
- var DataArray = [];
- var p;
- _.each(formulaList, function (fid) {
- if (fid == null) fid = 0;
- if (fid >= 1000)
- p = formulaGet.apiGet({
- FacilityTypeId: 103,
- FacilityCode: f.FacilityCode, // FacilityTypeId가 100보다 크면 의미가 없다. 정상
- FormulaId: fid - 1000 + 1,
- TimeIntervalType: timeIntervalType,
- StartDate: date.startDate,
- EndDate: date.endDate
- });
- else
- p = formulaGet.apiGet({
- FacilityTypeId: f.FacilityTypeId,
- FacilityCode: f.FacilityCode,
- FormulaId: fid,
- TimeIntervalType: timeIntervalType,
- StartDate: date.startDate,
- EndDate: date.endDate
- });
- promises.push(p);
- });
- $.when.apply(this, promises)
- .done(function (data1, data2, data3, data4) {
- if (formulaList.length == 1) {
- _.each(data1, function (x) {
- DataArray.push({
- DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
- lv1: x.Value
- });
- });
- deferred.resolve(DataArray);
- return DataArray;
- }
- if (data1 != undefined)
- _.each(data1[0], function (x) {
- DataArray.push({
- DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
- lv1: x.Value
- });
- });
- if (data2 != undefined)
- _.each(data2[0], function (x) {
- DataArray.push({
- DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
- lv2: x.Value
- });
- });
- if (data3 != undefined)
- _.each(data3[0], function (x) {
- DataArray.push({
- DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
- lv3: x.Value
- });
- });
- if (data4 != undefined)
- _.each(data4[0], function (x) {
- DataArray.push({
- DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
- lv4: x.Value
- });
- });
- deferred.resolve(DataArray);
- return DataArray;
- })
- .fail(function (error) {
- //alert(error);
- //visiblePopup(false);
- });
- return deferred.promise();
- }
- function FormulaProcessRight(timeIntervalType, date, formulaList) {
- var deferred = new $.Deferred();
- var promises = [];
- var f = m_Facility.toJS();
- var DataArray = [];
- var p;
- _.each(formulaList, function (fid) {
- if (fid == null) fid = 0;
- if (fid >= 1000)
- p = formulaGet.apiGet({
- FacilityTypeId: 103,
- FacilityCode: f.FacilityCode, // FacilityTypeId가 100보다 크면 의미가 없다. 정상
- FormulaId: fid - 1000 + 1,
- TimeIntervalType: timeIntervalType,
- StartDate: date.startDate,
- EndDate: date.endDate
- });
- else
- p = formulaGet.apiGet({
- FacilityTypeId: f.FacilityTypeId,
- FacilityCode: f.FacilityCode,
- FormulaId: fid,
- TimeIntervalType: timeIntervalType,
- StartDate: date.startDate,
- EndDate: date.endDate
- });
- promises.push(p);
- });
- $.when.apply(this, promises)
- .done(function (data1, data2, data3, data4) {
- if (formulaList.length == 1) {
- _.each(data1, function (x) {
- DataArray.push({
- DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
- rv1: x.Value
- });
- });
- deferred.resolve(DataArray);
- return DataArray;
- }
- if (data1 != undefined)
- _.each(data1[0], function (x) {
- DataArray.push({
- DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
- rv1: x.Value
- });
- });
- if (data2 != undefined)
- _.each(data2[0], function (x) {
- DataArray.push({
- DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
- rv2: x.Value
- });
- });
- if (data3 != undefined)
- _.each(data3[0], function (x) {
- DataArray.push({
- DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
- rv3: x.Value
- });
- });
- if (data4 != undefined)
- _.each(data4[0], function (x) {
- DataArray.push({
- DateTime: BWA.Chart.getCustermTimeArgumentAxisString(timeBoxForSearch.type(), moment(x.DateTime).toDate()),
- rv4: x.Value
- });
- });
- deferred.resolve(DataArray);
- return DataArray;
- })
- .fail(function (error) {
- //alert(error);
- //visiblePopup(false);
- });
- return deferred.promise();
- }
- // 최종적으로 차트별로 이함수를 불러줘야 한다.
- function DrawChart(chartInfo, timeIntervalType, date) {
- if (chartInfo == null) return;
- if (chartInfo.UseX()) return DrawChart2(chartInfo, timeIntervalType, date);
- var promises = [];
- var f = m_Facility.toJS();
- // L, R Y축 설정
- var valueAx = [];
- if (chartInfo.LAxTitle() != null) {
- var va = {
- name: 'left',
- //2018 04 23 hcLee 추가
- grid: {
- visible: true
- },
- title: {
- text: chartInfo.LAxTitle(),
- },
- };
- if (chartInfo.UseLAxMinMax())
- $.extend(va, {
- type: 'continuous',
- valueType: 'numeric',
- minValueMargin: 0,
- maxValueMargin: 0,
- max: chartInfo.LAxMax(),
- min: chartInfo.LAxMin(),
- tickInterval: (chartInfo.LAxMax() - chartInfo.LAxMin()) / 5,
- valueMarginsEnabled: true,
- });
- // 2018 03 12 hcLee 추가
- if (chartInfo.UseLCTLine())
- $.extend(va, {
- constantLines: [{
- label: {
- text: chartInfo.LCTLineTitle(),
- },
- width: 2,
- value: chartInfo.LCTLineValue(),
- dashStyle: 'dash'
- }],
- });
- valueAx.push(va);
- }
- if (chartInfo.RAxTitle() != null) {
- var va = {
- name: 'right',
- //2018 04 23 hcLee 추가
- grid: {
- visible: true
- },
- title: {
- text: chartInfo.RAxTitle(),
- },
- position: 'right',
- label: {
- visible: true,
- },
- };
- if (chartInfo.UseRAxMinMax())
- $.extend(va, {
- type: 'continuous',
- valueType: 'numeric',
- minValueMargin: 0,
- maxValueMargin: 0,
- max: chartInfo.RAxMax(),
- min: chartInfo.RAxMin(),
- tickInterval: (chartInfo.RAxMax() - chartInfo.RAxMin()) / 5,
- valueMarginsEnabled: true,
- });
- // 2018 03 12 hcLee 추가
- if (chartInfo.UseRCTLine())
- $.extend(va, {
- constantLines: [{
- label: {
- font: {
- color: 'red',
- },
- horizontalAlignment: 'right',
- text: chartInfo.RCTLineTitle(),
- },
- width: 2,
- value: chartInfo.RCTLineValue(),
- dashStyle: 'dash',
- color: 'red' // hcLee 2018 03 28 오른쪽 기준선
- }],
- });
- valueAx.push(va);
- }
- // L, R series 설정
- var series = [];
- if (chartInfo.LSFmId1() > 0)
- series.push(
- {
- name: chartInfo.LSName1(),
- type: chartInfo.LSType1(),
- valueField: 'lv1',
- argumentField: 'DateTime',
- label: {
- visible: false,
- },
- point: { size: 3 }
- });
- if (chartInfo.LSFmId2() > 0)
- series.push(
- {
- name: chartInfo.LSName2(),
- type: chartInfo.LSType2(),
- valueField: 'lv2',
- argumentField: 'DateTime',
- label: {
- visible: false,
- },
- point: { size: 3 }
- });
- if (chartInfo.LSFmId3() > 0)
- series.push(
- {
- name: chartInfo.LSName3(),
- type: chartInfo.LSType3(),
- valueField: 'lv3',
- argumentField: 'DateTime',
- label: {
- visible: false,
- },
- point: { size: 3 }
- });
- if (chartInfo.LSFmId4() > 0)
- series.push(
- {
- name: chartInfo.LSName4(),
- type: chartInfo.LSType4(),
- valueField: 'lv4',
- argumentField: 'DateTime',
- label: {
- visible: false,
- },
- point: { size: 3 }
- });
- if (chartInfo.RSFmId1() > 0)
- series.push(
- {
- name: chartInfo.RSName1(),
- type: chartInfo.RSType1(),
- axis: 'right',
- valueField: 'rv1',
- argumentField: 'DateTime',
- label: {
- visible: false,
- },
- point: { size: 3 }
- });
- if (chartInfo.RSFmId2() > 0)
- series.push(
- {
- name: chartInfo.RSName2(),
- type: chartInfo.RSType2(),
- axis: 'right',
- valueField: 'rv2',
- argumentField: 'DateTime',
- label: {
- visible: false,
- },
- point: { size: 3 }
- });
- if (chartInfo.RSFmId3() > 0)
- series.push(
- {
- name: chartInfo.RSName3(),
- type: chartInfo.RSType3(),
- axis: 'right',
- valueField: 'rv3',
- argumentField: 'DateTime',
- label: {
- visible: false,
- },
- point: { size: 3 }
- });
- if (chartInfo.RSFmId4() > 0)
- series.push(
- {
- name: chartInfo.RSName4(),
- type: chartInfo.RSType4(),
- axis: 'right',
- valueField: 'rv4',
- argumentField: 'DateTime',
- label: {
- visible: false,
- },
- point: { size: 3 }
- });
- var DataArray = [];
- promises.push(FormulaProcessLeft(timeIntervalType, date, [chartInfo.LSFmId1(), chartInfo.LSFmId2(), chartInfo.LSFmId3(), chartInfo.LSFmId4()]));
- promises.push(FormulaProcessRight(timeIntervalType, date, [chartInfo.RSFmId1(), chartInfo.RSFmId2(), chartInfo.RSFmId3(), chartInfo.RSFmId4()]));
- $.when.apply(this, promises)
- .done(function (dataL, dataR) {
- _.each(dataL, function (x) {
- DataArray.push(x);
- });
- _.each(dataR, function (x) {
- DataArray.push(x);
- });
- ChartProcess(chartInfo, DataArray, valueAx, series);
- })
- .fail(function (error) {
- //alert(error);
- //visiblePopup(false);
- });
- }
- // X가 시계열이 아닌 경우 별도 처리, 이 경우는 LY만 존재 하고 시리즈 또한 LY용 1개, X축 시리즈 1개 만 존재 한다.
- function DrawChart2(chartInfo, timeIntervalType, date) {
- if (chartInfo == null) return;
- var promises = [];
- var f = m_Facility.toJS();
- // L, Y축 설정
- var valueAx = [];
- if (chartInfo.LAxTitle() != null) {
- var va = {
- name: 'left',
- grid: {
- visible: true
- },
- title: {
- text: chartInfo.LAxTitle(),
- },
- };
- if (chartInfo.UseLAxMinMax())
- $.extend(va, {
- type: 'continuous',
- valueType: 'numeric',
- minValueMargin: 0,
- maxValueMargin: 0,
- max: chartInfo.LAxMax(),
- min: chartInfo.LAxMin(),
- tickInterval: (chartInfo.LAxMax() - chartInfo.LAxMin()) / 5,
- valueMarginsEnabled: true,
- });
- // 2018 03 12 hcLee 추가
- if (chartInfo.UseLCTLine())
- $.extend(va, {
- constantLines: [{
- label: {
- text: chartInfo.LCTLineTitle(),
- },
- width: 2,
- value: chartInfo.LCTLineValue(),
- dashStyle: 'dash'
- }],
- });
- valueAx.push(va);
- }
- var DataArray = [];
- promises.push(FormulaProcessLeft(timeIntervalType, date, [chartInfo.LSFmId1(), 0, 0, 0]));
- promises.push(FormulaProcessRight(timeIntervalType, date, [chartInfo.XSFmId(), 0, 0, 0]));
- $.when.apply(this, promises)
- .done(function (dataL, dataX) {
- _.each(dataL, function (x) {
- DataArray.push(x);
- });
- _.each(dataX, function (x) {
- DataArray.push(x);
- });
- var dataArray = BWA.Chart.getRelationDataArrayOnDateTimeNew(dataL, dataX, 'lv1', 'xv');
- ChartProcess2(chartInfo, dataArray, valueAx);
- })
- .fail(function (error) {
- //alert(error);
- //visiblePopup(false);
- });
- }
- function handleSearchInSearchView(filter, searchViewItems, viewModel) {
- if (m_Facility == null) return;
- var f = m_Facility.toJS();
- facilityViewModel.fromJS(f);
- var timeIntervalType = timeBoxForSearch.type();
- var date = timeBoxForSearch.getDate();
- // 2018 03 06 hcLee 테스트코드
- if (currentTabIndex() == 0) {
- for (var c = 0; c < 5; c++) {
- if (c >= charts.length) return;
- DrawChart(charts[c], timeIntervalType, date);
- }
- }
- else {
- for (var c = currentTabIndex() * 6 - 1; c < charts.length; c++) {
- if (c >= charts.length) return;
- if (c >= currentTabIndex() * 6 + 5) return;
- DrawChart(charts[c], timeIntervalType, date);
- }
- }
- return;
- }
- var viewModel = $.extend(BWA.CommonView.create(
- params, viewInfo, searchViewOptions, ko.observable(null),
- handleViewShown, null, handleSearchInSearchView, undefined,
- chartLayout), {
- viewHidden: handleViewHidden, // hcLee 2015 06 03
- refreshList: refreshList,
- viewShowing: handleViewShowing,
- scrolling: { mode: 'infinite' },
- FA_DataGridOptions: {
- dataSource: facilitiesForSearch,
- columns: [
- { dataField: 'Name', caption: $G('facilityName'), width: '100%', alignment: 'left' }
- ],
- filterRow: {
- visible: true,
- showOperationChooser: false
- },
- selection: {
- mode: 'single'
- },
- rowClick: function (clickRow) {
- handleSelectedFacilityInSearchView(clickRow.data);
- },
- paging: {
- pageSize: 11,
- enabled: true
- }
- },
- contentReadyAction: function (e) {
- datagrid = e.component;
- },
- });
- viewModel.timeBoxForSearch = timeBoxForSearch;
- viewModel.currentTabIndex = currentTabIndex;
- viewModel.multiViewItems = [
- {
- facility: facilityViewModel,
- template: 'mainCharts'
- },
- ];
- for (var p = 1; p < multiViewOptions.viewCount; p++) {
- viewModel.multiViewItems.push({ template: 'subCharts_' + p });
- }
- $HourGlassPopup(viewModel, visiblePopup);
- return viewModel;
- }
- });
|