From 4a7fadad81cdb696718fb25eccc65bf5e08127ef Mon Sep 17 00:00:00 2001 From: afc163 Date: Wed, 25 Oct 2017 22:12:11 +0800 Subject: [PATCH] update monitor page style --- src/components/Charts/Gauge/index.js | 23 ++++++++++---- src/components/Charts/Pie/index.js | 4 +-- src/components/Charts/WaterWave/index.js | 36 ++++++++++++---------- src/components/Charts/WaterWave/index.less | 4 +++ src/routes/Dashboard/Monitor.js | 14 ++++++--- src/routes/Dashboard/Monitor.less | 4 +++ 6 files changed, 56 insertions(+), 29 deletions(-) diff --git a/src/components/Charts/Gauge/index.js b/src/components/Charts/Gauge/index.js index 50de76e8..cba42020 100644 --- a/src/components/Charts/Gauge/index.js +++ b/src/components/Charts/Gauge/index.js @@ -4,15 +4,22 @@ import equal from '../equal'; const { Shape } = G2; +const primaryColor = '#2F9CFF'; +const backgroundColor = '#F0F2F5'; + /* eslint no-underscore-dangle: 0 */ class Gauge extends PureComponent { componentDidMount() { - this.renderChart(); + setTimeout(() => { + this.renderChart(); + }, 10); } componentWillReceiveProps(nextProps) { if (!equal(this.props, nextProps)) { - this.renderChart(nextProps); + setTimeout(() => { + this.renderChart(nextProps); + }, 10); } } @@ -27,7 +34,7 @@ class Gauge extends PureComponent { } initChart(nextProps) { - const { title, color = '#00b1f8' } = nextProps || this.props; + const { title, color = primaryColor } = nextProps || this.props; Shape.registShape('point', 'dashBoard', { drawShape(cfg, group) { @@ -103,7 +110,9 @@ class Gauge extends PureComponent { } renderChart(nextProps) { - const { height, color = '#00b1f8', bgColor = '#d3f3fe', title, percent, format } = nextProps || this.props; + const { + height, color = primaryColor, bgColor = backgroundColor, title, percent, format, + } = nextProps || this.props; const data = [{ name: title, value: percent }]; if (this.chart) { @@ -139,11 +148,13 @@ class Gauge extends PureComponent { min: 0, max: 100, tickCount: 6, - subTick: false, }); chart.axis('value', { + subTick: false, tickLine: { stroke: color, + lineWidth: 2, + value: -14, }, labelOffset: -12, formatter: format, @@ -154,7 +165,7 @@ class Gauge extends PureComponent { /* eslint no-shadow: 0 */ function draw(data) { const val = data[0].value; - const lineWidth = 18; + const lineWidth = 12; chart.guide().clear(); chart.guide().arc(() => { diff --git a/src/components/Charts/Pie/index.js b/src/components/Charts/Pie/index.js index a5173851..5766e277 100644 --- a/src/components/Charts/Pie/index.js +++ b/src/components/Charts/Pie/index.js @@ -204,11 +204,11 @@ class Pie extends Component { style={{ marginLeft: left, opacity: left ? 1 : 0 }} > { - subTitle &&

{subTitle}

+ subTitle &&

{subTitle}

} { // eslint-disable-next-line - total &&

+ total &&

} ) diff --git a/src/components/Charts/WaterWave/index.js b/src/components/Charts/WaterWave/index.js index 575dce14..d1275de9 100644 --- a/src/components/Charts/WaterWave/index.js +++ b/src/components/Charts/WaterWave/index.js @@ -29,21 +29,14 @@ class WaterWave extends PureComponent { resize = () => { const { height } = this.props; - const realWidth = this.root.parentNode.offsetWidth; - if (realWidth < this.props.height) { - const radio = realWidth / height; - this.setState({ - radio, - }); - } else { - this.setState({ - radio: 1, - }); - } + const { offsetWidth } = this.root.parentNode; + this.setState({ + radio: offsetWidth < height ? offsetWidth / height : 1, + }); } renderChart() { - const { percent, color = '#19AFFA' } = this.props; + const { percent, color = '#1890FF' } = this.props; const data = percent / 100; const self = this; @@ -61,7 +54,7 @@ class WaterWave extends PureComponent { const cR = radius - (lineWidth); ctx.beginPath(); - ctx.lineWidth = lineWidth; + ctx.lineWidth = lineWidth * 2; const axisLength = canvasWidth - (lineWidth); const unit = axisLength / 8; @@ -108,7 +101,11 @@ class WaterWave extends PureComponent { ctx.lineTo(xOffset + axisLength, canvasHeight); ctx.lineTo(xOffset, canvasHeight); ctx.lineTo(startPoint[0], startPoint[1]); - ctx.fillStyle = color; + + const gradient = ctx.createLinearGradient(0, 0, 0, 170); + gradient.addColorStop(0, '#ffffff'); + gradient.addColorStop(1, '#1890FF'); + ctx.fillStyle = gradient; ctx.fill(); ctx.restore(); } @@ -137,7 +134,7 @@ class WaterWave extends PureComponent { ctx.restore(); ctx.clip(); - ctx.fillStyle = '#108ee9'; + ctx.fillStyle = '#1890FF'; } } else { if (data >= 0.85) { @@ -181,7 +178,14 @@ class WaterWave extends PureComponent { const { percent, title, height } = this.props; return (

(this.root = n)} style={{ transform: `scale(${radio})` }}> - (this.node = n)} width={height} height={height} /> +
+ (this.node = n)} + width={height * 2} + height={height * 2} + /> +
{ title && {title} diff --git a/src/components/Charts/WaterWave/index.less b/src/components/Charts/WaterWave/index.less index 5248ed07..7cb9a4ec 100644 --- a/src/components/Charts/WaterWave/index.less +++ b/src/components/Charts/WaterWave/index.less @@ -22,4 +22,8 @@ font-size: 24px; } } + .waterWaveCanvasWrapper { + transform: scale(.5); + transform-origin: 0 0; + } } diff --git a/src/routes/Dashboard/Monitor.js b/src/routes/Dashboard/Monitor.js index b23e0ffc..e1526941 100644 --- a/src/routes/Dashboard/Monitor.js +++ b/src/routes/Dashboard/Monitor.js @@ -68,7 +68,7 @@ export default class Monitor extends PureComponent {
- map + map
@@ -105,11 +105,12 @@ export default class Monitor extends PureComponent { - + @@ -119,6 +120,7 @@ export default class Monitor extends PureComponent { subTitle="中式快餐" total="28%" height={129} + lineWidth={2} /> @@ -129,6 +131,7 @@ export default class Monitor extends PureComponent { subTitle="西餐" total="22%" height={129} + lineWidth={2} /> @@ -139,12 +142,13 @@ export default class Monitor extends PureComponent { subTitle="火锅" total="32%" height={129} + lineWidth={2} /> - + - - + +