riot.tag2('qualva-cv-trend', ' {summaryString}', 'qualva-cv-trend,[riot-tag="qualva-cv-trend"],[data-is="qualva-cv-trend"]{ display: block }', '', function(opts) {
this.chartColors = this.opts.option.chartColors || (this.opts.option.themeColor ? window.colors[this.opts.option.themeColor] : void 0) || (window.view.setting.themeColor ? window.colors[window.view.setting.themeColor] : void 0) || window.colors['qualva-cv-trend'];
this.alphas = [1, 1, 0.5, 0.5];
this.mailReportSummaryString = window.mailReportSummaryString || false;
this.mailReportSummaryMaxMinCount = window.mailReportSummaryMaxMinCount || 3;
this.summaryString = '';
this.on('mount', (function(_this) {
return function() {
return _this.timespan = (_.first(_this.opts.option.crossColumns)).column;
};
})(this));
this.on('unmount', (function(_this) {
return function() {};
})(this));
this.init = (function(_this) {
return function() {
return _this.reload();
};
})(this);
this.reload = (function(_this) {
return function() {
if (_this.tags.content.isCompare()) {
return _this.compareChanged();
} else {
return _this.getData();
}
};
})(this);
this.compareChanged = (function(_this) {
return function() {
var compareCondition, condition, filter;
filter = _this.tags.content.getConditionFilter(_this.opts.option.filter);
condition = {
term: window.condition.term,
filter: filter
};
compareCondition = _this.tags.content.getCompareCondition(condition);
return $.when.apply(null, [
Resources.post({
uri: "/summary/gt",
data: {
projectId: window.project.id,
summaryColumn: _this.opts.option.summaryColumn,
crossColumns: _this.opts.option.crossColumns,
condition: condition
}
}), Resources.post({
uri: "/summary/gt",
data: {
projectId: window.project.id,
summaryColumn: _this.opts.option.summaryColumn,
crossColumns: _this.opts.option.crossColumns,
condition: compareCondition
}
})
]).then(function() {
var gts;
gts = _.map(arguments, 0);
_.each(gts[0].summary, function(data, i) {
if (gts[1].summary[i]) {
data.compare = gts[1].summary[i].count;
return data.compare_cross1 = gts[1].summary[i].cross1;
} else {
data.compare = 0;
return data.compare_cross1 = 0;
}
});
return _this.drawChart(gts[0]);
});
};
})(this);
this.getData = (function(_this) {
return function() {
var filter;
filter = _this.tags.content.getConditionFilter(_this.opts.option.filter);
return Resources.post({
uri: "/summary/gt",
data: {
projectId: window.project.id,
summaryColumn: _this.opts.option.summaryColumn,
crossColumns: _this.opts.option.crossColumns,
condition: {
selectAs: _this.opts.option.selectAs,
term: window.condition.term,
filter: filter
}
}
}).then(function(result) {
_this.drawChart(result);
return _this.generateSummaryString(result);
});
};
})(this);
this.summaryColumnLabel = (function(_this) {
return function(column) {
var col;
col = _.find(window.columns, function(col) {
return (col.columnName.indexOf(column)) !== -1;
});
return col.displayLabel;
};
})(this);
this.summaryValueLabel = function(valueListInfo, index) {
return valueListInfo.summaryValueList[index].label;
};
this.crossValueLabel = function(valueListInfo, crossIndex, index) {
return valueListInfo.crossValueProducts[index][crossIndex].label;
};
this.drawChart = (function(_this) {
return function(gt) {
var chartConfig, cvTitle, dataProvider, datas, entryTitle, from, graphs, isInDay, lines, to, total, totalCount, valueListInfo;
valueListInfo = gt.valueListInfo;
total = gt.total || 0;
datas = gt.summary;
if (_this.opts.option.inverse) {
datas.reverse();
}
totalCount = total.count;
dataProvider = datas;
entryTitle = "Entry";
cvTitle = "CV";
if (window.project.type === 'lighthouse') {
entryTitle = "エントリー数";
cvTitle = "CV数";
}
if (_this.tags.content.isCompare()) {
lines = [
{
field: 'count',
title: entryTitle + "(" + window.compareInfo.option.label + ")"
}, {
field: 'cross1',
title: cvTitle + "(" + window.compareInfo.option.label + ")"
}, {
field: 'compare',
title: entryTitle + "(" + window.compareInfo.option.compareLabel + ")"
}, {
field: 'compare_cross1',
title: cvTitle + "(" + window.compareInfo.option.compareLabel + ")"
}
];
} else {
lines = [
{
field: 'count',
title: entryTitle
}, {
field: 'cross1',
title: cvTitle
}
];
}
graphs = _.map(lines, function(line, i) {
var color, graph, title, valueField;
color = _this.chartColors[i % _this.chartColors.length];
title = line.title;
valueField = line.field;
return graph = {
bullet: "round",
bulletColor: color,
bulletSize: 10,
bulletBorderAlpha: 0,
bulletAlpha: 0,
hideBulletsCount: 50,
lineThickness: 1,
useLineColorForBulletBorder: true,
balloonText: "
[[title]]
[[value]]
",
fillAlphas: 0.1 * _this.alphas[i],
lineAlpha: _this.alphas[i],
title: title,
fillColors: color,
lineColor: color,
valueField: valueField,
type: _this.opts.option.graphType || "smoothedLine"
};
});
chartConfig = {
type: 'serial',
theme: 'none',
percentPrecision: 1,
precision: 1,
dataProvider: dataProvider,
valueAxes: [
{
stackType: 'none',
axisAlpha: 0.5,
axisColor: '#ccc',
gridAlpha: 0.3,
gridColor: '#ccc',
color: "#666",
minHorizontalGap: 20,
tickLength: 0,
gridCount: 10
}
],
pathToImages: "https://www.amcharts.com/lib/3/images/",
chartScrollbar: {
oppositeAxis: false,
offset: 24,
scrollbarHeight: 36,
backgroundAlpha: 0,
selectedBackgroundAlpha: 0.1,
selectedBackgroundColor: "#888",
graphFillAlpha: 0,
graphLineAlpha: 0.0,
selectedGraphFillAlpha: 0,
selectedGraphLineAlpha: 1,
selectedGraphLineColor: '#fff',
autoGridCount: true
},
graphs: graphs,
categoryField: _this.opts.option.summaryColumn.column,
categoryAxis: {
startOnAxis: true,
equalSpacing: true,
parseDates: true,
dashLength: 1,
gridAlpha: 0,
minorGridAlpha: 0,
minorGridEnabled: false
},
fontSize: 10,
legend: {
equalWidths: false,
useGraphSettings: true,
align: "center",
marginTop: 0,
verticalGap: 3,
autoMargins: false,
marginRight: 0,
spacing: -64,
markerSize: 8
},
exportConfig: {
hideButton: true
}
};
if (opts.hideScroll) {
chartConfig = _.omit(chartConfig, ['chartScrollbar']);
}
from = moment(window.condition.term.fromDate);
to = moment(window.condition.term.toDate);
isInDay = to.diff(from, 'days') <= 1;
if (isInDay) {
chartConfig.dataDateFormat = "YYYY-MM-DD HH:NN";
chartConfig.categoryAxis.minPeriod = 'hh';
chartConfig.categoryAxis.dateFormats = [
{
period: 'hh',
format: 'HH:NN'
}, {
period: 'DD',
format: 'MM/DD'
}, {
period: 'WW',
format: 'MM'
}, {
period: 'MM',
format: 'YYYYMM'
}, {
period: 'YYYY',
format: 'YYYY/MM'
}
];
} else {
chartConfig.dataDateFormat = "YYYY-MM-DD";
chartConfig.categoryAxis.minPeriod = 'DD';
chartConfig.categoryAxis.dateFormats = [
{
period: 'DD',
format: 'MM/DD'
}, {
period: 'WW',
format: 'MM'
}, {
period: 'MM',
format: 'YYYY/MM'
}, {
period: 'YYYY',
format: 'YYYY/MM'
}
];
}
AmCharts.makeChart("chart_" + _this.opts.id, chartConfig);
_this.update();
return _this.loadComplete();
};
})(this);
this.generateSummaryString = (function(_this) {
return function(data) {
var cross1Values, formatDate, hasMinMax, maxDates, maxEntries, maxVal, minDates, minEntries, minVal;
hasMinMax = false;
minEntries = [];
maxEntries = [];
if (data && data.length > 0) {
formatDate = function(date) {
var _date, d;
_date = new Date(date);
d = moment(_date);
return d.format("MM/DD");
};
cross1Values = data.summary.map(function(item, i) {
return item.cross1;
});
minVal = Math.min.apply(Math, cross1Values);
maxVal = Math.max.apply(Math, cross1Values);
hasMinMax = minVal < maxVal;
if (hasMinMax) {
data.summary.forEach(function(item) {
if (item.cross1 === minVal) {
minEntries.push(item);
}
if (item.cross1 === maxVal) {
return maxEntries.push(item);
}
});
if (minEntries.length > _this.mailReportSummaryMaxMinCount) {
minEntries = [];
}
if (maxEntries.length > _this.mailReportSummaryMaxMinCount) {
maxEntries = [];
}
if (maxEntries.length && minEntries.length) {
maxDates = maxEntries.map(function(item) {
return formatDate(item.inputDate);
});
minDates = minEntries.map(function(item) {
return formatDate(item.inputDate);
});
_this.summaryString = "コンプリートは、" + (maxDates.join('、')) + " が最も多く、" + (minDates.join('、')) + " が最も少なかった。";
} else if (maxEntries.length) {
maxDates = maxEntries.map(function(item) {
return formatDate(item.inputDate);
});
_this.summaryString = "コンプリートは、" + (maxDates.join('、')) + " が最も多かった。";
} else if (minEntries.length) {
minDates = minEntries.map(function(item) {
return formatDate(item.inputDate);
});
_this.summaryString = "コンプリートは、" + (minDates.join('、')) + " が最も少なかった。";
} else {
_this.summaryString = "";
}
}
}
return _this.update();
};
})(this);
this.loadComplete = (function(_this) {
return function() {
return _this.tags.content.loadComplete();
};
})(this);
});