<?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: How to use host services? | SelectionManager - Visual Interactions in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/How-to-use-host-services-SelectionManager-Visual-Interactions/m-p/384768#M11424</link>
    <description>&lt;P&gt;The static&amp;nbsp;&lt;STRONG&gt;converter&lt;/STRONG&gt; method must accept a host object as an argument:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;STRONG&gt;public static converter(rows: DataViewTableRow, host): items[] {&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;STRONG&gt;var dat = Visual.converter(options.dataViews["0"].table.rows, this.host);&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt; color: #333333;"&gt;Ignat Vilesov,&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt; color: #333333;"&gt;Software Engineer&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt; color: #333333;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt; color: #333333;"&gt;Microsoft Power BI Custom Visuals&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt;"&gt;&lt;A href="mailto:pbicvsupport@microsoft.com" target="_blank"&gt;&lt;SPAN&gt;pbicvsupport@microsoft.com&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Mar 2018 14:28:14 GMT</pubDate>
    <dc:creator>v-viig</dc:creator>
    <dc:date>2018-03-27T14:28:14Z</dc:date>
    <item>
      <title>How to use host services? | SelectionManager - Visual Interactions</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/How-to-use-host-services-SelectionManager-Visual-Interactions/m-p/383852#M11403</link>
      <description>&lt;P&gt;Hello &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was trying to assign Selection Ids to each data point and&amp;nbsp;got an error message that says:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;(168,19) Cannot find name 'host'.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I marked line 168 below in red. By the way i was using this&amp;nbsp;&lt;A href="https://github.com/Microsoft/PowerBI-visuals/blob/master/Tutorial/Selection.md" target="_self"&gt;Tutorial&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did i forgot something?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my full code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;module powerbi.extensibility.visual {
	
&lt;STRONG&gt;/**
 * Interface for BarChart data points.
 *
 * @interface
 * @property {number} value             - Data value for point.
 * @property {string} category          - Corresponding category of data value.
 * @property {string} color             - Color corresponding to data point.
 * @property {ISelectionId} selectionId - Id assigned to data point for cross filtering
 *                                        and visual interaction.
 */&lt;/STRONG&gt;
 
	// Eingabevariablen-Deklaration (mit Datentyp)
&lt;STRONG&gt;	export interface items {
		
		counter: number;
		totalValue: string;
		selectionId: ISelectionId;

	}&lt;/STRONG&gt;

	// Visual-Klasse (erbt Superklasse IVisual)
	export class Visual implements IVisual {
		
		&lt;STRONG&gt;private host: IVisualHost;&lt;/STRONG&gt;
		&lt;STRONG&gt;private selectionManager: ISelectionManager;&lt;/STRONG&gt;
		
		private svg: d3.Selection&amp;lt;SVGElement&amp;gt;; // SVG-Element (Container) Deklaration
		private g: d3.Selection&amp;lt;SVGElement&amp;gt;; // SVG-Element (group "g") Deklaration
		private margin = {top: 20, right: 20, bottom: 30, left: 40}; // Definiert Ränder innerhalb der Sandbox (oben,rechts,unten,links)

		// Konstruktor dient der Auflösung von Objekten anhand der Klasse "Visual"
		constructor(options: VisualConstructorOptions) {
    
			// Initialisiere svg-Grafiken; Wende Datenpunkte als SVG-Elemente an und diese als group "g"
			this.svg = d3.select(options.element).append('svg'); // SVG-Element (Container)
			this.g = this.svg.append('g'); // Die SVG-Grafik soll gruppiert, also wie ein einzelnes Bild dargestellt/behandelt werden (append("g"))
			
			&lt;STRONG&gt;this.host = options.host;
			this.selectionManager = options.host.createSelectionManager();&lt;/STRONG&gt;
		
		}

		// Die "Main-Methode", hier finden Objekt-Instanziierungen, Festsetzen von Attribut-Eigenschaften, Erzeugung von SVG-Grafiken etc. statt
		public update(options: VisualUpdateOptions) {
			
			// Spricht das jeweilige Objekt (Datenpunkt) an
			var _this = this;

			// Höhen- und Breitenattribute des SVG-Containers
			_this.svg
				.attr({
					height: options.viewport.height,
					width: options.viewport.width
				});
			
			// Definiert Breite des Visuals innerhalb der Sandbox (Ränder werden abgezogen)  
			var gHeight = options.viewport.height
				- _this.margin.top
				- _this.margin.bottom;
			
			// Definiert Höhe des Visuals innerhalb der Sandbox (Ränder werden abgezogen)
			var gWidth = options.viewport.width
				- _this.margin.right
				- _this.margin.left;
			
			// Festsetzen von Höhen- und Breitenattributen der SVG-Grafik
			_this.g
				.attr({height: gHeight, width: gWidth})
				.attr('transform','translate(' + _this.margin.left + ',' + _this.margin.top + ')'); // Definiert Koordinatensystem ausgehend von oben links mit Einbezug der Ränder
			
			// Ruft Konstruktor auf, erzeugt Objekte ("dat") und konvertiert das Datenformat anhand der "converter"-Methode
			&lt;STRONG&gt;var dat =
				Visual.converter(options.dataViews["0"].table.rows);&lt;/STRONG&gt;
				
			// Skalenbreite x-Achse
			var x = d3.scale.linear()
				.range([ 0, gWidth ]) // Definiert die numerische Skalenbreite der x-Achse (vom Ausgangspunkt bis zur Visual-Länge)
				.domain([d3.min(dat, function(d) { return parseInt(d.totalValue); }), d3.max(dat, function(d) { return parseInt(d.totalValue); })]); // Trägt jeden Wert für die x-Achse ein
				
			// Skalenhöhe y-Achse
			var y = d3.scale.linear()
				.range([ gHeight, 0 ]) // Definiert die numerische Skalenhöhe der y-Achse (von der maximalen Höhe bis zum Ausgangspunkt)
				.domain([0, d3.max(dat, function (d) { return d.counter })]); // Trägt jeden Wert für die y-Achse ein

			// Entferne bereits existierende Achsen und Elemente
			_this.svg.selectAll('.axis').remove();
			_this.svg.selectAll('.bar').remove();

			// Erzeugt eine SVG-Grafik (x-Achse)
			var xAxis = d3.svg.axis()
				_this.g
				.append('g')
				.attr("class", "x axis")
				.attr("transform", "translate(0," + gHeight + ")") // Definiert das Koordinatensystem von 0 bis maximale Höhe
				.call(d3.svg.axis().scale(x).orient("bottom"));	// Zeichnet anhand der Breite der Variable x eine horizontale nach unten ausgerichtete Linie

			// Erzeugt eine SVG-Grafik (y-Achse)
			var yAxis = d3.svg.axis()
				_this.g
				.append('g')
				.attr("class", "y axis")
				.call(d3.svg.axis().scale(y).orient("left")); // Zeichnet anhand der Höhe der Variable y eine vertikale nach links ausgerichtete Linie

			// Erzeugt eine SVG-Grafik mit Datenpunktelementen
			var shapes = _this.g
				.append('g')
				.selectAll('.bar') // Da hier nur ".bar", kann es für beliebige Punkte Elemente einfügen (anders wie bei "rect.bar" -&amp;gt; Platz wird reserviert)
				.data(dat); // Nimmt die Objekte/Elemente, welche existieren auf

			shapes.enter() // Kombiniert die leeren Felder aus ".selectAll" mit ".data" und erstellt ein Set aus Elementen, auf diese man einzeln zugreifen kann
				.append('circle') // Definiert den Visualisierungstyp
				.attr("r", 5) // Definiert den Radius
				.attr('class', 'bar') // Klasse "bar"
				.attr('fill', 'green') // Koloriert die Elemente mit einem vorgegebenen Farbcode
				.attr('stroke', 'black') // Setzt Rahmen für jedes Element des Visualisierungtyps
				.attr('cx', function (d) {return x(parseInt(d.totalValue));}) // Trennt die Elemente voneinander auf horizonteler Ebene
				.attr('cy', function (d) {return y(d.counter);}); // Trennt die Elemente voneinander auf vertikaler Ebene

			shapes
				.exit()
				.remove();
		}

		public destroy(): void {
			
			//TODO: Perform any cleanup tasks here
			
		}

		// Konvertiert Daten wie folgt: ["Japan",100],["America",300], ... --&amp;gt; [{"Country" : "Japan",   "Cost" : 100},{"Country" : "America", "Cost" : 300}, ... ]
		&lt;STRONG&gt;public static converter(rows: DataViewTableRow): items[] {
			
			var resultData: items[] = [];

			for (var i = 0; i &amp;lt; rows.length; i++) {
				var row = rows[i];
				resultData.push({
					totalValue: row[0],
					counter: row[1],
					selectionId: &lt;FONT color="#FF0000"&gt;host&lt;/FONT&gt;.createSelectionIdBuilder()
						.withCategory(row[0], i)
						.createSelectionId()
				});
			}
			
			return resultData;
			
		}&lt;/STRONG&gt;
		
	}
   
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would be very thankful for any help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Mar 2018 14:58:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/How-to-use-host-services-SelectionManager-Visual-Interactions/m-p/383852#M11403</guid>
      <dc:creator>az2451</dc:creator>
      <dc:date>2018-03-26T14:58:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to use host services? | SelectionManager - Visual Interactions</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/How-to-use-host-services-SelectionManager-Visual-Interactions/m-p/384576#M11419</link>
      <description>&lt;P&gt;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/58439"&gt;@az2451&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If convenient, share a complete project for a quick test. You may take a good look at&amp;nbsp;&lt;A href="https://github.com/Microsoft/PowerBI-visuals-sampleBarChart" target="_blank"&gt;Sample Bar Chart Repo&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 10:27:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/How-to-use-host-services-SelectionManager-Visual-Interactions/m-p/384576#M11419</guid>
      <dc:creator>v-chuncz-msft</dc:creator>
      <dc:date>2018-03-27T10:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to use host services? | SelectionManager - Visual Interactions</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/How-to-use-host-services-SelectionManager-Visual-Interactions/m-p/384768#M11424</link>
      <description>&lt;P&gt;The static&amp;nbsp;&lt;STRONG&gt;converter&lt;/STRONG&gt; method must accept a host object as an argument:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;STRONG&gt;public static converter(rows: DataViewTableRow, host): items[] {&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;STRONG&gt;var dat = Visual.converter(options.dataViews["0"].table.rows, this.host);&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt; color: #333333;"&gt;Ignat Vilesov,&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt; color: #333333;"&gt;Software Engineer&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt; color: #333333;"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt; color: #333333;"&gt;Microsoft Power BI Custom Visuals&lt;/P&gt;
&lt;P style="margin: 0in; font-family: Calibri; font-size: 11.0pt;"&gt;&lt;A href="mailto:pbicvsupport@microsoft.com" target="_blank"&gt;&lt;SPAN&gt;pbicvsupport@microsoft.com&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Mar 2018 14:28:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/How-to-use-host-services-SelectionManager-Visual-Interactions/m-p/384768#M11424</guid>
      <dc:creator>v-viig</dc:creator>
      <dc:date>2018-03-27T14:28:14Z</dc:date>
    </item>
  </channel>
</rss>

