Skip to content

Commit

Permalink
Merge pull request #20 from NatVanG/rules-threshold-review
Browse files Browse the repository at this point in the history
Additional base rules and base rules threshold default values update.
  • Loading branch information
NatVanG authored Oct 19, 2023
2 parents adc4831 + 389db16 commit 3924141
Show file tree
Hide file tree
Showing 17 changed files with 329 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,5 @@ FodyWeavers.xsd
/PBIXInspectorCLI/Properties/PublishProfiles/FolderProfile.pubxml
/PBIXInspectorWinLibrary/Files/pbip/Inventory sample - fails.Dataset/.pbi/localSettings.json
/PBIXInspectorWinLibrary/Files/pbip/Inventory sample - fails.Report/.pbi/localSettings.json
/PBIXInspectorWinForm/Files/pbip/Inventory sample - fails.Dataset/.pbi
/PBIXInspectorWinForm/Files/pbip/Inventory sample - fails.Report/.pbi
52 changes: 41 additions & 11 deletions DocsExamples/Example-rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,37 @@
"var": "visualsConfigArray"
},
{
"none": [
"and": [
{
"var": "singleVisual.vcObjects.general"
"!": [
{
"in": [
{
"var": "singleVisual.visualType"
},
[
"shape"
]
]
}
]
},
{
"or": [
"none": [
{
"!!": [ { "var": "properties.altText.expr.Aggregation" } ]
"var": "singleVisual.vcObjects.general"
},
{
"!=": [
{ "var": "properties.altText.expr.Literal.Value" },
"''"
"or": [
{
"!!": [ { "var": "properties.altText.expr.Aggregation" } ]
},
{
"!=": [
{ "var": "properties.altText.expr.Literal.Value" },
"''"
]
}
]
}
]
Expand Down Expand Up @@ -395,7 +413,7 @@
"name": "Check Deneb charts properties - work in progress",
"description": "Checks that the drillvar custom rule can read deneb custom visual nested jsonspec properties. This is an example in progress that demonstrates the used of the drillvar custom rule but doesn't yet do anything useful.",
"disabled": true,
"logType": "error",
"logType": "warning",
"path": "$.sections[*]",
"pathErrorWhenNoMatch": true,
"test": [
Expand All @@ -407,11 +425,23 @@
"var": "pageArray"
},
{
"==": [
"and": [
{
"drillvar": "visualContainers.0.config>singleVisual.objects.vega.0.properties.jsonSpec.expr.Literal.Value>data.name"
"strcontains": [
{
"drillvar": "visualContainers.0.config>singleVisual.visualType"
},
"^deneb[A-Z0-9]+$"
]
},
"dataset"
{
"==": [
{
"drillvar": "visualContainers.0.config>singleVisual.objects.vega.0.properties.jsonSpec.expr.Literal.Value>data.name"
},
"dataset"
]
}
]
}
]
Expand Down
14 changes: 13 additions & 1 deletion PBIXInspectorLibrary/CustomRules/DrillVariableRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using Json.Pointer;
using System.Net.Http.Headers;

namespace PBIXInspectorLibrary.CustomRules;

Expand Down Expand Up @@ -64,7 +65,18 @@ internal DrillVariableRule(Json.Logic.Rule path, Json.Logic.Rule defaultValue)
{
if (pathEval is JsonValue val)
{
var pathEvalNode = JsonNode.Parse(val.ToString()!.Replace("'","")); //TODO: This is a hack to remove single quotes from the string. Probably need to remove start and end single quotes only.
//remove single quotes from beginning and end of string if any.
string strVal;
if (val.ToString()!.StartsWith("'") && val.ToString()!.EndsWith("'"))
{
strVal = val.ToString()!.Substring(1, val.ToString()!.Length - 2);
}
else
{
strVal = val.ToString()!;
}

var pathEvalNode = JsonNode.Parse(strVal);
return EvalPath(rightString, data, pathEvalNode);
}
else
Expand Down
2 changes: 1 addition & 1 deletion PBIXInspectorLibrary/CustomRules/RectangleOverlap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace PBIXInspectorLibrary.CustomRules
{

/// <summary>
/// Handles the `count` operation.
/// Handles the `rectoverlap` operation.
/// </summary>
[Operator("rectoverlap")]
[JsonConverter(typeof(RectOverlapJsonConverter))]
Expand Down
6 changes: 3 additions & 3 deletions PBIXInspectorLibrary/CustomRules/StringContains.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public StringContains(Json.Logic.Rule searchString, Json.Logic.Rule containsStri
var containsString = ContainsString.Apply(data, contextData);

if (searchString is not JsonValue searchStringValue || !searchStringValue.TryGetValue(out string? stringSearchString))
throw new JsonLogicException($"Cannot stringcontains a non-string searchString.");
throw new JsonLogicException($"strcontains rule: searchString parameter value is not a string.");

if (containsString is not JsonValue containsStringValue || !containsStringValue.TryGetValue(out string? stringContainsString))
throw new JsonLogicException($"Cannot stringcontains a non-string containsString.");
throw new JsonLogicException($"strcontains rule: containsString parameter value is not a string.");

return Regex.Matches(stringSearchString, stringContainsString).Count;
}
Expand All @@ -53,7 +53,7 @@ internal class StringContainsJsonConverter : JsonConverter<StringContains>
var parameters = JsonSerializer.Deserialize<Json.Logic.Rule[]>(ref reader, options);

if (parameters is not { Length: 2 })
throw new JsonException("The stringcontains rule needs an array with 2 parameters.");
throw new JsonException("The strcontains rule needs an array with 2 parameters.");

if (parameters.Length == 2) return new StringContains(parameters[0], parameters[1]);

Expand Down
4 changes: 2 additions & 2 deletions PBIXInspectorLibrary/CustomRules/ToRecordRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal ToRecordRule(Json.Logic.Rule a, params Json.Logic.Rule[] more)

var count = Items.Count;

if (count % 2 != 0) { throw new JsonLogicException("The ToRecord rule expects an even number of paramaters"); }
if (count % 2 != 0) { throw new JsonLogicException("The torecord rule expects an even number of paramaters"); }

for (var i = 0; i < count - 1; i += 2)
{
Expand All @@ -61,7 +61,7 @@ internal class ToRecordRuleJsonConverter : JsonConverter<ToRecordRule>
: new[] { node.Deserialize<Json.Logic.Rule>()! };

if (parameters == null || parameters.Length == 0)
throw new JsonException("The cat rule needs an array of parameters.");
throw new JsonException("The torecord rule needs an array of parameters.");

return new ToRecordRule(parameters[0], parameters.Skip(1).ToArray());
}
Expand Down
1 change: 0 additions & 1 deletion PBIXInspectorLibrary/CustomRules/isNullOrEmptyRule.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Json.Logic;
using Json.Logic.Rules;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
{
"name": "PBIDesktopVersion",
"value": "2.120.731.0 (23.08)"
"value": "2.121.903.0 (23.09)"
},
{
"name": "PBI_ProTooling",
Expand Down Expand Up @@ -46,10 +46,6 @@
{
"name": "PBI_ResultType",
"value": "Table"
},
{
"name": "PBI_NavigationStepName",
"value": "Navigation"
}
],
"columns": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"config": "{\"version\":\"5.42\",\"themeCollection\":{\"baseTheme\":{\"name\":\"CY22SU11\",\"version\":\"5.40\",\"type\":2}},\"activeSectionIndex\":0,\"defaultDrillFilterOtherVisuals\":true,\"slowDataSourceSettings\":{\"isCrossHighlightingDisabled\":false,\"isSlicerSelectionsButtonEnabled\":false,\"isFilterSelectionsButtonEnabled\":false,\"isFieldWellButtonEnabled\":false,\"isApplyAllButtonEnabled\":false},\"linguisticSchemaSyncVersion\":2,\"settings\":{\"isPersistentUserStateDisabled\":true,\"hideVisualContainerHeader\":false,\"useStylableVisualContainerHeader\":true,\"exportDataMode\":1,\"useNewFilterPaneExperience\":true,\"optOutNewFilterPaneExperience\":false,\"defaultFilterActionIsDataFilter\":true,\"useCrossReportDrillthrough\":false,\"allowChangeFilterTypes\":true,\"allowInlineExploration\":false,\"disableFilterPaneSearch\":false,\"enableDeveloperMode\":false,\"useEnhancedTooltips\":true,\"useDefaultAggregateDisplayName\":true},\"objects\":{\"section\":[{\"properties\":{\"verticalAlignment\":{\"expr\":{\"Literal\":{\"Value\":\"'Middle'\"}}}}}],\"outspacePane\":[{\"properties\":{\"expanded\":{\"expr\":{\"Literal\":{\"Value\":\"true\"}}}}}]}}",
"config": "{\"version\":\"5.42\",\"themeCollection\":{\"baseTheme\":{\"name\":\"CY22SU11\",\"version\":\"5.40\",\"type\":2}},\"activeSectionIndex\":12,\"defaultDrillFilterOtherVisuals\":true,\"slowDataSourceSettings\":{\"isCrossHighlightingDisabled\":false,\"isSlicerSelectionsButtonEnabled\":false,\"isFilterSelectionsButtonEnabled\":false,\"isFieldWellButtonEnabled\":false,\"isApplyAllButtonEnabled\":false},\"linguisticSchemaSyncVersion\":2,\"settings\":{\"isPersistentUserStateDisabled\":true,\"hideVisualContainerHeader\":false,\"useStylableVisualContainerHeader\":true,\"exportDataMode\":1,\"useNewFilterPaneExperience\":true,\"optOutNewFilterPaneExperience\":false,\"defaultFilterActionIsDataFilter\":true,\"useCrossReportDrillthrough\":false,\"allowChangeFilterTypes\":true,\"allowInlineExploration\":false,\"disableFilterPaneSearch\":false,\"enableDeveloperMode\":false,\"useEnhancedTooltips\":true,\"useDefaultAggregateDisplayName\":true},\"objects\":{\"section\":[{\"properties\":{\"verticalAlignment\":{\"expr\":{\"Literal\":{\"Value\":\"'Middle'\"}}}}}],\"outspacePane\":[{\"properties\":{\"expanded\":{\"expr\":{\"Literal\":{\"Value\":\"false\"}}}}}]}}",
"layoutOptimization": 0,
"pods": [
{
Expand All @@ -19,7 +19,8 @@
],
"publicCustomVisuals": [
"Aquarium1442671919391",
"BarChartF5983CEA542C47889C9DE852B430DE5F"
"BarChartF5983CEA542C47889C9DE852B430DE5F",
"deneb7E15AEF80B9E4D4F8E12924291ECE89A"
],
"resourcePackages": [
{
Expand Down Expand Up @@ -345,6 +346,27 @@
],
"width": 1280.00
},
{
"config": "{}",
"displayName": "Deneb custom visual",
"displayOption": 1,
"filters": "[]",
"height": 720.00,
"name": "ReportSection6c3c3f97279fafdeeb57",
"ordinal": 12,
"visualContainers": [
{
"config": "{\"name\":\"1a67964cf02b6170c3b8\",\"layouts\":[{\"id\":0,\"position\":{\"x\":548.5714285714286,\"y\":8.407224958949097,\"z\":0,\"width\":731.4285714285714,\"height\":692.5451559934319}}],\"singleVisual\":{\"visualType\":\"deneb7E15AEF80B9E4D4F8E12924291ECE89A\",\"projections\":{\"dataset\":[{\"queryRef\":\"Inventory.Colour\"},{\"queryRef\":\"Inventory.Sum of Qty\"}]},\"prototypeQuery\":{\"Version\":2,\"From\":[{\"Name\":\"i\",\"Entity\":\"Inventory\",\"Type\":0}],\"Select\":[{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"i\"}},\"Property\":\"Colour\"},\"Name\":\"Inventory.Colour\",\"NativeReferenceName\":\"Colour\"},{\"Measure\":{\"Expression\":{\"SourceRef\":{\"Source\":\"i\"}},\"Property\":\"Sum of Qty\"},\"Name\":\"Inventory.Sum of Qty\",\"NativeReferenceName\":\"Sum of Qty\"}],\"OrderBy\":[{\"Direction\":2,\"Expression\":{\"Measure\":{\"Expression\":{\"SourceRef\":{\"Source\":\"i\"}},\"Property\":\"Sum of Qty\"}}}]},\"drillFilterOtherVisuals\":true,\"objects\":{\"display\":[{\"properties\":{\"viewportHeight\":{\"expr\":{\"Literal\":{\"Value\":\"682.5451559934319D\"}}},\"viewportWidth\":{\"expr\":{\"Literal\":{\"Value\":\"721.4285714285714D\"}}}}}],\"developer\":[{\"properties\":{\"version\":{\"expr\":{\"Literal\":{\"Value\":\"'1.5.1.0'\"}}},\"showVersionNotification\":{\"expr\":{\"Literal\":{\"Value\":\"false\"}}}}}],\"vega\":[{\"properties\":{\"provider\":{\"expr\":{\"Literal\":{\"Value\":\"'vegaLite'\"}}},\"jsonSpec\":{\"expr\":{\"Literal\":{\"Value\":\"'{\\n \\\"data\\\": {\\\"name\\\": \\\"dataset\\\"},\\n \\\"layer\\\": [\\n {\\n \\\"mark\\\": {\\n \\\"type\\\": \\\"bar\\\",\\n \\\"opacity\\\": 0.3,\\n \\\"tooltip\\\": true\\n },\\n \\\"encoding\\\": {\\n \\\"x\\\": {\\\"field\\\": \\\"Sum of Qty\\\"}\\n }\\n },\\n {\\n \\\"mark\\\": {\\n \\\"type\\\": \\\"bar\\\",\\n \\\"tooltip\\\": true\\n },\\n \\\"encoding\\\": {\\n \\\"x\\\": {\\n \\\"field\\\": \\\"Sum of Qty__highlight\\\"\\n },\\n \\\"opacity\\\": {\\n \\\"condition\\\": {\\n \\\"test\\\": {\\n \\\"field\\\": \\\"__selected__\\\",\\n \\\"equal\\\": \\\"off\\\"\\n },\\n \\\"value\\\": 0\\n },\\n \\\"value\\\": 1\\n }\\n }\\n }\\n ],\\n \\\"encoding\\\": {\\n \\\"y\\\": {\\n \\\"field\\\": \\\"Colour\\\",\\n \\\"type\\\": \\\"nominal\\\"\\n },\\n \\\"x\\\": {\\n \\\"type\\\": \\\"quantitative\\\",\\n \\\"axis\\\": {\\\"title\\\": \\\"Sum of Qty\\\"}\\n }\\n }\\n}'\"}}},\"jsonConfig\":{\"expr\":{\"Literal\":{\"Value\":\"'{\\n \\\"view\\\": {\\\"stroke\\\": \\\"transparent\\\"},\\n \\\"font\\\": \\\"Segoe UI\\\",\\n \\\"arc\\\": {},\\n \\\"area\\\": {\\n \\\"line\\\": true,\\n \\\"opacity\\\": 0.6\\n },\\n \\\"bar\\\": {},\\n \\\"line\\\": {\\n \\\"strokeWidth\\\": 3,\\n \\\"strokeCap\\\": \\\"round\\\",\\n \\\"strokeJoin\\\": \\\"round\\\"\\n },\\n \\\"path\\\": {},\\n \\\"point\\\": {\\\"filled\\\": true, \\\"size\\\": 75},\\n \\\"rect\\\": {},\\n \\\"shape\\\": {},\\n \\\"symbol\\\": {\\n \\\"strokeWidth\\\": 1.5,\\n \\\"size\\\": 50\\n },\\n \\\"text\\\": {\\n \\\"font\\\": \\\"Segoe UI\\\",\\n \\\"fontSize\\\": 12,\\n \\\"fill\\\": \\\"#605E5C\\\"\\n },\\n \\\"axis\\\": {\\n \\\"ticks\\\": false,\\n \\\"grid\\\": false,\\n \\\"domain\\\": false,\\n \\\"labelColor\\\": \\\"#605E5C\\\",\\n \\\"labelFontSize\\\": 12,\\n \\\"titleFont\\\": \\\"wf_standard-font, helvetica, arial, sans-serif\\\",\\n \\\"titleColor\\\": \\\"#252423\\\",\\n \\\"titleFontSize\\\": 16,\\n \\\"titleFontWeight\\\": \\\"normal\\\"\\n },\\n \\\"axisQuantitative\\\": {\\n \\\"tickCount\\\": 3,\\n \\\"grid\\\": true,\\n \\\"gridColor\\\": \\\"#C8C6C4\\\",\\n \\\"gridDash\\\": [1, 5],\\n \\\"labelFlush\\\": false\\n },\\n \\\"axisX\\\": {\\\"labelPadding\\\": 5},\\n \\\"axisY\\\": {\\\"labelPadding\\\": 10},\\n \\\"header\\\": {\\n \\\"titleFont\\\": \\\"wf_standard-font, helvetica, arial, sans-serif\\\",\\n \\\"titleFontSize\\\": 16,\\n \\\"titleColor\\\": \\\"#252423\\\",\\n \\\"labelFont\\\": \\\"Segoe UI\\\",\\n \\\"labelFontSize\\\": 13.333333333333332,\\n \\\"labelColor\\\": \\\"#605E5C\\\"\\n },\\n \\\"legend\\\": {\\n \\\"titleFont\\\": \\\"Segoe UI\\\",\\n \\\"titleFontWeight\\\": \\\"bold\\\",\\n \\\"titleColor\\\": \\\"#605E5C\\\",\\n \\\"labelFont\\\": \\\"Segoe UI\\\",\\n \\\"labelFontSize\\\": 13.333333333333332,\\n \\\"labelColor\\\": \\\"#605E5C\\\",\\n \\\"symbolType\\\": \\\"circle\\\",\\n \\\"symbolSize\\\": 75\\n }\\n}'\"}}},\"isNewDialogOpen\":{\"expr\":{\"Literal\":{\"Value\":\"false\"}}},\"version\":{\"expr\":{\"Literal\":{\"Value\":\"'5.6.1'\"}}},\"enableTooltips\":{\"expr\":{\"Literal\":{\"Value\":\"true\"}}},\"enableContextMenu\":{\"expr\":{\"Literal\":{\"Value\":\"true\"}}},\"enableHighlight\":{\"expr\":{\"Literal\":{\"Value\":\"true\"}}},\"enableSelection\":{\"expr\":{\"Literal\":{\"Value\":\"true\"}}},\"selectionMaxDataPoints\":{\"expr\":{\"Literal\":{\"Value\":\"50D\"}}}}}]}}}",
"filters": "[]",
"height": 692.55,
"width": 731.43,
"x": 548.57,
"y": 8.41,
"z": 0.00
}
],
"width": 1280.00
},
{
"config": "{\"visibility\":0,\"type\":2}",
"displayName": "Detail",
Expand Down Expand Up @@ -396,6 +418,27 @@
],
"width": 320.00
},
{
"config": "{}",
"displayName": "Scrolling page",
"displayOption": 1,
"filters": "[]",
"height": 1280.00,
"name": "ReportSectionc9582afbe6f823e9059c",
"ordinal": 11,
"visualContainers": [
{
"config": "{\"name\":\"85573979ecf319df2ca4\",\"layouts\":[{\"id\":0,\"position\":{\"x\":0,\"y\":17,\"z\":0,\"width\":1280,\"height\":1112,\"tabOrder\":0}}],\"singleVisual\":{\"visualType\":\"columnChart\",\"projections\":{\"Category\":[{\"queryRef\":\"Inventory.Colour\",\"active\":true}],\"Y\":[{\"queryRef\":\"Inventory.Sum of Qty\"}]},\"prototypeQuery\":{\"Version\":2,\"From\":[{\"Name\":\"i\",\"Entity\":\"Inventory\",\"Type\":0}],\"Select\":[{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"i\"}},\"Property\":\"Colour\"},\"Name\":\"Inventory.Colour\",\"NativeReferenceName\":\"Colour\"},{\"Measure\":{\"Expression\":{\"SourceRef\":{\"Source\":\"i\"}},\"Property\":\"Sum of Qty\"},\"Name\":\"Inventory.Sum of Qty\",\"NativeReferenceName\":\"Sum of Qty\"}],\"OrderBy\":[{\"Direction\":2,\"Expression\":{\"Measure\":{\"Expression\":{\"SourceRef\":{\"Source\":\"i\"}},\"Property\":\"Sum of Qty\"}}}]},\"drillFilterOtherVisuals\":true}}",
"filters": "[]",
"height": 1112.00,
"width": 1280.00,
"x": 0.00,
"y": 17.00,
"z": 0.00
}
],
"width": 1280.00
},
{
"config": "{}",
"displayName": "Custom visuals",
Expand Down
Loading

0 comments on commit 3924141

Please sign in to comment.