2013-12-13 46 views
0

我已經擴展了一個組件,我無法將它渲染到面板。好像我缺少一些非常基本的東西,因爲Chrome中的調試器實際上顯示面板有數據,但它沒有顯示出來。自定義組件不顯示在Ext.panel.Panel上

這裏是fiddle,這裏是部分代碼:

定製組件:

Ext.define('StoplightControl', { 
    extend: 'Ext.draw.Component', 
    alias: 'widget.Stoplight', 
    constructor: function (config) { 
     this.initConfig(config); 
     this.callParent(arguments); 
    }, 
    initComponent: function() { 
     var kpiData; // = Ext.data.StoreManager.get('KPIStore').getById(this.model.get('KPI_ID')); 
     if (typeof (kpiData) === 'undefined' || kpiData == null) { 
      kpiData = Ext.create('KPIModel', { 
       ControlBackground: '#000000', 
       Caution_label: 'On', 
       Good_label: 'Ahead', 
       Poor_label: 'Behind', 
       Good_color: '#00FF00', 
       Poor_color: '#ff0000', 
       Caution_color: '#550000', 
       Header: 'Test' 
      }); 
     } 
     this.setGradients(kpiData.get('ControlBackground')); 
     this.drawItems(this.model, kpiData); 
    }, 
    setGradients: function (controlColor) { 
     this.gradients = [{ 
      id: 'middleGradient', 
      angle: 180, 
      stops: { 
       0: { 
        color: controlColor, 
        opacity: 1 
       }, 
       50: { 
        color: controlColor, 
        opacity: .6 
       }, 
       100: { 
        color: controlColor, 
        opacity: 1 
       } 
      } 
     }, { 
      id: 'lightGradient1', 
      angle: -90, 
      stops: { 
       0: { 
        color: '#ffffff', 
        opacity: 0.01 
       }, 

       100: { 
        color: '#ffffff', 
        opacity: .8 
       } 

      } 
     }] 
    }, 
    drawItems: function (model, kpiData) { 
     var cautionValueX = -22.5 * (model.get('cautionValue').toString().length) + 227.5, 
      goodValueX = -22.5 * (model.get('goodValue').toString().length) + 227.5, 
      poorValueX = -22.5 * (model.get('poorValue').toString().length) + 227.5, 

      maxLineLength = 15, 
      changeOfY = -50, 

      cautionLabel = linebreaks(kpiData.get('Caution_label'), maxLineLength), 
      goodLabel = linebreaks(kpiData.get('Good_label'), maxLineLength), 
      poorLabel = linebreaks(kpiData.get('Poor_label'), maxLineLength), 

      cautionChangeY = (cautionLabel.split("\n").length - 1) * changeOfY, 
      goodChangeY = (goodLabel.split("\n").length - 1) * changeOfY, 
      poorChangeY = (poorLabel.split("\n").length - 1) * changeOfY, 
      headerFontSize = '100px arial,sans-serif', 
      textFontSize = '80px arial,sans-serif'; 

     var drawItems = [{ 
      type: 'rect', 
      x: 1.6620979, 
      y: 52.362183, 
      radius: 90, 
      width: 448.10959, 
      height: 1000, 
      fill: 'url(#middleGradient)', 
      stroke: 'none' 
     }, { 
      type: "circle", 
      radius: 140, 
      x: 224, 
      y: 896, 
      stroke: "#000000", 
      'stroke-width': 1, 
      fill: kpiData.get('Good_color') 
     }, { 
      type: "circle", 
      x: 224, 
      y: 214, 
      radius: 140, 
      stroke: "#000000", 
      'stroke-width': 1, 
      fill: kpiData.get('Poor_color') 
     }, { 
      type: "circle", 
      x: 224, 
      y: 555, 
      radius: 140, 
      stroke: "#000000", 
      'stroke-width': 1, 
      fill: kpiData.get('Caution_color') 
     }, { 
      type: "text", 
      id: "svg-stoplight-poorValue", 
      text: model.get('poorValue'), 
      x: poorValueX, 
      y: 220, 
      fill: "Black", 
      font: textFontSize 
     }, { 
      type: "text", 
      id: "svg-stoplight-cautionValue", 
      text: model.get('cautionValue'), 
      x: cautionValueX, 
      y: 560, 
      fill: "Black", 
      font: textFontSize 
     }, { 
      type: "text", 
      id: "svg-stoplight-goodValue", 
      text: model.get('goodValue'), 
      x: goodValueX, 
      y: 900, 
      fill: "Black", 
      font: textFontSize 
     }, { 
      type: "text", 
      id: "svg-stoplight-poorLabel", 
      text: poorLabel, 
      x: 500, 
      y: 220 + poorChangeY, 
      fill: "Black", 
      font: textFontSize 
     }, { 
      type: "text", 
      id: "svg-stoplight-cautionLabel", 
      text: cautionLabel, 
      x: 500, 
      y: 560 + cautionChangeY, 
      fill: "Black", 
      font: textFontSize 
     }, { 
      type: "text", 
      id: "svg-stoplight-goodLabel", 
      text: goodLabel, 
      x: 500, 
      y: 900 + goodChangeY, 
      fill: "Black", 
      font: textFontSize 
     }, { 
      type: "text", 
      id: "svg-stoplight-headerLabel", 
      text: kpiData.get('Header'), 
      x: 145, 
      y: -40, 
      fill: "Black", 
      font: headerFontSize 
     }, { 
      type: "text", 
      id: "svg-stoplight-totalLabel", 
      text: "Total = " + model.get('total'), 
      x: 100, 
      y: 1250, 
      fill: "Black", 
      font: textFontSize 
     }]; 

     //don't add gradients if IE is > 10 or documentMode is less than 9 
     if (!(ie > 10 || document.documentMode < 9)) { 
      drawItems.push({ 
       type: "ellipse", 
       id: 'test1', 
       radiusX: 112, 
       radiusY: 80, 
       x: 224, 
       y: 156, 
       fill: 'url(#lightGradient1)' 
      }, { 
       type: "ellipse", 
       radiusX: 112, 
       radiusY: 80, 
       x: 224, 
       y: 498, 
       fill: 'url(#lightGradient1)' 
      }, { 
       type: "ellipse", 
       radiusX: 112, 
       radiusY: 80, 
       x: 224, 
       y: 838, 
       fill: 'url(#lightGradient1)' 
      }); 
     } 

    }, 
    width: 210, 
    height: 250 
}); 

