Skip to content

Commit

Permalink
removed support highlight logic (#112)
Browse files Browse the repository at this point in the history
* removed support highlight logic

* removed unused function
peviously was used by supportHighlight
  • Loading branch information
Nursultan Dzhumabaev authored Aug 10, 2023
1 parent 5ded539 commit 3e9bea9
Show file tree
Hide file tree
Showing 7 changed files with 489 additions and 329 deletions.
3 changes: 1 addition & 2 deletions capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,5 @@
}
},
"supportsMultiVisualSelection": true,
"supportsKeyboardFocus": true,
"supportsHighlight": true
"supportsKeyboardFocus": true
}
719 changes: 471 additions & 248 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,24 @@
"@types/lodash.toarray": "^4.4.7",
"@types/lodash.uniqby": "^4.7.7",
"@types/webpack": "^5.28.1",
"@typescript-eslint/eslint-plugin": "^6.1.0",
"@typescript-eslint/parser": "^6.1.0",
"@typescript-eslint/eslint-plugin": "^6.2.1",
"@typescript-eslint/parser": "^6.2.1",
"css-loader": "^6.8.1",
"eslint": "^8.45.0",
"eslint": "^8.46.0",
"eslint-plugin-powerbi-visuals": "^0.8.1",
"jasmine": "^5.0.2",
"jasmine": "^5.1.0",
"karma": "^6.4.2",
"karma-chrome-launcher": "^3.2.0",
"karma-coverage": "^2.2.1",
"karma-coverage-istanbul-reporter": "^3.0.3",
"karma-jasmine": "^5.1.0",
"karma-junit-reporter": "^2.0.1",
"karma-webpack": "^5.0.0",
"less": "^4.1.3",
"less": "^4.2.0",
"less-loader": "^11.1.3",
"playwright": "^1.36.1",
"playwright": "^1.36.2",
"powerbi-visuals-api": "~5.4.0",
"powerbi-visuals-tools": "^4.3.3",
"powerbi-visuals-tools": "^5.0.2",
"powerbi-visuals-utils-testutils": "^6.0.1",
"style-loader": "^3.3.3",
"ts-loader": "^9.4.4",
Expand Down
2 changes: 1 addition & 1 deletion pbiviz.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"displayName": "WordCloud 2.2.0.0",
"guid": "WordCloud1447959067750",
"visualClassName": "WordCloud",
"version": "2.2.0",
"version": "2.2.0.0",
"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": "https://community.powerbi.com",
"gitHubUrl": "https://github.com/Microsoft/PowerBI-visuals-WordCloud"
Expand Down
34 changes: 7 additions & 27 deletions src/WordCloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1426,7 +1426,6 @@ export class WordCloud implements IVisual {
}

private render(wordCloudDataView: WordCloudDataView): void {
const categorical : powerbi.DataViewCategorical = this.data.dataView.categorical;
if (!wordCloudDataView || !wordCloudDataView.data) {
return;
}
Expand Down Expand Up @@ -1483,14 +1482,14 @@ export class WordCloud implements IVisual {
.on("click", (event: MouseEvent, dataPoint: WordCloudDataPoint) => {
event.stopPropagation();

this.setSelection(dataPoint, event.ctrlKey, categorical);
this.setSelection(dataPoint, event.ctrlKey);
})
.on('contextmenu', (event : PointerEvent, datum : WordCloudDataPoint) =>
this.handleContextMenu(event, datum)
);

this.clearIncorrectSelection(this.data.dataView);
this.renderSelection(categorical);
this.renderSelection();
this.renderTooltip(wordGroupSelectionMerged);

this.isUpdating = false;
Expand Down Expand Up @@ -1539,7 +1538,7 @@ export class WordCloud implements IVisual {
}
}

private setSelection(dataPoint: WordCloudDataPoint, ctrlKey: boolean, categorical: powerbi.DataViewCategorical): void {
private setSelection(dataPoint: WordCloudDataPoint, ctrlKey: boolean): void {
if (!dataPoint) {
this.clearSelection();

Expand All @@ -1548,7 +1547,7 @@ export class WordCloud implements IVisual {

this.valueSelectionManager
.selectAndSendSelection(dataPoint.text, ctrlKey);
this.renderSelection(categorical);
this.renderSelection();
}

private clearSelection(): void {
Expand Down Expand Up @@ -1604,39 +1603,20 @@ export class WordCloud implements IVisual {
.style("line-height", WordCloud.TheSecondLineHeight); // Note: This construction fixes bug #6343.
}

private renderSelection(categorical: powerbi.DataViewCategorical = null): void {
private renderSelection(): void {
if (!this.wordsTextUpdateSelection) {
return;
}

//SupportHighlight Logic
const highlightedTexts : PrimitiveValue[] = [];
if(categorical)
{
const values : powerbi.DataViewValueColumns = categorical.values;
if(values)
{
const categories : powerbi.DataViewCategoryColumn[] = categorical.categories;
for(let idx = 0; idx < values.length; idx ++) {
if(!values[idx].highlights)
continue;
for(let innerIdx = 0; innerIdx < values[idx].highlights.length; innerIdx ++) {
if(values[idx].highlights[innerIdx])
highlightedTexts.push(categories[0].values[innerIdx]);
}
}
}
}

if (!this.valueSelectionManager.hasSelection && highlightedTexts.length == 0) {
if (!this.valueSelectionManager.hasSelection) {
this.setOpacity(this.wordsTextUpdateSelection, WordCloud.MaxOpacity);

return;
}

const selectedColumns: Selection<WordCloudDataPoint> = this.wordsTextUpdateSelection
.filter((dataPoint: WordCloudDataPoint) => {
return this.valueSelectionManager.isSelected(dataPoint.text) || highlightedTexts.some(x => x == dataPoint.text);
return this.valueSelectionManager.isSelected(dataPoint.text);
});

this.setOpacity(this.wordsTextUpdateSelection, WordCloud.MinOpacity);
Expand Down
23 changes: 2 additions & 21 deletions test/WordCloudData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,8 @@ export class WordCloudData extends TestDataViewBuilder {
["France", 966]
];

public generateHightLightedValues(valuesArray: number[], hightlightedElementNumber?: number): number[] {
let array: any[] = [];
const length: number = valuesArray.length;
for (let i: number = 0; i < length; i++) {
array[i] = null;
}
if (!hightlightedElementNumber)
return array;
if (hightlightedElementNumber >= length || hightlightedElementNumber < 0) {
array[0] = valuesArray[0];
} else {
array[hightlightedElementNumber] = valuesArray[hightlightedElementNumber];
}
return array;
}

public getDataView(columnNames?: string[], withHighlights: boolean = false, hightlightedElementNumber: number = 0): DataView {
public getDataView(columnNames?: string[]): DataView {
const categoriesColumn: TestDataViewBuilderCategoryColumnOptions[] = [
{
source: {
Expand Down Expand Up @@ -166,11 +151,7 @@ export class WordCloudData extends TestDataViewBuilder {
},
values: columnValues
}
];

if (withHighlights) {
columns[0].highlights = this.generateHightLightedValues(columnValues, hightlightedElementNumber);
}
];

return this.createCategoricalDataViewBuilder(categoriesColumn, [columns[0]], columnNames!).build();
}
Expand Down
23 changes: 0 additions & 23 deletions test/visualTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,27 +713,4 @@ describe("WordCloud", () => {
}
});
});

describe("support highlight test", () => {
const elementCount: number = 74;
let dataViewWithHighLighted: DataView;
let hightlightedElementNumber: number;

beforeEach(() => {
hightlightedElementNumber = Math.round(getRandomNumber(0, elementCount - 1));

dataViewWithHighLighted = defaultDataViewBuilder.getDataView(undefined, true, hightlightedElementNumber);
});

it("support highlight test", (done) => {
visualBuilder.updateRenderTimeout(dataViewWithHighLighted, async () => {
await new Promise(resolve => setTimeout(resolve, 1000));
let expectedHighlightedText = dataViewWithHighLighted.categorical?.categories![0].values[hightlightedElementNumber];
let actualHighlightedText = visualBuilder.selectedWords![0].innerHTML;
await new Promise(resolve => setTimeout(resolve, 1000));
expect(expectedHighlightedText).toBe(actualHighlightedText)
done();
});
});
});
});

0 comments on commit 3e9bea9

Please sign in to comment.