Skip to content

Commit

Permalink
Add features (#12)
Browse files Browse the repository at this point in the history
* Remove jQuery
* Add tooltips
* Add default color
* Add changelog
  • Loading branch information
MrMeison authored and ignatvilesov committed Jul 7, 2017
1 parent 041995f commit b35cebd
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 21 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.2.13
ADD. Added default color for words
ADD. Added tooltips

## 1.2.12
* FIX. memory leak: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': Out of memory at ImageData creation
* UPDATE. Updated package dependencies
Expand Down
11 changes: 11 additions & 0 deletions capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@
"displayName": "Data colors",
"displayNameKey": "Visual_DataColors",
"properties": {
"defaultColor": {
"displayName": "Default color",
"displayNameKey": "Visual_DefaultColor",
"type": {
"fill": {
"solid": {
"color": true
}
}
}
},
"fill": {
"displayName": "Fill",
"displayNameKey": "Visual_Fill",
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "powerbi-visuals-wordcloud",
"version": "1.2.12",
"version": "1.2.13",
"description": "Word Cloud is a visual representation of word frequency and value. Use it to get instant insight into the most important terms in a set.",
"repository": {
"type": "git",
Expand Down Expand Up @@ -31,9 +31,10 @@
"d3": "3.5.5",
"lodash": "4.17.4",
"powerbi-visuals-utils-colorutils": "^1.0.0",
"powerbi-visuals-utils-dataviewutils": "^1.0.0",
"powerbi-visuals-utils-formattingutils": "^1.0.0",
"powerbi-visuals-utils-svgutils": "^1.0.0",
"powerbi-visuals-utils-dataviewutils": "^1.2.0",
"powerbi-visuals-utils-formattingutils": "^2.0.0",
"powerbi-visuals-utils-svgutils": "^1.1.0",
"powerbi-visuals-utils-tooltiputils": "^1.0.0",
"powerbi-visuals-utils-typeutils": "^1.0.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions pbiviz.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"displayName": "WordCloud",
"guid": "WordCloud1447959067750",
"visualClassName": "WordCloud",
"version": "1.2.12",
"version": "1.2.13",
"description": "Word Cloud is a visual representation of word frequency and value. Use it to get instant insight into the most important terms in a set.",
"supportUrl": "http://community.powerbi.com",
"gitHubUrl": "https://github.com/Microsoft/PowerBI-visuals-WordCloud"
Expand All @@ -18,12 +18,12 @@
"icon": "assets/icon.png"
},
"externalJS": [
"node_modules/jquery/dist/jquery.min.js",
"node_modules/d3/d3.min.js",
"node_modules/lodash/lodash.min.js",
"node_modules/globalize/lib/globalize.js",
"node_modules/globalize/lib/cultures/globalize.culture.en-US.js",
"node_modules/powerbi-visuals-utils-typeutils/lib/index.js",
"node_modules/powerbi-visuals-utils-tooltiputils/lib/index.js",
"node_modules/powerbi-visuals-utils-svgutils/lib/index.js",
"node_modules/powerbi-visuals-utils-dataviewutils/lib/index.js",
"node_modules/powerbi-visuals-utils-formattingutils/lib/index.js",
Expand Down
5 changes: 5 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module powerbi.extensibility.visual {

export class WordCloudSettings extends DataViewObjectsParser {
public general: GeneralSettings = new GeneralSettings();
public dataPoint: DataPointSettings = new DataPointSettings();
public stopWords: StopWordsSettings = new StopWordsSettings();
public rotateText: RotateTextSettings = new RotateTextSettings();
}
Expand All @@ -45,6 +46,10 @@ module powerbi.extensibility.visual {
public isPunctuationsCharacters: boolean = false;
}

export class DataPointSettings {
defaultColor: string = null;
}

export class StopWordsSettings {
public show: boolean = true;
public isDefaultStopWords: boolean = false;
Expand Down
35 changes: 20 additions & 15 deletions src/visual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ module powerbi.extensibility.visual {
// powerbi.extensibility.utils.color
import ColorHelper = powerbi.extensibility.utils.color.ColorHelper;

// powerbi.extensibility.utils.tooptip
import TooltipEventArgs = powerbi.extensibility.utils.tooltip.TooltipEventArgs;
import ITooltipServiceWrapper = powerbi.extensibility.utils.tooltip.ITooltipServiceWrapper;
import createTooltipServiceWrapper = powerbi.extensibility.utils.tooltip.createTooltipServiceWrapper;

enum WordCloudScaleType {
logn,
sqrt,
Expand All @@ -80,17 +85,13 @@ module powerbi.extensibility.visual {

export class WordCloud implements IVisual {
private static ClassName: string = "wordCloud";

private tooltipService: ITooltipServiceWrapper;
private static Words: ClassAndSelector = createClassAndSelector("words");
private static WordGroup: ClassAndSelector = createClassAndSelector("word");

private static StopWordsDelimiter: string = " ";

private static Radians: number = Math.PI / 180;

private static MinOpacity: number = 0.2;
private static MaxOpacity: number = 1;

private static Punctuation: string[] = [
"!", ".", ":", "'", ";", ",", "?",
"@", "#", "$", "%", "^", "&", "*",
Expand Down Expand Up @@ -282,9 +283,7 @@ module powerbi.extensibility.visual {
if (categorical.Category.objects && categorical.Category.objects[index]) {
color = colorHelper.getColorForMeasure(categorical.Category.objects[index], "");
} else {
color = previousData && previousData.texts && previousData.texts[index]
? previousData.texts[index].color
: colors.getColor(index.toString()).value;
color = settings.dataPoint.defaultColor || colors.getColor(index.toString()).value;
}

selectionIdBuilder = visualHost.createSelectionIdBuilder()
Expand Down Expand Up @@ -322,7 +321,6 @@ module powerbi.extensibility.visual {

private static parseSettings(dataView: DataView, previousSettings: WordCloudSettings): WordCloudSettings {
const settings: WordCloudSettings = WordCloudSettings.parse<WordCloudSettings>(dataView);

settings.general.minFontSize = Math.max(
settings.general.minFontSize,
GeneralSettings.MinFontSize);
Expand Down Expand Up @@ -439,7 +437,7 @@ module powerbi.extensibility.visual {

if (!settings.general.isPunctuationsCharacters) {
item.text = item.text
.replace(punctuationRegExp, " ");
.replace(punctuationRegExp, " ");
}

if (splittedWords.length === splittedWordsOriginalLength) {
Expand Down Expand Up @@ -583,6 +581,9 @@ module powerbi.extensibility.visual {

public init(options: VisualConstructorOptions): void {
this.root = d3.select(options.element).append("svg");
this.tooltipService = createTooltipServiceWrapper(
options.host.tooltipService,
options.element);

this.colorPalette = options.host.colorPalette;
this.visualHost = options.host;
Expand Down Expand Up @@ -1184,7 +1185,6 @@ module powerbi.extensibility.visual {
wordGroupEnterSelection
.append("svg:text")
.style("font-size", WordCloud.DefaultTextFontSize);

wordGroupEnterSelection
.append("svg:rect");

Expand Down Expand Up @@ -1230,6 +1230,7 @@ module powerbi.extensibility.visual {

this.clearIncorrectSelection(this.data.dataView);
this.renderSelection();
this.renderTooltip(this.wordsGroupUpdateSelection);

this.isUpdating = false;

Expand Down Expand Up @@ -1382,7 +1383,6 @@ module powerbi.extensibility.visual {

let instanceEnumeration: VisualObjectInstanceEnumeration =
WordCloudSettings.enumerateObjectInstances(settings, options);

switch (options.objectName) {
case "dataPoint": {
if (this.data && this.data.dataPoints) {
Expand Down Expand Up @@ -1413,13 +1413,11 @@ module powerbi.extensibility.visual {
instanceEnumeration: VisualObjectInstanceEnumeration): void {

let wordCategoriesIndex: number[] = [];

dataPoints.forEach((item: WordCloudDataPoint) => {
if (wordCategoriesIndex.indexOf(item.wordIndex) === -1) {
let instance: VisualObjectInstance;

wordCategoriesIndex.push(item.wordIndex);

instance = {
objectName: options.objectName,
displayName: this.data.texts[item.wordIndex].text,
Expand All @@ -1428,7 +1426,6 @@ module powerbi.extensibility.visual {
false),
properties: { fill: { solid: { color: item.color } } }
};

this.addAnInstanceToEnumeration(instanceEnumeration, instance);
}
});
Expand Down Expand Up @@ -1460,6 +1457,14 @@ module powerbi.extensibility.visual {
.duration(duration)
.each("end", callback);
}
private renderTooltip(selection: UpdateSelection<WordCloudDataPoint>): void {
this.tooltipService.addTooltip(selection, (tooltipEvent: TooltipEventArgs<WordCloudDataPoint>) => {
return [{
displayName: tooltipEvent.data.text,
value: tooltipEvent.data.count.toString()
}];
});
}

public destroy(): void {
this.root = null;
Expand Down
1 change: 1 addition & 0 deletions stringResources/en-US/resources.resjson
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"Visual_General": "General",
"Visual_MinFontSize": "Min font size",
"Visual_DataColors": "Data colors",
"Visual_DefaultColor": "Default color",
"Visual_Fill": "Fill",
"Visual_MaxFontSize": "Max font size",
"Visual_Show": "Show",
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"node_modules/powerbi-visuals-utils-dataviewutils/lib/index.d.ts",
"node_modules/powerbi-visuals-utils-formattingutils/lib/index.d.ts",
"node_modules/powerbi-visuals-utils-colorutils/lib/index.d.ts",
"node_modules/powerbi-visuals-utils-tooltiputils/lib/index.d.ts",
"src/dataInterfaces.ts",
"src/settings.ts",
"src/layout.ts",
Expand Down

0 comments on commit b35cebd

Please sign in to comment.