小組的創建和加入組分:

var displayPanel = Ext.create('widget.panel', { 
    width: 600, 
    height: 800, 
    title: 'Cost & Schedule Variance', 
    renderTo: 'WorkstreamStoplights', 
    pack: 'center', 
    shrinkWrap: 3, 
    layout: { 
     type: 'table', 
     column: 2 
    }, 

}); 

stoplightStore.each(function (model, idx) { 
    var stoplight = Ext.create('StoplightControl', { 
     model: model 
    }); 
    displayPanel.add(stoplight); 
}); 

displayPanel.doLayout(); 

正如您從小提琴中可以看到的,Title顯示pro佩爾利和我甚至在創造產品添加到displayPanel,但做了.add()似乎並不甚至已經與.doLayout()

+0

是一種形式的面板部分? –

+0

不,它不是任何形式的一部分 - 你可以看到我上面提供的jsfiddle中的所有代碼。 – wilsjd

回答

0

還沒有涉足的ExtJS了很長時間,但4.2的文檔狀態有任何影響爲this方法:

這種方法需要,只要更改這個 組件需要組件的佈局進行重新計算的東西被調用。

+0

我已經在調用'doLayout()' – wilsjd

0

啊,傻我。我需要添加項目到我的組件。我需要在initComponents的作業

this.items = drawItems;

工作fiddle

+0

您還需要''initComponent'中的'callParent()'。 –