-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add logarithmic and logistic scale to prevalence over time charts
- Loading branch information
1 parent
a3c2a03
commit 57df325
Showing
13 changed files
with
428 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ docs-src/* | |
rollup-config.js | ||
custom-elements.json | ||
web-dev-server.config.js | ||
build/* | ||
storybook-static/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,6 @@ | |
/build/ | ||
custom-elements.json | ||
components.iml | ||
.env | ||
componets/storybook-static/ | ||
/storybook-static/* |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Scale } from 'chart.js'; | ||
import { Chart } from 'chart.js/dist/types'; | ||
|
||
export class LogisticScale extends Scale { | ||
static id = 'logistic'; | ||
|
||
constructor(cfg: { id: string; type: string; ctx: CanvasRenderingContext2D; chart: Chart }) { | ||
super(cfg); | ||
this.min = 0.001; | ||
this.max = 0.999; | ||
} | ||
|
||
override buildTicks() { | ||
const ticks: { value: number }[] = []; | ||
|
||
const tickValues = [this.min, 0.01, 0.1, 0.5, 0.9, 0.99, this.max]; | ||
|
||
tickValues.forEach((value) => { | ||
ticks.push({ value: value }); | ||
}); | ||
|
||
this.ticks = ticks; | ||
return this.ticks; | ||
} | ||
|
||
getLogit(value: number): number { | ||
if (value <= 0) { | ||
return -Infinity; | ||
} | ||
if (value >= 1) { | ||
return Infinity; | ||
} | ||
|
||
return Math.log(value / (1 - value)); | ||
} | ||
|
||
override getPixelForValue(value: number): number { | ||
const logitMin = this.getLogit(this.min); | ||
const logitMax = this.getLogit(this.max); | ||
|
||
const logitValue = this.getLogit(value); | ||
|
||
const decimal = (logitValue - logitMin) / (logitMax - logitMin); | ||
|
||
return this.getPixelForDecimal(decimal); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
components/src/components/container/component-scaling-selector.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { html } from 'lit'; | ||
import { Meta, StoryObj } from '@storybook/web-components'; | ||
import './component-scaling-selector'; | ||
|
||
const meta: Meta = { | ||
title: 'Component/Scaling Selector', | ||
component: 'gs-component-scaling-selector', | ||
}; | ||
|
||
export default meta; | ||
|
||
const Template: StoryObj = { | ||
render: () => html`<gs-component-scaling-selector />`, | ||
}; | ||
|
||
export const ScalingSelectorStory = { | ||
...Template, | ||
}; |
40 changes: 40 additions & 0 deletions
40
components/src/components/container/component-scaling-selector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { html, LitElement } from 'lit'; | ||
import { customElement, property } from 'lit/decorators.js'; | ||
|
||
export type scaleType = 'linear' | 'logarithmic' | 'logistic'; | ||
|
||
@customElement('gs-component-scaling-selector') | ||
export class ComponentScalingSelector extends LitElement { | ||
@property({ attribute: false }) | ||
setYAxisScaleType: (scaleType: scaleType) => void = () => {}; | ||
|
||
@property({ type: String }) | ||
currentScaleType: scaleType = 'linear'; | ||
|
||
private scales = [ | ||
{ label: 'Linear', value: 'linear' }, | ||
{ label: 'Logarithmic', value: 'logarithmic' }, | ||
{ label: 'Logistic', value: 'logistic' }, | ||
]; | ||
|
||
private onChange(event: Event) { | ||
const select = event.target as HTMLSelectElement; | ||
const value = select.value as scaleType; | ||
this.setYAxisScaleType(value); | ||
} | ||
|
||
override render() { | ||
const scaleOptions = this.scales.map((scale) => { | ||
return html` <option value="${scale.value}" ?selected=${this.currentScaleType === scale.value}> | ||
${scale.label} | ||
</option>`; | ||
}); | ||
|
||
return html` | ||
<select class="select select-bordered" @change="${this.onChange}"> | ||
<option disabled selected>Pick your y axis scaling</option> | ||
${scaleOptions} | ||
</select> | ||
`; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
components/src/components/container/component-toolbar-button-checkboxes.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { html } from 'lit'; | ||
import { Meta, StoryObj } from '@storybook/web-components'; | ||
import { renderAllNoneOrCommaSeparated } from './component-toolbar-button-checkboxes'; | ||
|
||
const meta: Meta = { | ||
title: 'Toolbar/Toolbar button checkboxes', | ||
component: 'gs-component-toolbar-button-checkboxes', | ||
argTypes: { | ||
options: { | ||
options: ['firstOption', 'secondOption'], | ||
control: { type: 'check' }, | ||
defaultValue: ['firstOption'], | ||
}, | ||
selected: { | ||
options: ['firstOption', 'secondOption'], | ||
control: { type: 'check' }, | ||
defaultValue: ['firstOption'], | ||
}, | ||
prefix: { | ||
control: { type: 'text' }, | ||
defaultValue: 'somePrefix: ', | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
const Template: StoryObj = { | ||
render: (args) => | ||
html` <gs-component-toolbar-button-checkboxes | ||
.options=${args.options} | ||
.renderButtonLabel=${renderAllNoneOrCommaSeparated(args.options.length, args.prefix)} | ||
.selected=${args.selected} | ||
> | ||
</gs-component-toolbar-button-checkboxes>`, | ||
}; | ||
|
||
export const ButtonCheckboxesStory = { | ||
...Template, | ||
args: { | ||
options: ['firstOption', 'secondOption'], | ||
selected: ['firstOption'], | ||
prefix: 'somePrefix: ', | ||
}, | ||
}; |
Oops, something went wrong.