- import {register} from 'yh-plugin-manager';
- import echarts from "echarts";
- const plugin = {
- getProps: () => {
- return [
- {
- group: "titleOption",
- type: "string",
- key: "title",
- value: "漏斗图"
- },
- {
- group: "titleOption",
- type: "boolean",
- key: "titleOption_visible",
- value: true
- },
- {
- group: "titleOption",
- type: "font",
- key: "titleFont",
- },
- {
- group: "titleOption",
- type: "combo",
- key: "titlePosition",
- value: "top",
- option: ["top", "bottom"],
- },
- {
- group: "legendOption",
- type: "chartColor",
- key: "chartColor"
- },
- {
- group: "legendOption",
- type: "boolean",
- key: "legendOption_visible",
- value: true
- },
- {
- group: "legendOption",
- type: "font",
- key: "legendFont"
- },
- {
- group: "legendOption",
- type: "combo",
- key: "legendPosition",
- value: "right",
- option: ["left", "top", "right", "bottom"],
- },
- {
- group: "valueOption",
- type: "boolean",
- key: "valueOption_visible",
- value: true
- },
- {
- group: "valueOption",
- type: "font",
- key: "valueFont"
- },
- {
- group: "valueOption",
- type: "combo",
- key: "valuePosition",
- option: ["left", "right", "inside"],
- value: "inside"
- },
- ];
- },
- getLocalView: (key) => {
- const LocalSetting = {
- "PluginName": {"zh_CN": "漏斗图\n1个维度\n1个度量", "en_US": "Funnel\n1 dimension\n1 measure", "ja_JP": "ファンネルチャート\n1次元\n1指標", "zh_TW": "漏斗圖\n1個維度\n1個度量"},
- "title": {"zh_CN": "漏斗图", "en_US": "Funnel", "ja_JP": "ファンネルチャート", "zh_TW": "漏斗圖"},
- "valueFont": {"zh_CN": "", "en_US": "", "ja_JP": "", "zh_TW": ""},
- "legendFont": {"zh_CN": "", "en_US": "", "ja_JP": "", "zh_TW": ""},
- "chartColor": {"zh_CN": "图例颜色", "en_US": "Legend Color", "ja_JP": "凡例の色", "zh_TW": "圖例顏色"},
- "titlePosition": {"zh_CN": "位置", "en_US": "Position", "ja_JP": "位置", "zh_TW": "位置"},
- "titleFont": {"zh_CN": "", "en_US": "", "ja_JP": "", "zh_TW": ""},
- "titleOption": {"zh_CN": "标题选项", "en_US": "Title", "ja_JP": "タイトル", "zh_TW": "標題選項"},
- "left": {"zh_CN": "左", "en_US": "Left", "ja_JP": "左", "zh_TW": "左"},
- "top": {"zh_CN": "上", "en_US": "Top", "ja_JP": "上", "zh_TW": "上"},
- "right": {"zh_CN": "右", "en_US": "Right", "ja_JP": "右", "zh_TW": "右"},
- "bottom": {"zh_CN": "下", "en_US": "Bottom", "ja_JP": "下", "zh_TW": "下"},
- "inside": {"zh_CN": "内部", "en_US": "Inside", "ja_JP": "内部", "zh_TW": "內部"},
- "legendOption": {"zh_CN": "图例选项", "en_US": "Legent", "ja_JP": "凡例", "zh_TW": "圖例選項"},
- "valueOption": {"zh_CN": "数值选项", "en_US": "Value", "ja_JP": "数値", "zh_TW": "數值選項"},
- "legendPosition": {"zh_CN": "位置", "en_US": "Position", "ja_JP": "位置", "zh_TW": "位置"},
- "valuePosition": {"zh_CN": "位置", "en_US": "Position", "ja_JP": "位置", "zh_TW": "位置"},
- }
- return LocalSetting[key];
- },
- getBindInfo: () => {
- return {
- xcolumns: [
- {
- index: 0,
- isDim: true
- }],
- ycolumns: [
- {
- index: 0,
- isDim: false
- }]
- };
- },
- render: (domName, props, grid = null, qinfo = null) => {
- if(document.getElementById(domName) == null) {
- return;
- }
- let funnel = echarts.init(document.getElementById(domName));
- funnel.resize();
- if(grid == null || grid.csize() < 2) {
- funnel.dispose();
- funnel = null;
- return;
- }
- funnel.resize({
- width: "auto",
- height: "auto"
- });
- let option = {
- toolbox: {
- feature: {
- }
- },
- legend: {
- icon: 'rect'
- },
- cursor: "default",
- calculable: true,
- series: [
- ]
- };
- let funnel0 = {
- type:'funnel',
- min: 0,
- max: 100,
- minSize: '0%',
- maxSize: '100%',
- sort: 'descending',
- gap: 2,
- label: {
- normal: {
- show: true,
- position: 'inside'
- },
- emphasis: {
- textStyle: {
- fontSize: 20
- }
- }
- },
- labelLine: {
- normal: {
- length: 10,
- lineStyle: {
- width: 1,
- type: 'solid'
- }
- }
- },
- itemStyle: {
- normal: {
- borderColor: '#fff',
- borderWidth: 1
- }
- }
- };
- if(props.chartColor) {
- option.color = props.chartColor;
- }
- if(props.legendFont) {
- let legendFont = props.legendFont;
- option.legend.textStyle = {
- color: legendFont.fontColor,
- fontFamily: legendFont.fontFamily,
- fontStyle: legendFont.fontStyle,
- fontWeight: legendFont.fontWeight,
- fontSize: legendFont.fontSize
- };
- }
- //legend position.
- switch(props.legendPosition) {
- case "left":
- option.legend.y = 'center';
- option.legend.orient = 'vertical';
- break;
- case "top":
- option.legend.left = "center";
- option.legend.orient = 'horizontal';
- break;
- case "right":
- option.legend.left = "auto";
- option.legend.y = 'center';
- option.legend.orient = 'vertical';
- break;
- case "bottom":
- option.legend.left = "center";
- option.legend.orient = 'horizontal';
- break;
- }
- if(props.legendOption_visible != undefined) {
- option.legend.show = props.legendOption_visible;
- }
- // legend page
- option.legend.type = 'scroll';
- option.legend.pageButtonItemGap = 0;
- // texture in right of icon.
- option.legend.align = 'left';
- // graph bounds
- let data = [];
- for(let i = 1; i < grid.rsize(); i++) {
- if(grid.get(i, 0) != null && grid.get(i, 1) != 0) {
- data.push({value: Number(grid.get(i, 1)), name: grid.get(i, 0), value0: Number(grid.get(i, 1))});
- }
- }
- let maxName = data[0].name;
- for(let i = 1; i< data.length; i++) {
- if(data[i].name.length > maxName.length) {
- maxName = data[i].name;
- }
- }
- data.sort(function(a, b) {
- return b.value == a.value ? 0 : (b.value > a.value ? 1 : -1);
- });
- for(let i = 0; i < data.length; i++) {
- data[i].value = data[i].value / data[0].value0 * 100;
- }
- funnel0.data = data;
- option.series.push(funnel0);
- funnel.off('legendselectchanged');
- funnel.on('legendselectchanged', function (params) {
- const result = [];
- let view = qinfo.xcols[0].col.getView(false);
- if(params.selected) {
- for(let key in params.selected) {
- params.selected[key] && result.push([{[view]: key}]);
- }
- }
- props.filter(result);
- });
- funnel.setOption(option, true);
- }
- }
- /**
- * The YHPluginManager register the user-customized plugin.
- */
- register(plugin);
复制代码 |