Skip to content

[Section] Better content clipping #157

@johsi-k

Description

@johsi-k

The Area mark has been set up such that when the second dependent variable (y2 or x2) is not specified, it defaults to 0.

However in some cases it may be undesirable for the dependent axis to start at 0. For instance when plotting speed against time, with area representing distance travelled, we may want a truncated y-axis beginning at 1000
image

Yet when y2 is not specified, we end up with a graph like this
image
reproduction: https://svelte.dev/repl/1e6fa75636d44e00a9ada00dc7c39dec?version=3.19.1

Rather than mandating that the user specify y2={[1000, 1000, 1000]} or replacing its default 0 with domainMin in the back end, I suggest we clip whatever is rendered by Mark to the bounds of the data

<clipPath id={`clip-${sectionId}-data`}>
  <rect 
    x={Math.min(...rangeX)}
    y={Math.min(...rangeY)}
    width={Math.abs(rangeX[0] - rangeX[1])}
    height={Math.abs(rangeY[0] - rangeY[1])}
    fill="white"
  />
</clipPath>

instead of the bounds of the section, as is currently the case

<clipPath id={`clip-${sectionId}`}>
  <rect 
    x={Math.min(scaledCoordinates.x1, scaledCoordinates.x2)}
    y={Math.min(scaledCoordinates.y1, scaledCoordinates.y2)}
    width={Math.abs(scaledCoordinates.x2 - scaledCoordinates.x1)}
    height={Math.abs(scaledCoordinates.y2 - scaledCoordinates.y1)}
  />
 </clipPath>
...
<g class="section" clip-path={`url(#clip-${sectionId})`} >
  ...
  <slot />
</g>

For example in the case of polygons,

{#if renderPolygon}
    <path clip-path={`url(#clip-${$sectionContext._sectionId}-data)`}
      class={type.toLowerCase()}
      d={generatePath($tr_screenGeometry)}
      fill={$tr_fill}
      stroke={$tr_stroke}
      stroke-width={$tr_strokeWidth}
      fill-opacity={$tr_fillOpacity}
      stroke-opacity={$tr_strokeOpacity}
      opacity={$tr_opacity}
    />
{/if}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions