営業データ管理

Wijmoのコントロールを使用して、簡易的な営業データ管理アプリケーションを作成します。このサンプルでは、次のシナリオを確認することができます。

  • 担当者別進捗状況のタブ
    • FlexGridを利用して案件データを表示します
      • CollectionView.groupDescriptionsプロパティを利用して、営業部署別および四半期ごとのデータを表示しています
      • 進捗率の列ではLinearGaugeを利用して、ゲージ形式で進捗率を表現しています
      • 進捗の列ではcellTemplateプロパティを利用して、進捗値に応じたステータスバッジを設定しています
      • 重要度の列ではCellMakerクラスを利用して、セルに設定された値に応じて任意の要素をセル上に表示しています
  • 部門別売上高のタブ
    • FlexChartを利用して売上データを表示します
      • データは部門別、四半期別、担当者別にドリルダウンすることできます
  • 全体進捗状況のタブ
    • RadialGaugeを利用して進捗率を表示します
    • Tooltipを利用して任意のメッセージを表示します
import 'bootstrap.css'; import '@mescius/wijmo.styles/wijmo.css'; import { CollectionView } from '@mescius/wijmo'; import { FlexGrid } from '@mescius/wijmo.grid'; import './styles.css'; import * as wjcCore from '@mescius/wijmo'; import { LinearGauge, ShowText, RadialGauge, NeedleShape } from "@mescius/wijmo.gauge"; import { CellMaker } from '@mescius/wijmo.grid.cellmaker'; import { getData, getGroupData } from './data'; import * as chart from '@mescius/wijmo.chart'; import * as wjNav from '@mescius/wijmo.nav'; document.readyState === 'complete' ? init() : window.onload = init; function init() { const budgetRate = 0.9542; const expenseRate = 1.092; let theTabPanel = new wjNav.TabPanel('#theTabPanel', { isAnimated: true }); // create a paged CollectionView with 6 data items per page let data = getData(); let view = new CollectionView(data, { groupDescriptions: ['department', 'quarter'] }); let layoutDefs = [ // { binding: 'id', header: '案件ID', align: 'center', width: 150 }, { binding: 'person', header: '担当者', align: 'center', width: '*' }, { binding: 'sales', header: '受注予定金額', align: 'right', format: 'c0', width: '*' }, { binding: 'progress', header: '進捗率(%)', align: 'center', width: '0.7*' }, { binding: 'status', header: '進捗', align: 'center', cellTemplate: '<span class="badge rounded-pill bg-${text}">${text}</span>', isReadOnly: true }, { binding: 'priority', header: '重要度', align: 'center', isReadOnly: true, cssClass: 'custom-rating', cellTemplate: CellMaker.makeRating({ range: [1, 3], }), width: '0.7*' }, ]; let grid = new FlexGrid('#theGrid', { autoGenerateColumns: false, showMarquee: true, columns: layoutDefs, headersVisibility: 'Column', itemsSource: view, allowDragging: 0, }); var discountCol = grid.columns.getColumn("progress"); discountCol.cssClass = "my-cell"; discountCol.width = 200; discountCol.isReadOnly = true; grid.formatItem.addHandler((s, e) => { if (s.cells !== e.panel || (s.editRange && s.editRange.containsRow(e.row) && s.editRange.containsColumn(e.col))) { return; } let col = e.getColumn(); if (col.binding !== "progress") { return; } let item = e.getRow().dataItem, binding = col.binding; let host = document.createElement("div"); //host.style.height = '10px'; e.cell.innerHTML = ""; e.cell.appendChild(host); let gauge = new LinearGauge(host, { min: 0, max: 100, isReadOnly: false, step: 1, showText: ShowText.Value, valueChanged: (gs, ge) => { item[binding] = gs.value; let value = gs.value === 0 ? '未着手' : gs.value === 100 ? '完了' : '対応中'; if (item['status'] === value) return; item['status'] = value; grid.refresh(false); }, ranges: [ { name: 'low', min: 0, max: 20, color: 'rgba(255,0,0,.4)' }, { name: 'med', min: 20, max: 80, color: '#e5f8ff' }, { name: 'top', min: 80, max: 1000, color: '#c4e6a1' }, ], thumbSize: 25 }); gauge.value = s.getCellData(e.row, e.col, false); }); let salesGauge = new RadialGauge('#salesGauge', { min: 0, max: 1, value: budgetRate, startAngle: -90, sweepAngle: 360, showText: ShowText.Value, stackRanges: true, face: { thickness: 0.3 }, pointer: { thickness: 0.3 }, format: 'p2' }); let perf = data.reduce((sum, i) => sum + i.sales, 0); document.querySelector('#budget').textContent = wjcCore.Globalize.format(((perf / budgetRate)), 'c0'); document.querySelector('#perf').textContent = wjcCore.Globalize.format(perf, 'c0'); let profitsGauge = new RadialGauge('#profitsGauge', { min: 0, max: 1, value: 0.2806, startAngle: -45, sweepAngle: 270, showText: ShowText.Value, face: { thickness: 0.3 }, pointer: { thickness: 0.3 }, format: 'p2' }); document.querySelector('#profit').textContent = wjcCore.Globalize.format((0.275), 'p2'); let expenseGauge = new RadialGauge('#expenseGauge', { min: 0, max: 1., value: expenseRate, startAngle: 0, sweepAngle: 360, showText: ShowText.Value, face: { thickness: 0.3 }, pointer: { thickness: 0.3 }, format: 'p2' }); document.querySelector('#fexpense').textContent = wjcCore.Globalize.format(perf * 0.75, 'c'); document.querySelector('#aexpense').textContent = wjcCore.Globalize.format(perf * 0.75 * expenseRate, 'c'); let chartView = new CollectionView(data, { groupDescriptions: ['department', 'quarter', 'person'] }); let tt = new wjcCore.Tooltip(); let prospectiveGauge = new RadialGauge('#prospectiveCustomer', { thickness: .2, showText: ShowText.None, min: 0, max: 5000, value: 3780, startAngle: 0, sweepAngle: 180, showTicks: true, showTickText: true, tickSpacing: 1000, showRanges: true, pointer: { thickness: 0, }, needleShape: NeedleShape.Pointer, ranges: [ { name: 'low', min: 0, max: 1500, color: 'rgba(255,0,0,.4)' }, { name: 'med', min: 1500, max: 3500, color: 'rgba(255,255,0,.4)' }, { name: 'top', min: 3500, max: 5000, color: '#c4e6a1' }, ], }); tt.setTooltip(salesGauge.hostElement, '予算は若干ですが、<b>未達</b>です。'); tt.setTooltip(expenseGauge.hostElement, '経費が予測よりもかかっているため、分析が必要です。'); tt.setTooltip(profitsGauge.hostElement, '目標を達成しています。'); tt.setTooltip(prospectiveGauge.hostElement, '目標まであと、<b>1220</b>人です。'); let barchart = new chart.FlexChart('#chart', { legend: { position: chart.Position.None }, bindingX: 'name', series: [{ binding: 'sales', name: '売上高', }], axisX: { title: '部署別', }, axisY: { title: '売上高', format: 'c' }, selectionMode: chart.SelectionMode.Point, selectionChanged: (s) => { if (s.selection) { let point = s.selection.collectionView.currentItem; if (point && point.group && !point.group.isBottomLevel) { showGroup(point.group); } } }, itemsSource: getGroupData(chartView), palette: ['rgba(45,159,199,1)', 'rgba(236,153,60,1)', 'rgba(137,194,53,1)', 'rgba(227,119,164,1)', 'rgba(166,137,49,1)', 'rgba(166,114,166,1)', 'rgba(208,192,65,1)', 'rgba(227,88,85,1)', 'rgba(104,112,106,1)'] }); function showGroup(group) { updateChartHeader(group); let level = 'level' in group ? group.level + 1 : 0; let pgd = chartView.groupDescriptions[level]; barchart.axisX.title = { person: '担当者', quarter: '四半期', department: '部署' }[pgd.propertyName]; let palette = barchart.palette || chart.Palettes.standard; barchart.series[0].style = { fill: palette[level], stroke: palette[level] }; barchart.itemsSource = getGroupData(group); barchart.selection = null; } var header = document.getElementById('header'); function updateChartHeader(group) { let item = group.items[0], path = '', headers = []; // for (let i = 0; i <= group.level; i++) { let pgd = chartView.groupDescriptions[i]; let prop = pgd.propertyName, hdr = wjcCore.format('<a href="#{path}">{prop}</a>: {value}', { path: path, prop: { person: '担当者', quarter: '四半期', department: '部署' }[prop], value: item[prop] }); // headers.push(hdr); path += '/' + item[prop]; } // header.innerHTML = headers.length > 0 ? '売上高 - ' + headers.join('、') : '売上高'; } header.addEventListener('click', function (e) { if (e.target.nodeName === 'A') { e.preventDefault(); let path = e.target.href; ; path = path.substr(path.lastIndexOf('#') + 1); let paths = path.split('/'); let src = chartView; for (let i = 1; i < paths.length; i++) { for (let j = 0; j < src.groups.length; j++) { let group = src.groups[j]; if (group.name == decodeURI(paths[i])) { src = group; break; } } } showGroup(src); } }); }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>MESCIUS Wijmo FlexGrid SalesDataManagementApplication</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- SystemJS --> <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.21.5/system.src.js" integrity="sha512-skZbMyvYdNoZfLmiGn5ii6KmklM82rYX2uWctBhzaXPxJgiv4XBwJnFGr5k8s+6tE1pcR1nuTKghozJHyzMcoA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script> <script src="systemjs.config.js"></script> <script> System.import('./src/app'); </script> </head> <body> <div class="container-fluid"> <div id="theTabPanel"> <div> <a>担当者別進捗状況</a> <div> <div id="theGrid"></div> </div> </div> <div> <a>部門別売上高</a> <div> <h4 id="header">部署別売上高</h4> <div id="chart"></div> </div> </div> <div> <a>全体進捗状況</a> <div> <div class="gauges"> <div class="tile"> <div class="tile-container"> <div class="tile-header">対予算比</div> </div> <div class="tile-content"> <div id="salesGauge"></div> <p> 予算: <b id="budget"></b> </p> <p> 実績: <b id="perf"></b> </p> </div> </div> <div class="tile"> <div class="tile-container"> <div class="tile-header">経費</div> </div> <div class="tile-content"> <div id="expenseGauge"></div> <p> 予測: <b id="fexpense"></b> </p> <p> 実績: <b id="aexpense"></b> </p> </div> </div> <div class="tile"> <div class="tile-container"> <div class="tile-header">利益率</div> </div> <div class="tile-content"> <div id="profitsGauge"></div> <p class="profit"> 目標値: <b id="profit"></b> </p> </div> </div> </div> <div class="tile" id="tilePros"> <div class="tile-container"> <div class="tile-header">見込み顧客獲得状況</div> </div> <div class="tile-content"> <div id="prospectiveCustomer" id="tilePros"></div> <p class="pros"> <b>目標値: 5000</b> </p> <p> <b>実績値: 3780</b> </p> </div> </div> </div> </div> </div> </div> </body> </html>
import * as core from '@mescius/wijmo'; // create an array with 1000 data items const departments = '第一営業部,第二営業部,第三営業部'.split(','); let products = 'ピアノ,バイオリン,フルート,ギター,チェロ'.split(','); let quarter = '第1 四半期,第2 四半期,第3 四半期,第4 四半期'.split(','); let firstNames = '佐藤,鈴木,高橋,田中,伊藤,山本,渡辺,中村,小林,加藤,吉田,山田,佐々木,山口,松本,井上,木村,斎藤,林,清水,山崎,阿部,森,池田,橋本,山下,石川,中島,前田,藤田'.split(','); let lastNames = '浩,誠,健一,大輔,達也,翔太,浩一,哲也,剛,大介,健太,拓也,豊,修,和彦,学,直樹,健太郎,浩二,徹,隆,亮,翔,恵子,久美子,由美子,明美,直美,陽子,智子,絵美,恵,裕子,愛,真由美,由美,麻衣,美穂,愛美,彩'.split(','); let numbers = [0, 7, 15, 22, 27, 34, 48, 50, 58, 60, 62, 70, 74, 78, 80, 85, 90, 93, 97, 100, 100, 100]; let priorityVal = [1, 2, 2, 2, 3]; export function getData() { let data = []; departments.forEach((department) => { quarter.forEach((quarter) => { products.forEach((product) => { let progress = numbers[Math.floor(Math.random() * numbers.length)]; data.push({ id: `CAS-${getRandomValue()}-${getRandomValue()}`, department: department, person: randArray(firstNames) + ' ' + randArray(lastNames), quarter: quarter, sales: Math.floor(Math.random() * 1000000), progress: progress, status: (progress === 0) ? '未着手' : (progress === 100) ? '完了' : '対応中', priority: priorityVal[Math.floor(Math.random() * priorityVal.length)], }); }); }); }); return data; } function randArray(arr) { return arr[randBetween(0, arr.length - 1)]; } function randBetween(min, max) { return Math.floor(Math.random() * (max - min + 1) + min); } function getValues(cnt, max) { let values = [], val = Math.random() * max; for (let i = 0; i < cnt; i++) { val = Math.min(max, val + (Math.random() - 0.5) * max / 5); values.push(val); } return values; } function getRandomValue() { let min = 1000; let max = 9999; return (Math.floor(Math.random() * (max + 1 - min)) + min); } export function getGroupData(group) { let arr = []; group.groups.forEach(g => { arr.push({ name: g.name, sales: g.getAggregate(core.Aggregate.Sum, 'sales'), group: g, }); }); return new core.CollectionView(arr); }
.wj-flexgrid { height: 540px; } .change-up { color: darkgreen; } .change-up:after { content: '\25b2'; margin-left: 0.5em; } .change-down { color: darkred; } .change-down:after { content: '\25bc'; margin-left: 0.5em; } .bg-完了 { background-color: green; } .bg-対応中 { background-color: #a1d3e6; } .bg-未着手 { background-color: palevioletred; } .wj-radialgauge { width: 200px; } .gauges { margin: 20px 0px; display: flex; flex-wrap: wrap; width: 700px; } .wj-gauge .wj-face path { stroke: #f5f5f5; } #salesGauge.wj-gauge .wj-pointer { fill: #66b1cc; } #salesGauge.wj-radialgauge .wj-value { color: #66b1cc; } #lastGauge.wj-gauge .wj-pointer { fill: #66a2cc; } #lastGauge.wj-gauge .wj-value { color: #66a2cc; } #expenseGauge.wj-gauge .wj-pointer { fill: #9bcc66; } #expenseGauge.wj-gauge .wj-value { color: #ff0000; } #profitsGauge.wj-gauge .wj-pointer { fill: #66cc94; } #profitsGauge.wj-radialgauge .wj-value { color: #66cc94; } .wj-flexgrid .wj-cell.wj-cell-maker.wj-radio-map.custom-rating label { width: .30em; color: red; } .wj-flexgrid .wj-cell.wj-cell-maker.wj-radio-map.custom-rating label:after { transform: scale(12); content: '\2b24'; } .tile { width: 30%; height: 310px; background: white; border-radius: 0.5rem; box-sizing: border-box; margin-right: 15px; margin-bottom: 15px; box-shadow: 0 1px 2px rgba(55, 63, 66, 0.07), 0 2px 4px rgba(55, 63, 66, 0.07), 0 4px 8px rgba(55, 63, 66, 0.07), 0 8px 16px rgba(55, 63, 66, 0.07), 0 16px 24px rgba(55, 63, 66, 0.07), 0 24px 32px rgba(55, 63, 66, 0.07); } .tile .tile-container { border-bottom: 1px solid #e0e0e0; padding: 0.75rem 1rem; } .tile .tile-header { padding: 0.125rem; opacity: 0.75; text-align: center; font-size: 20px; } .tile .tile-content { display: flex; align-items: center; justify-content: center; flex-direction: column; height: 90%; } .wj-tabpane { padding: 12px; } .profit { margin-top: 55px; } #prospectiveCustomer.wj-radialgauge { width: 250px; } .pros { margin-top: 20px; } .wj-needle-cap { display: none; } #prospectiveCustomer.wj-gauge .wj-pointer, .wj-gauge .wj-needle { fill: #66a2cc; } #tilePros { width: 500px } .wj-cell.wj-group { font-size: 0px } .wj-cell.wj-group b { font-size: 15px; }
(function (global) { System.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true }, meta: { '*.css': { loader: 'css' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { 'jszip': 'npm:jszip/dist/jszip.js', '@mescius/wijmo': 'npm:@mescius/wijmo/index.js', '@mescius/wijmo.input': 'npm:@mescius/wijmo.input/index.js', '@mescius/wijmo.styles': 'npm:@mescius/wijmo.styles', '@mescius/wijmo.cultures': 'npm:@mescius/wijmo.cultures', '@mescius/wijmo.chart': 'npm:@mescius/wijmo.chart/index.js', '@mescius/wijmo.chart.analytics': 'npm:@mescius/wijmo.chart.analytics/index.js', '@mescius/wijmo.chart.animation': 'npm:@mescius/wijmo.chart.animation/index.js', '@mescius/wijmo.chart.annotation': 'npm:@mescius/wijmo.chart.annotation/index.js', '@mescius/wijmo.chart.finance': 'npm:@mescius/wijmo.chart.finance/index.js', '@mescius/wijmo.chart.finance.analytics': 'npm:@mescius/wijmo.chart.finance.analytics/index.js', '@mescius/wijmo.chart.hierarchical': 'npm:@mescius/wijmo.chart.hierarchical/index.js', '@mescius/wijmo.chart.interaction': 'npm:@mescius/wijmo.chart.interaction/index.js', '@mescius/wijmo.chart.radar': 'npm:@mescius/wijmo.chart.radar/index.js', '@mescius/wijmo.chart.render': 'npm:@mescius/wijmo.chart.render/index.js', '@mescius/wijmo.chart.webgl': 'npm:@mescius/wijmo.chart.webgl/index.js', '@mescius/wijmo.chart.map': 'npm:@mescius/wijmo.chart.map/index.js', '@mescius/wijmo.gauge': 'npm:@mescius/wijmo.gauge/index.js', '@mescius/wijmo.grid': 'npm:@mescius/wijmo.grid/index.js', '@mescius/wijmo.grid.detail': 'npm:@mescius/wijmo.grid.detail/index.js', '@mescius/wijmo.grid.filter': 'npm:@mescius/wijmo.grid.filter/index.js', '@mescius/wijmo.grid.search': 'npm:@mescius/wijmo.grid.search/index.js', '@mescius/wijmo.grid.grouppanel': 'npm:@mescius/wijmo.grid.grouppanel/index.js', '@mescius/wijmo.grid.multirow': 'npm:@mescius/wijmo.grid.multirow/index.js', '@mescius/wijmo.grid.transposed': 'npm:@mescius/wijmo.grid.transposed/index.js', '@mescius/wijmo.grid.transposedmultirow': 'npm:@mescius/wijmo.grid.transposedmultirow/index.js', '@mescius/wijmo.grid.pdf': 'npm:@mescius/wijmo.grid.pdf/index.js', '@mescius/wijmo.grid.sheet': 'npm:@mescius/wijmo.grid.sheet/index.js', '@mescius/wijmo.grid.xlsx': 'npm:@mescius/wijmo.grid.xlsx/index.js', '@mescius/wijmo.grid.selector': 'npm:@mescius/wijmo.grid.selector/index.js', '@mescius/wijmo.grid.cellmaker': 'npm:@mescius/wijmo.grid.cellmaker/index.js', '@mescius/wijmo.nav': 'npm:@mescius/wijmo.nav/index.js', '@mescius/wijmo.odata': 'npm:@mescius/wijmo.odata/index.js', '@mescius/wijmo.olap': 'npm:@mescius/wijmo.olap/index.js', '@mescius/wijmo.rest': 'npm:@mescius/wijmo.rest/index.js', '@mescius/wijmo.pdf': 'npm:@mescius/wijmo.pdf/index.js', '@mescius/wijmo.pdf.security': 'npm:@mescius/wijmo.pdf.security/index.js', '@mescius/wijmo.viewer': 'npm:@mescius/wijmo.viewer/index.js', '@mescius/wijmo.xlsx': 'npm:@mescius/wijmo.xlsx/index.js', '@mescius/wijmo.undo': 'npm:@mescius/wijmo.undo/index.js', '@mescius/wijmo.interop.grid': 'npm:@mescius/wijmo.interop.grid/index.js', '@mescius/wijmo.touch': 'npm:@mescius/wijmo.touch/index.js', '@mescius/wijmo.cloud': 'npm:@mescius/wijmo.cloud/index.js', '@mescius/wijmo.barcode': 'npm:@mescius/wijmo.barcode/index.js', '@mescius/wijmo.barcode.common': 'npm:@mescius/wijmo.barcode.common/index.js', '@mescius/wijmo.barcode.composite': 'npm:@mescius/wijmo.barcode.composite/index.js', '@mescius/wijmo.barcode.specialized': 'npm:@mescius/wijmo.barcode.specialized/index.js', 'jszip': 'npm:jszip/dist/jszip.js', 'bootstrap.css': 'npm:bootstrap/dist/css/bootstrap.min.css', 'css': 'npm:systemjs-plugin-css/css.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', 'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'js' }, "node_modules": { defaultExtension: 'js' }, } }); })(this);