From 9fe3eea58198bc4418ffeb353c22ab9e261807fc Mon Sep 17 00:00:00 2001 From: paleface001 Date: Sat, 16 Nov 2019 14:29:14 +0800 Subject: [PATCH] add mini charts demo1 --- examples/mini/multiple/demo/mini-multiple.js | 107 +++++++++++++++---- gatsby-config.js | 24 +++-- site/pages/index.zh.tsx | 2 +- src/tiny-plots/progress/layer.ts | 1 - src/tiny-plots/ring-progress/layer.ts | 1 + 5 files changed, 106 insertions(+), 29 deletions(-) diff --git a/examples/mini/multiple/demo/mini-multiple.js b/examples/mini/multiple/demo/mini-multiple.js index 154362195b..3ce030e16f 100644 --- a/examples/mini/multiple/demo/mini-multiple.js +++ b/examples/mini/multiple/demo/mini-multiple.js @@ -1,3 +1,6 @@ + +import {TinyLine, TinyColumn, RingProgress} from '@antv/g2plot'; + const CSS = ` .g2plot-table { width: 100%; @@ -87,10 +90,6 @@ function loadCssCode(code) { head.appendChild(style); } -function randomArray(n) { - return Array(n).map(() => Math.random() * 100); -} - loadCssCode(CSS); // create table dom @@ -101,32 +100,32 @@ container.innerHTML = TABLE; const data = [ { id: 'local-001', - times: randomArray(10), - trend: randomArray(10), + times: randomData(20,200,400), + trend: randomData(10,10,1000), load: Math.random(), }, { id: 'local-002', - times: randomArray(10), - trend: randomArray(10), + times: randomData(20,200,400), + trend: randomData(10,10,1000), load: Math.random(), }, { id: 'local-003', - times: randomArray(10), - trend: randomArray(10), + times: randomData(20,200,400), + trend: randomData(10,10,1000), load: Math.random(), }, { id: 'local-004', - times: randomArray(10), - trend: randomArray(10), + times: randomData(20,200,400), + trend: randomData(10,10,1000), load: Math.random(), }, { id: 'local-005', - times: randomArray(10), - trend: randomArray(10), + times: randomData(20,200,400), + trend: randomData(10,10,1000), load: Math.random(), }, ]; @@ -138,12 +137,82 @@ const content = data.map((d) => { return ` ${d.id} - tiny bar - tiny line - ring-progress + + + `; }); -console.log(content.join('')); - $tbody.innerHTML = content.join(''); + +function randomData(num,max,min){ + const data = []; + for(let i =0; i{ + //tiny-line + const tinyLineContainer = $(`#tiny-line-${d.id}`); + const tinyLine = new TinyLine(tinyLineContainer,{ + width: 200, + height: 50, + data: d.times, + xField: 'index', + yField: 'value', + smooth: true, + guideLine: [ + { type: 'mean', + text: { + position: 'start', + content: '平均值', + style:{ + stroke:'white', + lineWidth: 2 + } + } + } + ], + }); + tinyLine.render(); + //tiny-column + const tinyColumnContainer = $(`#tiny-bar-${d.id}`); + const tinyColumn= new TinyColumn(tinyColumnContainer,{ + width: 200, + height: 50, + data: d.trend, + xField: 'index', + yField: 'value', + guideLine: [ + { type: 'median', + text: { + position: 'start', + content: '中位数', + style:{ + stroke:'white', + lineWidth: 2 + } + } + } + ], + }); + tinyColumn.render(); + //ring-progress + const progressContainer = $(`#ring-progress-${d.id}`); + const progress = new RingProgress(progressContainer,{ + width: 50, + height: 50, + percent:d.load, + color: (v) => { + if(v < 0.3){ + return ['green', '#E8EDF3']; + }else if( v>= 0.3 && v< 0.7){ + return ['#55A6F3', '#E8EDF3']; + } + return ['red', '#E8EDF3']; + }, + }); + progress.render(); +}); \ No newline at end of file diff --git a/gatsby-config.js b/gatsby-config.js index bad13974c5..f969a6b97d 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -50,14 +50,6 @@ module.exports = { }, ], examples: [ - { - slug: 'general', - icon: 'other', - title: { - zh: '通用配置', - en: 'General Config', - }, - }, { slug: 'line', icon: 'line', // 图标名可以去 https://antv.alipay.com/zh-cn/g2/3.x/demo/index.html 打开控制台查看图标类名 @@ -114,6 +106,22 @@ module.exports = { en: 'Gauge Charts', }, }, + { + slug: 'mini', + icon: 'other', + title: { + zh: '迷你图表', + en: 'Mini Chart', + }, + }, + { + slug: 'general', + icon: 'other', + title: { + zh: '通用配置', + en: 'General Config', + }, + }, ], }, }; diff --git a/site/pages/index.zh.tsx b/site/pages/index.zh.tsx index 9851d2ee9e..e54e1a113d 100644 --- a/site/pages/index.zh.tsx +++ b/site/pages/index.zh.tsx @@ -48,7 +48,7 @@ const IndexPage = () => { const bannerButtons = [ { text: t('图表示例'), - link: '/zh/examples/general/title-description', + link: '/zh/examples/line/basic', type: 'primary', }, { diff --git a/src/tiny-plots/progress/layer.ts b/src/tiny-plots/progress/layer.ts index a23145d64f..44415a1c9b 100644 --- a/src/tiny-plots/progress/layer.ts +++ b/src/tiny-plots/progress/layer.ts @@ -31,7 +31,6 @@ export default class ProgressLayer