From 08bc04706c7ac96d63b5eecef44618e10b5bb89f Mon Sep 17 00:00:00 2001 From: tengge1 <930372551@qq.com> Date: Sat, 27 Apr 2019 15:48:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9D=A1=E5=BD=A2=E5=9B=BE=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ShadowEditor.Web/lang/zh-CN.js | 3 +- .../src/editor/menubar/VisualMenu.js | 15 +++ ShadowEditor.Web/src/language/Language.js | 1 + ShadowEditor.Web/src/visual/BarChart.js | 108 ++++++++++++++++++ 4 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 ShadowEditor.Web/src/visual/BarChart.js diff --git a/ShadowEditor.Web/lang/zh-CN.js b/ShadowEditor.Web/lang/zh-CN.js index 848ee5cf..930ad5f3 100644 --- a/ShadowEditor.Web/lang/zh-CN.js +++ b/ShadowEditor.Web/lang/zh-CN.js @@ -609,4 +609,5 @@ L_TIANDITU_MAP = '天地图'; L_VISUAL = '可视化'; L_DATA_SOURCE_MANAGE = '数据源管理'; L_SIDEBAR = '侧边栏'; -L_PANEL = '面板'; \ No newline at end of file +L_PANEL = '面板'; +L_BAR_CHART = '条形图'; \ No newline at end of file diff --git a/ShadowEditor.Web/src/editor/menubar/VisualMenu.js b/ShadowEditor.Web/src/editor/menubar/VisualMenu.js index 85530c3e..95119d00 100644 --- a/ShadowEditor.Web/src/editor/menubar/VisualMenu.js +++ b/ShadowEditor.Web/src/editor/menubar/VisualMenu.js @@ -1,6 +1,7 @@ import UI from '../../ui/UI'; import Sidebar from '../../visual/Sidebar'; import Panel from '../../visual/Panel'; +import BarChart from '../../visual/BarChart'; /** * 数据可视化菜单 @@ -37,6 +38,11 @@ VisualMenu.prototype.render = function () { cls: 'option', html: L_PANEL, onClick: this.addPanel.bind(this), + }, { + xtype: 'div', + cls: 'option', + html: L_BAR_CHART, + onClick: this.addBarChart.bind(this), }] }] }); @@ -62,4 +68,13 @@ VisualMenu.prototype.addPanel = function () { control.render(); }; +// ---------------------------- 条形图 ------------------------------------------ + +VisualMenu.prototype.addBarChart = function () { + var control = new BarChart({ + parent: this.app.editor.svg, + }); + control.render(); +}; + export default VisualMenu; \ No newline at end of file diff --git a/ShadowEditor.Web/src/language/Language.js b/ShadowEditor.Web/src/language/Language.js index 50227962..baae8e9c 100644 --- a/ShadowEditor.Web/src/language/Language.js +++ b/ShadowEditor.Web/src/language/Language.js @@ -608,4 +608,5 @@ Object.assign(window, { L_DATA_SOURCE_MANAGE: 'Data Source Manage', L_SIDEBAR: 'Sidebar', L_PANEL: 'Panel', + L_BAR_CHART: 'Bar Chart', }); \ No newline at end of file diff --git a/ShadowEditor.Web/src/visual/BarChart.js b/ShadowEditor.Web/src/visual/BarChart.js new file mode 100644 index 00000000..f8f60c13 --- /dev/null +++ b/ShadowEditor.Web/src/visual/BarChart.js @@ -0,0 +1,108 @@ +import Component from './Component'; + +/** + * 条形图 + * @param {*} options + */ +function BarChart(options) { + Component.call(this, options); +} + +BarChart.prototype = Object.create(Component.prototype); +BarChart.prototype.constructor = BarChart; + +BarChart.prototype.render = function () { + var svg = d3.select(this.parent); + var defs = svg.select('defs'); + + // 面板背景 + var barChartDef = defs.append('g') + .attr('id', 'barChartDef'); + + barChartDef.append('rect') + .attr('x', 0) + .attr('y', 0) + .attr('width', 180) + .attr('height', 212) + .attr('fill', 'rgba(0,0,0,0.2)'); + + barChartDef.append('path') + .attr('d', 'M11,0 L72,0 L85,12 L72,24 L11,24 L0,12 Z') + .attr('transform', 'translate(50,200)') + .attr('fill', '#2d232c'); + + // 面板 + var chart = svg.append('g') + .attr('transform', 'translate(850,200)'); + + chart.append('use') + .attr('href', '#barChartDef'); + + var data = [{ + text: '桌椅松动', + value: 100 / 105, + }, { + text: '启动活门', + value: 100 / 105, + }, { + text: '雷达系统', + value: 73 / 105, + }, { + text: '引气系统', + value: 72 / 105, + }, { + text: '防冰活门', + value: 69 / 105, + }, { + text: '引擎', + value: 46 / 105, + }, { + text: '起落架', + value: 42 / 105, + }]; + + var group = chart.selectAll('.bar') + .data(data) + .enter() + .append('g') + .classed('bar', true); + + group.append('text') + .text(function (d) { + return d.text; + }) + .attr('x', 10) + .attr('y', function (d, i) { + return (i + 1) * 25; + }) + .attr('fill', '#4ccdfc'); + + group.append('rect') + .attr('x', 68) + .attr('y', function (d, i) { + return (i + 1) * 25 - 10; + }) + .attr('width', 105) + .attr('height', 10) + .attr('fill', '#0c6887'); + + group.append('rect') + .attr('x', 68) + .attr('y', function (d, i) { + return (i + 1) * 25 - 10; + }) + .attr('width', function (d) { + return d.value * 105; + }) + .attr('height', 10) + .attr('fill', '#4ccdfc'); + + group.append('text') + .text('检修耗时') + .attr('transform', 'translate(88,217)') + .attr('fill', '#4ccdfc') + .attr('font-size', 14) + .attr('text-anchor', 'middle'); +}; + +export default BarChart; \ No newline at end of file