@khanacademy/perseus-editor 2.8.4 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,7 @@ declare class ItemExtrasEditor extends React.Component<Props> {
7
7
  chi2Table: PropTypes.Requireable<boolean>;
8
8
  onChange: PropTypes.Validator<(...args: any[]) => any>;
9
9
  periodicTable: PropTypes.Requireable<boolean>;
10
+ periodicTableWithKey: PropTypes.Requireable<boolean>;
10
11
  tTable: PropTypes.Requireable<boolean>;
11
12
  zTable: PropTypes.Requireable<boolean>;
12
13
  };
@@ -1,10 +1,9 @@
1
1
  import * as React from "react";
2
- declare const plotTypes: string[];
3
- type PlotType = typeof plotTypes[number];
2
+ import type { PerseusPlotterWidgetOptions } from "@khanacademy/perseus";
4
3
  declare const editingStates: string[];
5
4
  type EditingState = typeof editingStates[number];
6
5
  type Props = {
7
- type: PlotType;
6
+ type: PerseusPlotterWidgetOptions["type"];
8
7
  labels: Array<string>;
9
8
  categories: ReadonlyArray<string | number>;
10
9
  scaleY: number;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Perseus editors",
4
4
  "author": "Khan Academy",
5
5
  "license": "MIT",
6
- "version": "2.8.4",
6
+ "version": "2.9.0",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },
@@ -22,10 +22,10 @@
22
22
  "test": "bash -c 'yarn --silent --cwd \"../..\" test ${@:0} $($([[ ${@: -1} = -* ]] || [[ ${@: -1} = bash ]]) && echo $PWD)'"
23
23
  },
