Skip to content

Instantly share code, notes, and snippets.

@matsonj
Last active May 1, 2024 01:22
Show Gist options
  • Save matsonj/389702feef1f119e474ebec307c62297 to your computer and use it in GitHub Desktop.
Save matsonj/389702feef1f119e474ebec307c62297 to your computer and use it in GitHub Desktop.
An implementation of xmrit as a svelte component for Evidence.dev

This is based on the code on xmrit which is the reference implementation.

In order to use this in your own evidence project, you will need to do 4 things

(1) Add the three files below to your \components folder in your evidence project.

  • ShareLinkComponent.svelte
  • types.ts
  • shareLink.ts

(2) Add the lz77 library to your node project

npm install lz77

(3) prepare your data for the component. the two columns must be named "x" and "value"

  select start_date::date::text AS x, 
    value 
  from ${my_data}
  order by start_date

(4) add the component to your project

<ShareLinkComponent 
  xLabel={x_label}
  yLabel={y_label}
  xdata={prepared_data} />
<script context="module">
export const evidenceInclude = true;
</script>
<script lang="ts">
import { generateShareLink } from './shareLink';
export let xLabel = "date";
export let yLabel = "value";
export let xdata = [];
export let dividerLines = [];
export let lockedLimits = null;
export let lockedLimitStatus = null;
let shareLink;
// Whenever any of the props change, this code will run
$: {
if (xLabel && yLabel && xdata) {
shareLink = generateShareLink({xLabel, yLabel, xdata, dividerLines, lockedLimits, lockedLimitStatus});
}
}
</script>
<!-- You can use {shareLink} anywhere in your HTML now -->
<div>
See <a href={shareLink} style="color: blue; text-decoration: underline;">XmR chart</a>
</div>
export interface XData {
x: string, // date in yyyy-mm-dd
value: number
}
export interface DividerLines {
id: string,
x: number // date in unix milliseconds
}
export interface LockedLimits {
avgX: number,
avgMovement: number,
UNPL: number, // upper natural process limit
LNPL: number, // lower natural process limit
URL: number, // upper range limit
}
export interface ShareLinkParams {
xLabel: string,
yLabel: string,
xdata: XData[],
dividerLines?: DividerLines[],
lockedLimits?: LockedLimits,
lockedLimitStatus?: number,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment