<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Power BI Visuals -Dimple.js Trellis sample... in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Visuals-Dimple-js-Trellis-sample/m-p/173983#M5676</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="5730" data-lia-user-login="MawashiKid" class="lia-mention lia-mention-user"&gt;MawashiKid&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've done a quick test. You may&amp;nbsp;add try...catch statement for troubleshooting. I'm sure you will be able to&amp;nbsp;get it&amp;nbsp;solved.&lt;/P&gt;</description>
    <pubDate>Thu, 11 May 2017 12:38:18 GMT</pubDate>
    <dc:creator>v-chuncz-msft</dc:creator>
    <dc:date>2017-05-11T12:38:18Z</dc:date>
    <item>
      <title>Power BI Visuals -Dimple.js Trellis sample...</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Visuals-Dimple-js-Trellis-sample/m-p/172522#M5658</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I stumbled on an article on LinkedIn where the author claimed he managed&lt;BR /&gt;to run a dimple.js trellis sample on Power BI Visuals.&lt;BR /&gt;&lt;A href="https://www.linkedin.com/pulse/power-bi-fast-prototyping-dimpled3-custom-visual-martin-x" target="_blank"&gt;https://www.linkedin.com/pulse/power-bi-fast-prototyping-dimpled3-custom-visual-martin-x&lt;/A&gt;&lt;BR /&gt;I decided to give it a try as I thought this would be a very good initiative to test external&lt;BR /&gt;libraries. One thing to keep in mind with dimple.js is it depends mainly on d3.js.&lt;BR /&gt;[d3.v4.. in this case] to work. So d3.js must appear first in directives hierarchy&lt;BR /&gt;otherwise dimple.js won't be able to run.&lt;/P&gt;&lt;PRE&gt;d3.v4.js: http:&lt;SPAN class="hljs-comment"&gt;//d3js.org/d3.v4.min.js //1st&lt;/SPAN&gt;&lt;BR /&gt;'---&amp;gt; dimplejs: http:&lt;SPAN class="hljs-comment"&gt;//dimplejs.org/dist/dimple.v2.3.0.min.js //2nd&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;So I came up with this code based on information. I wish the author had provided&lt;BR /&gt;a complete working .&lt;/P&gt;&lt;P&gt;The whole code shows no error on &lt;STRONG&gt;pbiviz package&lt;/STRONG&gt; compilation,&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;though when run in &lt;STRONG&gt;Power BI Desktop&lt;/STRONG&gt; or testing on &lt;STRONG&gt;Power BI Online&lt;/STRONG&gt;, nothing shows up... :(&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using a similar csv mockup data sample:&lt;BR /&gt;&lt;img /&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I aslo checked visual's underlying data view and it seemed ok, so I presume something is obviously missing as dimple.js may not be recognized...&lt;/P&gt;&lt;P&gt;So here's what I came up with.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The application&amp;nbsp;hierarchy&lt;BR /&gt;&lt;img /&gt;&lt;BR /&gt;&lt;BR /&gt;tsconfigj.son:&lt;/P&gt;&lt;PRE&gt;{
  "compilerOptions": {
    "allowJs": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "ES5",
    "sourceMap": true,
    "out": "./.tmp/build/visual.js"
  },
  "files": [
    ".api/v1.5.0/PowerBI-visuals.d.ts",
     "typings/index.d.ts",
     "src/trellischart.d.ts",
     "src/trellischart.js",
     "src/visual.ts"
  ]
}&lt;/PRE&gt;&lt;P&gt;pbiviz.json:&lt;/P&gt;&lt;PRE&gt; "externalJS": ["node_modules/d3v4/build/d3.js","extlib/dimple.v2.3.0.js"], &amp;lt;--------
  "style": "style/visual.less",
  "capabilities": "capabilities.json",
  "dependencies": "dependencies.json"&lt;/PRE&gt;&lt;P&gt;capabilities.json:&lt;/P&gt;&lt;PRE&gt;{
    "dataRoles": [
        {
            "displayName": "Date",
            "name": "Date",
            "kind": "Grouping"
        },{
            "displayName": "Month",
            "name": "Month",
            "kind": "Grouping"
        },
        {
            "displayName": "Category",
            "name": "Category",
            "kind": "Grouping"
        },
        {
            "displayName": "Value",
            "name": "Value",
            "kind": "Measure"
        }
    ],
    "dataViewMappings": [
        {
            "conditions": [
                    {
                        "Date": { "max": 1 }, "Month": { "max": 1 }, 
                        "Category": { "max": 1 }, "Value": { "max": 1 }
                    }
                ]
                ,"categorical": {
                    "categories": {
                        "for": { "in": "Date" },
                        "dataReductionAlgorithm": { "top": {} }
                    },
                    "values": {
                        "select": [
                            { "bind": { "to": "Month" } },
                            { "bind": { "to": "Category" } },
                            { "bind": { "to": "Value" } }
                        ]
                    } 
                }
        }
    ]
}&lt;/PRE&gt;&lt;P&gt;src/tresllischart.d.ts:&lt;/P&gt;&lt;PRE&gt;declare var dimple: any;
declare var trellichart: any;&lt;/PRE&gt;&lt;P&gt;src/trellischart.js:&lt;/P&gt;&lt;PRE&gt;/// &amp;lt;amd-dependency path='external/dimple.v2.3.0.js'&amp;gt;

function loadTrellis(element, dataView, config) {
	console.log(config);
    var trellis = element;

	trellis.style('width', config.viewport.width)
  		.style('height',config.viewport.height);
    
	// var x = convert(dataView);
	var data = convert(dataView);//loadData(); //load data from here
	//d3.tsv("/data/example_data.tsv", function (data) {

 	// Get a unique list of dates
    var months = dimple.getUniqueValues(data.rows, data.date.Date);

      // Set the bounds for the charts
      var row = 0,
          col = 0,
          top = 25,
          left = 60,
          inMarg = 15,
          width = 115,
          height = 90,
          totalWidth = config.viewport.width*.9;//;parseFloat(trellis.attr("width"));

      // Pick the latest 12 dates
      months = months.slice(months.length - 12);

      // Draw a chart for each of the 12 dates
      months.forEach(function (month) {
          
          // Wrap to the row above
          if (left + ((col + 1) * (width + inMarg)) &amp;gt; totalWidth) {
            row += 1;
            col = 0;
          }
          
          // Filter for the month in the iteration
          var chartData = dimple.filterData(data.rows, data.date.Date, month);
          
          // Use d3 to draw a text label for the month
          trellis
            .append("text")
                .attr("x", left + (col * (width + inMarg)) + (width / 2))
                .attr("y", top + (row * (height + inMarg)) + (height / 2) + 12)
                .style("font-family", "sans-serif")
                .style("text-anchor", "middle")
                .style("font-size", "28px")
                .style("opacity", 0.2)
                .text(chartData[0].Month.substring(0, 3));
          
          // Create a chart at the correct point in the trellis
          var myChart = new dimple.chart(trellis, chartData);
          myChart.setBounds(
            left + (col * (width + inMarg)),
            top + (row * (height + inMarg)),
            width,
            height);
          
          // Add x and fix ordering so that all charts are the same
          var x = myChart.addCategoryAxis("x", data.axis.x);
          x.addOrderRule(data.axis.x);
          
          // Add y and fix scale so that all charts are the same
          var y = myChart.addMeasureAxis("y", data.axis.y);
          y.overrideMax = 1500;
          
          // Draw the bars.  Passing null here would draw all bars with
          // the same color.  Passing owner second colors by owner, which
          // is normally bad practice in a bar chart but works in a trellis.
          // Month is only passed here so that it shows in the tooltip.
          myChart.addSeries([data.date.Month, data.axis.x], dimple.plot.bar);

          // Draw the chart
          myChart.draw();

          // Once drawn we can access the shapes
          // If this is not in the first column remove the y text
          if (col &amp;gt; 0) {
            y.shapes.selectAll("text").remove();
          }
          // If this is not in the last row remove the x text
          if (row &amp;lt; 2) {
             x.shapes.selectAll("text").remove();
          }
          // Remove the axis labels
          y.titleShape.remove();
          x.titleShape.remove();

          // Move to the next column
          col += 1;

      }, this);
}


function convert(dataView)
{

	var DateCol = -1, MonthCol = -1, CategoryCol = -1, ValueCol = -1, ret = []; 

	if (dataView &amp;amp;&amp;amp; dataView.categorical &amp;amp;&amp;amp; dataView.metadata &amp;amp;&amp;amp; dataView.metadata.columns) { //&amp;amp;&amp;amp; dataView.categorical.categories
		var metadataColumns = dataView.metadata.columns;
		//step 1: 1)find correct column index in meta data
		for (var i = 0; i &amp;lt; metadataColumns.length; i++) {
			var col = metadataColumns[i];
			if (col.roles) {
				if (col.roles['Date'])
					DateCol = i;
				else if (col.roles['Month'])
					MonthCol = i;
				else if (col.roles['Category'])
					CategoryCol = i;
				else if (col.roles['Value'])
					ValueCol = i;
			}
		}
		function getMonth(d)
		{
			function pad(s) { return (s &amp;lt; 10) ? '0' + s : s; }
			return [pad("1"), pad(d.getMonth() + 1), d.getFullYear()].join('/')
		}
		if (dataView &amp;amp;&amp;amp; dataView.table) {
			//step 2: convert table row by row into correct columns of graph
			dataView.table.rows.forEach(function (item) {
				ret.push({"Date":getMonth(item[DateCol]),"Month":item[MonthCol], "Category":item[CategoryCol], "Value":item[ValueCol]});
			});
        }
		
	}//if
	return {axis:{ x: "Category", y: "Value"}
			, date:{ Date:"Date", Month:"Month"}
			, rows: ret
		};
}&lt;/PRE&gt;&lt;P&gt;src/visual.ts&lt;/P&gt;&lt;PRE&gt;// &amp;lt;amd-dependency path='external/dimple.v2.3.0.js'  name='dimple'&amp;gt;
/// &amp;lt;amd-dependency path='trellichart'&amp;gt;

module powerbi.extensibility.visual {
    /// &amp;lt;reference types="d3" /&amp;gt;
    export class Visual implements IVisual {
        
        private svg: d3.Selection&amp;lt;SVGElement&amp;gt;;
        private ele: any;

        constructor(options: VisualConstructorOptions) {
            let ele = options.element;
            let svg = this.svg = d3.select(options.element)
                .append('svg').classed('trellis', true);
        }

        public update(options: VisualUpdateOptions) {
            let dataView = options.dataViews[0];
            debugger;            
            loadTrellis(this.svg, dataView, options);
        }
    }
}&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;So if anyone has a solution to make this work, then be my guest...&lt;BR /&gt;Any help would be appreciated. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 May 2017 19:26:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Visuals-Dimple-js-Trellis-sample/m-p/172522#M5658</guid>
      <dc:creator>MawashiKid</dc:creator>
      <dc:date>2017-05-09T19:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI Visuals -Dimple.js Trellis sample...</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Visuals-Dimple-js-Trellis-sample/m-p/173983#M5676</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="5730" data-lia-user-login="MawashiKid" class="lia-mention lia-mention-user"&gt;MawashiKid&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've done a quick test. You may&amp;nbsp;add try...catch statement for troubleshooting. I'm sure you will be able to&amp;nbsp;get it&amp;nbsp;solved.&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 12:38:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Visuals-Dimple-js-Trellis-sample/m-p/173983#M5676</guid>
      <dc:creator>v-chuncz-msft</dc:creator>
      <dc:date>2017-05-11T12:38:18Z</dc:date>
    </item>
  </channel>
</rss>

