-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #855 from scottdickerson/fix-zoombar-scale
* fix(zoombar): cache zoombar data and zoombar default domain * fix(zoombar): cache custom zoom bar data in the model * fix(zoombar): cache custom zoom bar data in the model * Update packages/core/stories/utils.ts Co-authored-by: Eliad Moosavi <theiliad@users.noreply.github.com> * fix(zoombar): still need to sanitize * test(dev): remove dev stories * refactor(model-zoom): move methods zoom bar specific to model-zoom * refactor(model-zoom): rename to model-cartesian-charts * fix(lint): fix lint issue * fix(stories): remove from non core stories * fix(stories): remove from non core stories Co-authored-by: Eliad Moosavi <theiliad@users.noreply.github.com>
- Loading branch information
1 parent
80d6906
commit 27e1725
Showing
13 changed files
with
242 additions
and
148 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
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,7 @@ | ||
import { addZoomBarToOptions } from "./zoom-bar"; | ||
import * as lineChart from "./line"; | ||
|
||
export const zoomBarHighScaleLineTimeSeriesOptions = addZoomBarToOptions( | ||
Object.assign({ highScale: true }, lineChart.lineTimeSeriesOptions) | ||
); | ||
zoomBarHighScaleLineTimeSeriesOptions["title"] = "High scale (zoom bar)"; |
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
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
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,74 @@ | ||
// Internal Imports | ||
import { ChartModel } from "./model"; | ||
import { Tools } from "./tools"; | ||
|
||
/** | ||
* This supports adding X and Y Cartesian[2D] zoom data to a ChartModel | ||
* */ | ||
export class ChartModelCartesian extends ChartModel { | ||
constructor(services: any) { | ||
super(services); | ||
} | ||
|
||
setData(newData) { | ||
let data; | ||
if (newData) { | ||
data = super.setData(newData); | ||
if (Tools.getProperty(this.getOptions(), "zoomBar")) { | ||
// if we have zoom bar data we need to update it as well | ||
this.setZoomBarData(); | ||
} | ||
} | ||
|
||
return data; | ||
} | ||
|
||
/** | ||
* @param zoomBarData any special zoom bar data to use instead of the model data | ||
*/ | ||
setZoomBarData(newZoomBarData?) { | ||
const sanitizedData = newZoomBarData | ||
? this.sanitize(Tools.clone(newZoomBarData)) | ||
: this.getDisplayData(); // if we're not passed explicit zoom data use the model | ||
|
||
let zoomBarNormalizedValues = sanitizedData; | ||
|
||
const { cartesianScales } = this.services; | ||
if ( | ||
sanitizedData && | ||
cartesianScales.domainAxisPosition && | ||
cartesianScales.rangeAxisPosition | ||
) { | ||
const domainIdentifier = cartesianScales.getDomainIdentifier(); | ||
const rangeIdentifier = cartesianScales.getRangeIdentifier(); | ||
// get all dates (Number) in displayData | ||
let allDates = sanitizedData.map((datum) => | ||
datum[domainIdentifier].getTime() | ||
); | ||
allDates = Tools.removeArrayDuplicates(allDates).sort(); | ||
|
||
// Go through all date values | ||
// And get corresponding data from each dataset | ||
zoomBarNormalizedValues = allDates.map((date) => { | ||
let sum = 0; | ||
const datum = {}; | ||
|
||
sanitizedData.forEach((data) => { | ||
if (data[domainIdentifier].getTime() === date) { | ||
sum += data[rangeIdentifier]; | ||
} | ||
}); | ||
datum[domainIdentifier] = new Date(date); | ||
datum[rangeIdentifier] = sum; | ||
|
||
return datum; | ||
}); | ||
} | ||
|
||
this.set({ zoomBarData: zoomBarNormalizedValues }); | ||
} | ||
|
||
getZoomBarData() { | ||
return this.get("zoomBarData"); | ||
} | ||
} |
Oops, something went wrong.