Skip to content

Commit

Permalink
Adds OpacityLegendBehavior (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
Helen Rodionova authored and ignatvilesov committed Jul 17, 2018
1 parent 32e47e3 commit c749d33
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.7.0
* Added OpacityLegendBehavior for legend

## 1.6.0
* Allows to specify custom behavior for legend

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "powerbi-visuals-utils-chartutils",
"version": "1.6.0",
"version": "1.7.0",
"description": "ChartUtils",
"main": "lib/index.js",
"repository": {
Expand Down
File renamed without changes.
63 changes: 63 additions & 0 deletions src/legend/behavior/opacityLegendBehavior.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Power BI Visualizations
*
* Copyright (c) Microsoft Corporation
* All rights reserved.
* MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the ""Software""), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

module powerbi.extensibility.utils.chart.legend {

import IInteractiveBehavior = powerbi.extensibility.utils.interactivity.IInteractiveBehavior;

import LegendBehavior = powerbi.extensibility.utils.chart.legend.LegendBehavior;
import LegendDataPoint = powerbi.extensibility.utils.chart.legend.LegendDataPoint;

export class OpacityLegendBehavior extends LegendBehavior implements IInteractiveBehavior {
public static dimmedOpacity: number = 0.4;
public static defaultOpacity: number = 1;

public renderSelection(hasSelection: boolean): void {
if (hasSelection) {
this.legendIcons.style(
"fill", (d: LegendDataPoint) => {
return d.color;
})
.style(
"fill-opacity", (d: LegendDataPoint) => {
if (!d.selected) {
return OpacityLegendBehavior.dimmedOpacity;
}
else {
return OpacityLegendBehavior.defaultOpacity;
}
});
}
else {
this.legendIcons.style(
"fill", (d: LegendDataPoint) => {
return d.color;
})
.style("fill-opacity", OpacityLegendBehavior.defaultOpacity);
}
}
}
}
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"src/axis/axisInterfaces.ts",
"src/axis/axis.ts",
"src/legend/legendInterfaces.ts",
"src/legend/legendBehavior.ts",
"src/legend/behavior/legendBehavior.ts",
"src/legend/behavior/opacityLegendBehavior.ts",
"src/legend/legendPosition.ts",
"src/legend/legend.ts",
"src/legend/legendData.ts",
Expand Down

0 comments on commit c749d33

Please sign in to comment.