24
24
  "dependencies": {
25
- "@khanacademy/kas": "^0.3.4",
26
- "@khanacademy/kmath": "^0.1.5",
27
- "@khanacademy/perseus": "^12.3.0",
28
- "@khanacademy/perseus-core": "1.2.0"
25
+ "@khanacademy/kas": "^0.3.5",
26
+ "@khanacademy/kmath": "^0.1.6",
27
+ "@khanacademy/perseus": "^13.0.0",
28
+ "@khanacademy/perseus-core": "1.3.0"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@khanacademy/wonder-blocks-button": "^4.1.3",
@@ -12,6 +12,7 @@ class ItemExtrasEditor extends React.Component<Props> {
12
12
  chi2Table: PropTypes.bool,
13
13
  onChange: PropTypes.func.isRequired,
14
14
  periodicTable: PropTypes.bool,
15
+ periodicTableWithKey: PropTypes.bool,
15
16
  tTable: PropTypes.bool,
16
17
  zTable: PropTypes.bool,
17
18
  };
@@ -20,6 +21,7 @@ class ItemExtrasEditor extends React.Component<Props> {
20
21
  calculator: false,
21
22
  chi2Table: false,
22
23
  periodicTable: false,
24
+ periodicTableWithKey: false,
23
25
  tTable: false,
24
26
  zTable: false,
25
27
  };
@@ -29,6 +31,7 @@ class ItemExtrasEditor extends React.Component<Props> {
29
31
  calculator: this.props.calculator,
30
32
  chi2Table: this.props.chi2Table,
31
33
  periodicTable: this.props.periodicTable,
34
+ periodicTableWithKey: this.props.periodicTableWithKey,
32
35
  tTable: this.props.tTable,
33
36
  zTable: this.props.zTable,
34
37
  };
@@ -79,6 +82,28 @@ class ItemExtrasEditor extends React.Component<Props> {
79
82
  </InfoTip>
80
83
  </div>
81
84
 
85
+ {this.props.periodicTable && (
86
+ <div>
87
+ <label>
88
+ Include key/legend with periodic table:{" "}
89
+ <input
90
+ type="checkbox"
91
+ checked={this.props.periodicTableWithKey}
92
+ onChange={(e) => {
93
+ this.props.onChange({
94
+ periodicTableWithKey:
95
+ e.target.checked,
96
+ });
97
+ }}
98
+ />
99
+ </label>
100
+ <InfoTip>
101
+ Include a key for HS courses, omit for AP
102
+ chemistry.
103
+ </InfoTip>
104
+ </div>
105
+ )}
106
+
82
107
  <div>
83
108
  <label>
84
109
  Show z table (statistics):{" "}
@@ -4,6 +4,7 @@ import {number as knumber} from "@khanacademy/kmath";
4
4
  import {
5
5
  components,
6
6
  Dependencies,
7
+ plotterPlotTypes,
7
8
  PlotterWidget,
8
9
  Util,
9
10
  } from "@khanacademy/perseus";
@@ -13,18 +14,11 @@ import _ from "underscore";
13
14
 
14
15
  import BlurInput from "../components/blur-input";
15
16
 
17
+ import type {PerseusPlotterWidgetOptions} from "@khanacademy/perseus";
18
+
16
19
  const {InfoTip, NumberInput, RangeInput, TextListEditor} = components;
17
20
  const Plotter = PlotterWidget.widget;
18
21
 
19
- const BAR = "bar";
20
- const LINE = "line";
21
- const PIC = "pic";
22
- const HISTOGRAM = "histogram";
23
- const DOTPLOT = "dotplot";
24
-
25
- const plotTypes = [BAR, LINE, PIC, HISTOGRAM, DOTPLOT];
26
- type PlotType = typeof plotTypes[number];
27
-
28
22
  const STARTING = "starting";
29
23
  const CORRECT = "correct";
30
24
 
@@ -48,7 +42,7 @@ const editorDefaults = {
48
42
  } as const;
49
43
 
50
44
  type Props = {
51
- type: PlotType;
45
+ type: PerseusPlotterWidgetOptions["type"];
52
46
  labels: Array<string>;
53
47
  categories: ReadonlyArray<string | number>;
54
48
  scaleY: number;
@@ -100,7 +94,7 @@ class PlotterEditor extends React.Component<Props, State> {
100
94
  correct: [1],
101
95
  starting: [1],
102
96
 
103
- type: BAR,
97
+ type: "bar",
104
98
  labels: ["", ""],
105
99
  categories: [""],
106
100
 
@@ -184,12 +178,12 @@ class PlotterEditor extends React.Component<Props, State> {
184
178
 
185
179
  changeType: (arg1: any) => void = (type) => {
186
180
  let categories;
187
- if (type === HISTOGRAM) {
181
+ if (type === "histogram") {
188
182
  // Switching to histogram, add a label (0) to the left
189
183
  // @ts-expect-error - TS2769
190
184
  categories = [formatNumber(0)].concat(this.props.categories);
191
185
  this.props.onChange({type: type, categories: categories});
192
- } else if (this.props.type === HISTOGRAM) {
186
+ } else if (this.props.type === "histogram") {
193
187
  // Switching from histogram, remove a label from the left
194
188
  categories = this.props.categories.slice(1);
195
189
  this.props.onChange({type: type, categories: categories});
@@ -222,7 +216,7 @@ class PlotterEditor extends React.Component<Props, State> {
222
216
 
223
217
  changeCategories: (arg1: any) => void = (categories) => {
224
218
  let n = categories.length;
225
- if (this.props.type === HISTOGRAM) {
219
+ if (this.props.type === "histogram") {
226
220
  // Histograms with n labels/categories have n - 1 buckets
227
221
  n--;
228
222
  }
@@ -279,7 +273,7 @@ class PlotterEditor extends React.Component<Props, State> {
279
273
  const length = Math.floor((max - min) / scale) * scale;
280
274
 
281
275
  let categories;
282
- if (this.props.type === HISTOGRAM || this.props.type === DOTPLOT) {
276
+ if (this.props.type === "histogram" || this.props.type === "dotplot") {
283
277
  // Ranges for histogram and dotplot labels should start at zero
284
278
  categories = _.range(0, length + scale, scale);
285
279
  } else {
@@ -312,7 +306,7 @@ class PlotterEditor extends React.Component<Props, State> {
312
306
  "labelInterval",
313
307
  );
314
308
 
315
- if (this.props.type === PIC) {
309
+ if (this.props.type === "pic") {
316
310
  // @ts-expect-error - TS2339 - Property 'picUrl' does not exist on type 'Pick<Readonly<any> & Readonly<{ children?: ReactNode; }>, "type" | "correct" | "labels" | "categories" | "starting" | "scaleY" | "maxY" | "snapsPerLine" | "labelInterval">'.
317
311
  json.picUrl = this.props.picUrl;
318
312
  }
@@ -322,10 +316,10 @@ class PlotterEditor extends React.Component<Props, State> {
322
316
 
323
317
  render(): React.ReactNode {
324
318
  const setFromScale = _.contains(
325
- [LINE, HISTOGRAM, DOTPLOT],
319
+ ["line", "histogram", "dotplot"],
326
320
  this.props.type,
327
321
  );
328
- const canChangeSnaps = !_.contains([PIC, DOTPLOT], this.props.type);
322
+ const canChangeSnaps = !_.contains(["pic", "dotplot"], this.props.type);
329
323
  const props = {
330
324
  trackInteraction: () => {},
331
325
  ...this.props,
@@ -335,7 +329,7 @@ class PlotterEditor extends React.Component<Props, State> {
335
329
  <div className="perseus-widget-plotter-editor">
336
330
  <div>
337
331
  Chart type:{" "}
338
- {plotTypes.map((type) => {
332
+ {plotterPlotTypes.map((type) => {
339
333
  return (
340
334
  <label key={type}>
341
335
  <input
@@ -419,7 +413,7 @@ class PlotterEditor extends React.Component<Props, State> {
419
413
  </p>
420
414
  </InfoTip>
421
415
  </div>
422
- {this.props.type === PIC && (
416
+ {this.props.type === "pic" && (
423
417
  <div>
424
418
  <label>
425
419
  Picture:{" "}