Compound.Line¶
Creates a Line compound SVG Visual for a numeric axis
DaxLib.SVG.Compound.Line( x, y, width, height, axisRef, measureRef, lineColor, minMarkColor, maxMarkColor, showAxis, axisFontSize, paddingX, paddingY )
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| x | INT64 | The x position of the compound | ||
| y | INT64 | The y position of the compound | ||
| width | INT64 | The width of the compound | ||
| height | INT64 | The height of the compound | ||
| axisRef | ANYREF EXPR | The column that the measure will be evaluated against | ||
| measureRef | NUMERIC EXPR | The measure to evaluate | ||
| lineColor | STRING | "#01B8AA" |
Optional:The hex color of the line. Defaults to "#01B8AA" | |
| minMarkColor | STRING | BLANK() |
Optional: The hex color for the minimum value marker | |
| maxMarkColor | STRING | BLANK() |
Optional: The hex color for the maximum value marker | |
| showAxis | BOOLEAN | FALSE() |
Optional: show axes when TRUE, defaults to FALSE | |
| axisFontSize | INT64 | 10 |
Optional: axis label font size, defaults to 10 | |
| paddingX | DECIMAL | 0 |
Optional: The horizontal padding percentage (0.0-1.0, e.g., 0.1 = 10% padding). Defaults to 0.05 | |
| paddingY | DECIMAL | 0 |
Optional: The vertical padding percentage (0.0-1.0, e.g., 0.1 = 10% padding). Defaults to 0.02 |
STRING SVG Line Chart
DaxLib.SVG.SVG(
500,
100,
BLANK(),
DaxLib.SVG.Compound.Line(
0, // x
0, // y
500, // width
100, // height
Dates[Date], // axisRef
[Total Cost], // measureRef
"#EC008C", // lineColor
BLANK(), // minMarkColor
BLANK(), // maxMarkColor
TRUE, // showAxis
10, // axisFontSize
0.05, // paddingX
0.04 // paddingY
),
BLANK()
)
function 'DaxLib.SVG.Compound.Line' =
(
x: INT64,
y: INT64,
width: INT64,
height: INT64,
axisRef: ANYREF EXPR,
measureRef: NUMERIC EXPR,
lineColor: STRING = "#01B8AA",
minMarkColor: STRING = BLANK(),
maxMarkColor: STRING = BLANK(),
showAxis: BOOLEAN = FALSE(),
axisFontSize: INT64 = 10,
paddingX: DOUBLE = 0,
paddingY: DOUBLE = 0
) =>
// Apply padding to dimensions
VAR _X = x + (width * (IF(ISBLANK(paddingX), 0, paddingX) / 2))
VAR _Y = y + (height * (IF(ISBLANK(paddingY), 0, paddingY) / 2))
VAR _Width = width * (1 - IF(ISBLANK(paddingX), 0, paddingX))
VAR _Height = height * (1 - IF(ISBLANK(paddingY), 0, paddingY))
VAR _ShowAxis = IF( ISBLANK( showAxis ), FALSE(), showAxis )
VAR _AxisFontSize = IF( ISBLANK( axisFontSize ), 10, axisFontSize )
VAR _AxisIsDate = ISDATETIME( MAX( axisRef ) )
VAR _LineColor = IF( NOT ISBLANK( lineColor ), lineColor, "#01B8AA" )
VAR _MinMarkColor = IF( NOT ISBLANK( minMarkColor ), minMarkColor, _LineColor )
VAR _MaxMarkColor = IF( NOT ISBLANK( maxMarkColor ), maxMarkColor, _LineColor )
VAR _Data = DaxLib.SVG.Data.AxisMeasure( axisRef, measureRef, "Auto" )
VAR _DataNonBlank = FILTER( _Data, NOT ISBLANK( [@Value] ) )
VAR _RawYMin = MINX( _DataNonBlank, [@Value] )
VAR _RawYMax = MAXX( _DataNonBlank, [@Value] )
VAR _Range = DaxLib.SVG.Data.Range( _RawYMin, _RawYMax, TRUE() )
// Define axis scales
VAR _XMin = MINX( _DataNonBlank, [@AxisIndex] )
VAR _XMax = MAXX( _DataNonBlank, [@AxisIndex] )
VAR _RawYMin2 = MINX( _Range, [@Baseline] )
VAR _RawYMax2 = MAXX( _Range, [@Max] )
// Compute nice range for value axis
VAR _NiceY = DaxLib.SVG.Scale.NiceRange( _RawYMin2, _RawYMax2, 5, TRUE() )
VAR _YMin = MINX( _NiceY, [@NiceMin] )
VAR _YMax = MINX( _NiceY, [@NiceMax] )
VAR _YTickCount = MINX( _NiceY, [@NiceTickCount] )
// Axis layout
VAR _MaxTickLabelWidth = DaxLib.SVG.Axes.MaxTickLabelWidth( _YMin, _YMax, _YTickCount, _AxisFontSize )
VAR _Layout = DaxLib.SVG.Axes.Layout( _X, _Y, _Width, _Height, _MaxTickLabelWidth, _ShowAxis, _AxisFontSize )
VAR _PlotX = MINX( _Layout, [@PlotX] )
VAR _PlotY = MINX( _Layout, [@PlotY] )
VAR _PlotWidth = MINX( _Layout, [@PlotWidth] )
VAR _PlotHeight = MINX( _Layout, [@PlotHeight] )
//Points
VAR _Points =
CONCATENATEX(
_DataNonBlank,
IF(
NOT ISBLANK( [@Value] ),
VAR _Point = DaxLib.SVG.Axes.Point( "Vertical", [@AxisIndex], [@Value], _XMin, _XMax, _YMin, _YMax, _PlotX, _PlotY, _PlotWidth, _PlotHeight )
RETURN COMBINEVALUES( ",", MINX( _Point, [@X] ), MINX( _Point, [@Y] ) )
),
" ",
[@AxisIndex],
ASC
)
// Line Element
VAR _LineElement =
DaxLib.SVG.Element.Polyline(
_Points,
DaxLib.SVG.Attr.Shapes(
"none",
BLANK(),
BLANK(),
_LineColor,
1
)
)
// Single Point Element
VAR _SinglePoint = DaxLib.SVG.Axes.Point( "Vertical", MAXX( _DataNonBlank, [@AxisIndex] ), MAXX( _DataNonBlank, [@Value] ), _XMin, _XMax, _YMin, _YMax, _PlotX, _PlotY, _PlotWidth, _PlotHeight )
VAR _SinglePointElement =
DaxLib.SVG.Element.Circle(
MINX( _SinglePoint, [@X] ),
MINX( _SinglePoint, [@Y] ),
2,
DaxLib.SVG.Attr.Shapes( _LineColor )
)
// Combined elements
VAR _CombinedElement =
IF(
COUNTROWS( _DataNonBlank ) = 1,
_SinglePointElement,
_LineElement
)
// Min and Max value markers
VAR _MinValueRow = TOPN( 1, _DataNonBlank, [@Value], ASC )
VAR _MinValueAxisIdx = MINX( _MinValueRow, [@AxisIndex] )
VAR _MinValueVal = MINX( _MinValueRow, [@Value] )
VAR _MinPointData = DaxLib.SVG.Axes.Point( "Vertical", _MinValueAxisIdx, _MinValueVal, _XMin, _XMax, _YMin, _YMax, _PlotX, _PlotY, _PlotWidth, _PlotHeight )
VAR _MaxValueRow = TOPN( 1, _DataNonBlank, [@Value], DESC )
VAR _MaxValueAxisIdx = MINX( _MaxValueRow, [@AxisIndex] )
VAR _MaxValueVal = MAXX( _MaxValueRow, [@Value] )
VAR _MaxPointData = DaxLib.SVG.Axes.Point( "Vertical", _MaxValueAxisIdx, _MaxValueVal, _XMin, _XMax, _YMin, _YMax, _PlotX, _PlotY, _PlotWidth, _PlotHeight )
VAR _MinMarkHalo =
DaxLib.SVG.Element.Circle(
MINX( _MinPointData, [@X] ),
MINX( _MinPointData, [@Y] ),
3.5,
DaxLib.SVG.Attr.Shapes( "white", 0.7 )
)
VAR _MinMark =
DaxLib.SVG.Element.Circle(
MINX( _MinPointData, [@X] ),
MINX( _MinPointData, [@Y] ),
2.5,
DaxLib.SVG.Attr.Shapes( _MinMarkColor )
)
VAR _MaxMarkHalo =
DaxLib.SVG.Element.Circle(
MINX( _MaxPointData, [@X] ),
MINX( _MaxPointData, [@Y] ),
3.5,
DaxLib.SVG.Attr.Shapes( "white", 0.7 )
)
VAR _MaxMark =
DaxLib.SVG.Element.Circle(
MINX( _MaxPointData, [@X] ),
MINX( _MaxPointData, [@Y] ),
2.5,
DaxLib.SVG.Attr.Shapes( _MaxMarkColor )
)
VAR _MinMaxMarks =
IF(
COUNTROWS( _DataNonBlank ) > 2,
IF( NOT ISBLANK( minMarkColor ), _MinMarkHalo & _MinMark )
& IF( NOT ISBLANK( maxMarkColor ), _MaxMarkHalo & _MaxMark )
)
VAR _AxisElements = DaxLib.SVG.Axes.Render( _PlotX, _PlotY, _PlotWidth, _PlotHeight, _XMin, _XMax, _YMin, _YMax, _ShowAxis, _AxisFontSize, _AxisIsDate, FALSE(), 5, _YTickCount )
RETURN
IF( NOT ISEMPTY( _DataNonBlank ) && _PlotWidth > 0 && _PlotHeight > 0, _CombinedElement & _MinMaxMarks & _AxisElements )